Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I cannot seem to get the default to be printed can you help edit my code please

ID: 3822285 • Letter: I

Question

I cannot seem to get the default to be printed can you help edit my code please the below is the error output and the instructions on the lab. I was suggested to do an if else statement? but i dont understand.

import java.util.Scanner;

public class ApartmentSales {

public static void main(String[] args) {
  

int view,parkingOption;
int estimatedprice;
String str="";
  
  
Scanner sc=new Scanner(System.in);

  
System.out.println("Please select a view :(1) Park (2) Golf Course (3) lake ");
view=sc.nextInt();
  
  
switch(view)
{
case 1:
estimatedprice=150000;
str+="Park view ";
break;

case 2:

estimatedprice=170000;
str+="Golf course view";
break;

case 3:

estimatedprice=210000;
str+="Lake view";
break;

default:
estimatedprice=0;
System.out.println("Error: invalid choice of view.");
break;

}

if(view <4 && view >0){
System.out.println("Please select a Parking option :(1) Garage (2) Space ");

parkingOption=sc.nextInt();
  

switch(parkingOption) {
case 1:
estimatedprice+=5000;
str+=" with a garage";
break;

case 2:
str+=" with a parking space ";
estimatedprice+=0;
break;

default :

System.out.println("Error: invalid parking option");
estimatedprice+=0;
break;

}
}
System.out.println("Your Choice:"+str);




  
System.out.println("Estimated Price :$"+estimatedprice);
  
  
}

}

5. Compare output Input 4 0 Please select a view (1) Park (2) Golf Course (3) lake Error: invalid choice of view. Your output your choice Estimated Price $0 Please select a view: (1) Park (2) Golf Course (3) Lake Your choice Expected output Error: invalid choice of view. Estimated price: $0 6. Compare output Input 3 0 Please select a view (1) Park (2) Golf Course (3) lake Please select a Parking option (1) Garage (2) Space Your output Error: invalid parking option Your choice Lake view Estimated Price $210000 Please select a view (1) Park (2) Golf Course (3) Lake Please select a parking option (1) Garage (2) Space Your choice Lake view Expected output Error: invalid parking option Estimated price: $210000 DOWNLOAD SUBMISSION 0/2

Explanation / Answer

Hi, Please find my implementation.

import java.util.Scanner;

public class ApartmentSales {

   public static void main(String[] args) {

       int view = 0,parkingOption = 0;

       int estimatedprice;

       String str="";

      

       Scanner sc=new Scanner(System.in);

       System.out.println("Please select a view :(1) Park (2) Golf Course (3) lake ");

       view=sc.nextInt();

      

       switch(view)

       {

       case 1:

           estimatedprice=150000;

           str+="Park view ";

           break;

       case 2:

           estimatedprice=170000;

           str+="Golf course view";

           break;

       case 3:

           estimatedprice=210000;

           str+="Lake view";

           break;

       default:

           estimatedprice=0;

           System.out.println("Error: invalid choice of view.");

           break;

       }

      

       if(view <4 && view >0){

           System.out.println("Please select a Parking option :(1) Garage (2) Space ");

           parkingOption=sc.nextInt();

           switch(parkingOption) {

           case 1:

               estimatedprice+=5000;

               str+=" with a garage";

               break;

           case 2:

               str+=" with a parking space ";

               estimatedprice+=0;

               break;

           default :

               System.out.println("Your Choice:"+str);

               System.out.println("Error: invalid parking option");

               estimatedprice+=0;

               break;

           }

       }

      

       if(parkingOption >0 && parkingOption < 3)

           System.out.println("Your Choice:"+str);

       System.out.println("Estimated Price :$"+estimatedprice);

   }

}

/*

Sample run:

Please select a view :(1) Park (2) Golf Course (3) lake

2

Please select a Parking option :(1) Garage (2) Space

5

Your Choice:Golf course view

Error: invalid parking option

Estimated Price :$170000

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote