Question

In: Computer Science

Write a Java program called RevenueAdvanced to calculate the revenue from a sale based on the...

Write a Java program called RevenueAdvanced to calculate the revenue from a sale based on the unit price and quantity of a product input by the user. (use if and if-else statements)
• The discount rate is
o 0% for the quantity purchased between 1 and 49 units.
o 10% for the quantity purchased between 50 and 99 units.
o 15% for the quantity purchased between 100 and 149 units.
o 25% for the quantity purchased greater than or equal150 units.
New: Catch any invalid inputs as the following, if so, output a warning message and end the program.
o Employee Number: should be nine digits, no zero leading, non-negative, and no decimal points.
o Item Price: should be within the range [0.25, 100], and non-negative.
o Quantity: non-negative, and no decimal points.

Demo (1) a successful run:
Welcome to "Temple" store
Enter item price: 10
Enter quantity: 60
The item price is: $10.0
The order is: 60 item(s)
The cost is: $600.0
The discount is: 10.0%
The discount amount is: $60.0
The total is: $540.0
Thank You for using "Temple" store

Demo (2) a failed run:
Welcome to "Temple" store
Enter item price: -30
This is not a valid item price.
Please run the program again
Thank You for using "Temple" store

Demo (3) another failed run:
Welcome to "Temple" store
Enter item price: 10
Enter quantity: -90
This is not a valid quantity order.
Please run the program again
Thank You for using "Temple" store

Solutions

Expert Solution

Explanation:

here is the code which asks for the item quantity and the price of each item from the user and then calculates the total of the amount and shows the discount and other details on the screen.

Code:

import java.util.Scanner;

public class Main
{
   public static void main(String[] args) {
       System.out.println("Welcome to \"Temple\" store");
      
       Scanner sc = new Scanner(System.in);
  
       System.out.print("Enter item price: ");
       double item_price = sc.nextDouble();
      
       if(item_price<0.25 || item_price>100)
       {
       System.out.println("This is not a valid item price.");
       System.out.println("Please run the program again");
      
       }
       else
       {
       System.out.print("Enter quantity: ");
       double quantity = sc.nextDouble();
       if(quantity<0 || quantity-(int)quantity >0)
       {
       System.out.println("This is not a valid quantity order.");
       System.out.println("Please run the program again");
       }
       else
       {
      
       System.out.println("The order is: "+(int)quantity+" item(s)");
       System.out.println("The cost is: $"+(quantity*item_price));
      
       int discount;
      
       if(quantity<50)
       {
       discount = 0;
       }
       else if(quantity<100)
       {
       discount = 10;
       }
       else if(quantity<150)
       {
       discount = 15;
       }
       else
       {
       discount = 25;
       }
      
       System.out.println("The discount is: "+discount+"%");
       System.out.println("The discount amount is: $"+(discount*(quantity*item_price)/100.0));
       System.out.println("The total is: $"+((quantity*item_price)-(discount*(quantity*item_price)/100.0)));
      
      
       }
       }
      
       System.out.println("Thank you for using \"Temple\" store");
      
      
   }
}

Output:

PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!
PLEASE COMMENT IF YOU NEED ANY HELP!


Related Solutions

Write a complete Java program called CharCounter that gets two Strings called inputWord and inputCharacter from...
Write a complete Java program called CharCounter that gets two Strings called inputWord and inputCharacter from the user at the command line. Check that the character has a length of 1. If it doesn't, provide the user with suitable feedback and conclude the program. If the character length is valid (i.e., it has a length of 1), use a while loop to check each position in the inputWord variable and return the number of times the character occurs. For example,...
In Java: Write a program called F2C that allows the user to convert from degrees Fahrenheit...
In Java: Write a program called F2C that allows the user to convert from degrees Fahrenheit to degrees Celsius. The program should prompt for a temperature in Fahrenheit and output a temperature in Celsius. All calculations should be done in in ints, so be careful of truncation.
Using Java, write a program that takes in two integers from the keyboard called m and...
Using Java, write a program that takes in two integers from the keyboard called m and n, where m > n. Your program should print the first m natural numbers (m..1) downwards in n rows.
DO THIS PROGRAM IN JAVA Write a complete Java console based program following these steps: 1....
DO THIS PROGRAM IN JAVA Write a complete Java console based program following these steps: 1. Write an abstract Java class called Shape which has only one abstract method named getArea(); 2. Write a Java class called Rectangle which extends Shape and has two data membersnamed width and height.The Rectangle should have all get/set methods, the toString method, and implement the abstract method getArea()it gets from class Shape. 3. Write the driver code tat tests the classes and methods you...
URGENT!!! DO THIS PROGRAM IN JAVA Write a complete Java console based program following these steps:...
URGENT!!! DO THIS PROGRAM IN JAVA Write a complete Java console based program following these steps: 1. Write an abstract Java class called Shape which has only one abstract method named getArea(); 2. Write a Java class called Rectangle which extends Shape and has two data membersnamed width and height.The Rectangle should have all get/set methods, the toString method, and implement the abstract method getArea()it gets from class Shape. 3. Write the driver code tat tests the classes and methods...
Java program Write a class called Animal that contains a static variable called count to keep...
Java program Write a class called Animal that contains a static variable called count to keep track of the number of animals created. Your class needs a getter and setter to manage this resource. Create another variable called myCount that is assigned to each animal for each animal to keep track of its own given number. Write a getter and setter to manage the static variable count so that it can be accessed as a class resource
Program: Java Write a Java program using good programming principles that will aggregate the values from...
Program: Java Write a Java program using good programming principles that will aggregate the values from several input files to calculate relevant percentages and write the values to an output file. You have been tasked with reading in values from multiple files that contains different pieces of information by semester. The Department of Education (DOE) would like the aggregate values of performance and demographic information by academic year. A school year begins at the fall semester and concludes at the...
Program: Java Write a Java program using good programming principles that will aggregate the values from...
Program: Java Write a Java program using good programming principles that will aggregate the values from several input files to calculate relevant percentages and write the values to an output file. You have been tasked with reading in values from multiple files that contains different pieces of information by semester.    The Department of Education (DOE) would like the aggregate values of performance and demographic information by academic year. A school year begins at the fall semester and concludes at the...
Write a program called Assignment3 (saved in a file Assignment3 .java) that asks a user to...
Write a program called Assignment3 (saved in a file Assignment3 .java) that asks a user to enter two strings. First, the program prompts: Please enter a string. The program should read in the string, and prompts: Please enter another string. The program reads in two strings and it prints a menu to the user. The program asks for user to enter an option and performs one of the following: Here are the options on the menu: Option a: checks if...
Write a Java program to compute the income after tax of an employee based on the...
Write a Java program to compute the income after tax of an employee based on the following rule of tax rate. Assuming the salary is $22000, display the tax and the income after tax. 12% if salary ≥ 25,000 5% if salary < 10,000 Otherwise 8% will be applied Write a Java program to compute and display the sum of the numbers that can be both divisible by 6 and 8 from 1 to 500. Suppose there is a list...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT