Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package MidExam.O1;
- import java.util.Scanner;
- public class O1ComputerStore {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String command = scanner.nextLine();
- double sum = 0;
- while (command.length() < 7) {
- double product = Double.parseDouble(command);
- if (product == 0) {
- System.out.println("Invalid order!");
- } else if (product < 0) {
- System.out.println("Invalid price!");
- } else {
- sum += product;
- }
- command = scanner.nextLine();
- }
- if (command.equals("regular") && sum <= 0 || command.equals("special") && sum <= 0) {
- System.out.println("Invalid order!");
- } else {
- System.out.println("Congratulations you've just bought a new computer!");
- System.out.printf("Price without taxes: %.2f$%n", sum);
- double taxes = sum * 1.2 - sum;
- double totalPrice = sum + taxes;
- if (command.equals("special")) {
- totalPrice = totalPrice * 0.90;
- }
- System.out.printf("Taxes: %.2f$%n", taxes);
- System.out.println("-----------");
- System.out.printf("Total price: %.2f$", totalPrice);
- }
- }
- }
Add Comment
Please, Sign In to add comment