67 035
Assignments Done
99,3%
Successfully Done
In November 2018

Answer to Question #46277 in Java | JSP | JSF for Fel

Question #46277

Java programming question
.
Write a program to take an order for a computer system. The basic system costs 375.99. the user then has to choose from a 38 cm screen(costing 75.99) or a 43 cm screen (costing 99.99).

the following extras are optional.

Item Price
DVD/CD writer 65.99
printer 125.00

The program should allow the user to select from these extras and then display the final cost of the order.


Expert's answer
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class ComSysOrder {
public static void main(String[] args) {
BufferedReader bRead = new BufferedReader(new InputStreamReader(System.in));
double cost = 375.99;

System.out.println("The basic configuration: $" + cost);
System.out.println("Please choose screen:\n1 - 38 cm, $75.99\n2 - 43 cm, $99.99");
int option = 0;
do {
try {
option = Integer.parseInt(bRead.readLine());
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
switch (option) {
case 1:
cost += 75.99;
break;
case 2:
cost += 99.99;
break;
default:
option = 0;
break;
}
}
while (option == 0);

option = 0;
do {
System.out.println("Please choose optional extras:\n1 - DVD/CD writer, $65.99\n2 - printer, $125.00\n3 - none");
try {
option = Integer.parseInt(bRead.readLine());
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
switch (option) {

case 1:
cost += 65.99;
break;
case 2:
cost += 125.0;
break;
case 3:
default:
option = 3;
break;
}
}
while (option != 3);

System.out.println("The final cost is $" + cost);
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions