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