Answer to Question #336701 in Java | JSP | JSF for Djk

Question #336701

Write a program which consists of a single class called BuyStuff that asks the user for two amounts, adds them, calculates tax at 15%, shows the result to the user, and asks for money. It then compares if the person gave enough money. If so, it displays the amount of change to return otherwise it displays a message asking for more money

1
Expert's answer
2022-05-03T14:18:38-0400

public class BuyStuff {


  public static void main(String[] args) {

    Scanner scanner = new Scanner(System.in);

    System.out.println("Amount 1: ");

    double amount1 = scanner.nextDouble();

    System.out.println("Amount 2: ");

    double amount2 = scanner.nextDouble();

    double sum = addAmounts(amount1, amount2) + tax(addAmounts(amount1, amount2));

    double depMoney = 0;

    double count = 0;


    System.out.println("result: " + sum + " Deposit money: ");

    while (depMoney < sum) {

      count = scanner.nextDouble();

      depMoney = depMoney + count;

      if (depMoney >= sum) {

        break;

      }

      System.out.println("result: " + depMoney + " left to deposit: " + (sum - depMoney) + " Deposit more money: ");

    }

    System.out.println("Ok!");

    scanner.close();


  }


  private static double addAmounts(double a, double b) {

    return a + b;

  }


  private static double tax(double a) {

    return a * 15 / 100;

  }

}


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 the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS