While the code for the two tasks below does work, I was suppose to use JOptionPa
ID: 640649 • Letter: W
Question
While the code for the two tasks below does work, I was suppose to use JOptionPane for all input or output and am not sure how to edit the code to do that properly. Any help would be greatly appreciated!
*/Task #1:
Write an application for the Summerdale Condo Sales office; the program determines the price of a condominium. Ask the user to choose 1 for park view, 2 for golf course view, or 3 for lake view. The output is the name of the chosen view as well as the price of the condo. Park view condos are $150,000, condos with golf course views are $170,000, and condos with lake views are $210,000. If the user enters an invalid code, set the price to 0. Save the file as CondoSales.java.
*/
import java.util.Scanner;
class CondoSales
{
public static void main(String[] args)
{
int view;
double price;
Scanner in=new Scanner(System.in);
System.out.println("Select View ");
System.out.print("1)Park view 2)Golf course view 3)Lake view ");
view=in.nextInt();
in.nextLine();
switch(view)
{
case 1: price=150000;
System.out.println("You Have Selected Park View Price is $"+price);
break;
case 2: price=170000;
System.out.println("You Have Selected Golf Course View Price is $"+price);
break;
case 3: price=210000;
System.out.println("You Have Selected Lake View Price is $"+price);
break;
default: price=0;
System.out.println("Invalid price is $"+price);
}
}
}
*/Task #2:
Add a prompt to the Condo Sales application to ask the user to specify a (1) garage or a (2) parking space, but only if the condo view selection is valid. Add $5,000 to the price of any condo with a garage. If the parking value is invalid, display an appropriate message and assume that the price is for a condo with no garage. Save the file as CondoSales2.java.
*/
import java.util.Scanner;
class CondoSales2
{
public static void main(String[] args)
{
int view;
int additionalChoice;
double price;
boolean condoSelected=false;
Scanner in=new Scanner(System.in);
System.out.println("Select View ");
System.out.print("1)Park view 2)Golf course view 3)Lake view ");
view=in.nextInt();
in.nextLine();
switch(view)
{
case 1:
condoSelected=true;
price=150000;
System.out.println("You Have Selected Park View Price is $"+price);
break;
case 2:
condoSelected=true;
price=170000;
System.out.println("You Have Selected Golf Course View Price is $"+price);
break;
case 3:
condoSelected=true;
price=210000;
System.out.println("You Have Selected Lake View Price is $"+price);
break;
default:
condoSelected=false;
price=0;
System.out.println("Invalid price is $"+price);
}
if(condoSelected)
{
System.out.println("Enter Details if Required 1)Garage 2)Parking Space ");
additionalChoice=in.nextInt();
if(additionalChoice==1||additionalChoice==2)
{
price +=5000;
System.out.println("Total Cost = $"+price+" ");
}
else
{
System.out.println("Total Cost =$"+price+" ");
}
}
}
}
Explanation / Answer
Here is the Simple JAVA Program:
A)
import java.util.Scanner;
public class CondoSales
{
public static void main(String args [])
{
Scanner scan = new Scanner(System.in);
System.out.println("Press 1 for parkview, 2 for golf course view, or 3 for lake view");
int a = scan.nextInt();
if(a == 1)
System.out.println("Park View: $150,000");
else if(a == 2)
System.out.println("Golf Course View: $170,000");
else if(a == 3)
System.out.println("Lake View: $210,000");
else
System.out.println("Invalid Code: $0");
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.