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.
1
Expert's answer
2014-09-12T13:45:04-0400
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);
Comments
Leave a comment