This content is controlled by your instructor, and is not zyBooks content. Direc
ID: 3820951 • Letter: T
Question
This content is controlled by your instructor, and is not zyBooks content. Direct questions or concerns about this content to your instructor. If you have any technical issues with the zyLab submission system, use the "Trouble with lab?" button at the bottom of the lab. Introduction This lab consists of more practice with flow control. You can either use if or switch statements, either would be appropriate. Let's Sell Some Apartments ApartmentSales.java You've been hired to automate the Summerdale Sales Office's apartment price estimation system. It will need to: Ask the user to choose: -1 for park view -2 for golf course view -3 for lake view Park view apartments are $150k, apartments with gold course views are $170k, and apartments with the lake views are $210k. If the user enters an invalid code, set the price to 0. It should also ask the user to specify if they want a: -1 garage -2 parking space but only if the view selection is valid. Add $5k to the price of any apartment with a garage. If the parking value is invalid, display an appropriate massage and assume that the price for a apartment with no garage. Sample expected output for a park view with a parking space: Please select a view: Park Golf Course Lake Please select a parking option: Garage Space Your choice: Park view with a parking space Estimated price: $150000Explanation / Answer
SellAppartment.java
import java.util.Scanner;
public class SellAppartment {
public static void main(String[] args) {
//Declaring variables
int view,parkingOption;
int estimatedprice;
String str="";
//Scanner object is used to get the inputs entered by the user
Scanner sc=new Scanner(System.in);
//Getting the input enterd by the user
System.out.println("Please select a view :(1) Park (2) Golf Course (3) lake ");
view=sc.nextInt();
//based on the user selection the corresponding case will get executed
switch(view)
{
case 1:
{
estimatedprice=150000;
str+="Park View With a ";
break;
}
case 2:
{
estimatedprice=170000;
str+="Golf Course View With a ";
break;
}
case 3:
{
estimatedprice=210000;
str+="Lake View With a ";
break;
}
default:{
estimatedprice=0;
System.out.println("Invalid Selection");
break;
}
}
//Getting the input entered by the user
System.out.println("Please select a Parking option :(1) Garage (2) Parking Space ");
parkingOption=sc.nextInt();
//based on the user selection the corresponding case will get executed
switch(parkingOption)
{
case 1:{
estimatedprice+=5000;
str+="Garage";
break;
}
case 2:{
str+="parking space";
estimatedprice+=0;
break;
}
default :
{
System.out.println("Invalid Selection");
estimatedprice+=0;
break;
}
}
if(estimatedprice>0)
//Displaying the user choice
System.out.println("Your Choice :"+str);
//Displaying the estimated price
System.out.println("Estimated Price :$"+estimatedprice);
}
}
________________
output:
Please select a view :(1) Park (2) Golf Course (3) lake
1
Please select a Parking option :(1) Garage (2) Parking Space
2
Your Choice :Park View With a parking space
Estimated Price :$150000
___________Thank You