0% found this document useful (0 votes)
28 views

Java

This Java program allows a user to calculate the total charge for ordering garage door openers. It prompts the user to input the quantity ordered, unit price, and contractor credit. It then calls a method to calculate the order total by applying a 15% discount, 9.5% tax, and subtracting the credit amount. The total charge is printed and the user is prompted to calculate another order or quit.

Uploaded by

Jenil Donda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Java

This Java program allows a user to calculate the total charge for ordering garage door openers. It prompts the user to input the quantity ordered, unit price, and contractor credit. It then calls a method to calculate the order total by applying a 15% discount, 9.5% tax, and subtracting the credit amount. The total charge is printed and the user is prompted to calculate another order or quit.

Uploaded by

Jenil Donda
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.util.

Scanner;

public class GarageDoorOpener {


public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String choice = "Y";

while (choice.equalsIgnoreCase("Y")) {
int quantity = 0;
double unitPrice = 0.0;
double credit = 0.0;

// Ask user for inputs


System.out.print("Enter the quantity of garage door openers ordered:
");
if (input.hasNextInt()) {
quantity = input.nextInt();
} else {
System.out.println("Invalid input. Please enter a valid integer.");
input.next();
continue;
}

System.out.print("Enter the unit price of the garage door openers: ");


if (input.hasNextDouble()) {
unitPrice = input.nextDouble();
} else {
System.out.println("Invalid input. Please enter a valid decimal
number.");
input.next();
continue;
}

System.out.print("Enter the credit that the contractor has with the


company: ");
if (input.hasNextDouble()) {
credit = input.nextDouble();
} else {
System.out.println("Invalid input. Please enter a valid decimal
number.");
input.next();
continue;
}

// Calculate total charge


double totalCharge = calculateOrders(quantity, unitPrice, credit);

// Print total charge


System.out.printf("The total charge is $%.2f%n", totalCharge);

// Ask user if they want to try again


System.out.print("Do you want to try again? (Y/N) ");
choice = input.next();
}
}

public static double calculateOrders(int quantity, double unitPrice, double


credit) {
final double DISCOUNT_RATE = 0.15;
final double TAX_RATE = 0.095;

double totalAmount = quantity * unitPrice;


double discountAmount = totalAmount * DISCOUNT_RATE;
double taxableAmount = totalAmount - discountAmount;
double taxAmount = taxableAmount * TAX_RATE;
double totalCharge = taxableAmount + taxAmount - credit;

return totalCharge;
}
}

You might also like