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

In java Write a program called FileProcessor.java that reads the file numbers.txt, and: Calculate the total...
In java Write a program called FileProcessor.java that reads the file numbers.txt, and: Calculate the total number of numbers in the file, Calculate the sum of all the numbers in the file, Calculate the average of all the numbers in the file, Find the smallest value of all the numbers in the file, Find the largest value of all the numbers in the file, Calculate the standard deviation of all the numbers in the file
Write a java program that simulates thousands of games and then calculate the probabilities from the...
Write a java program that simulates thousands of games and then calculate the probabilities from the simulation results. Specifically in the game, throw two dice, the possible summations of the results are: 2, 3, ..., 12. You need to use arrays to count the occurrence and store the probabilities of all possible summations. Try to simulate rolling two dice 100, 1000, 10,0000 times, or more if needed. Choose one simulation number so that the probabilities you calculated is within 1%...
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...
Must be in Java Write a program called showTwos that shows the factors of 2 in...
Must be in Java Write a program called showTwos that shows the factors of 2 in a given positive integer (user input) in the range of [16,128]. For example, if user inputs 7, 18, 68, 120, the correctly working program should print the following: 7 = 7 18 = 2 * 9 68 = 2 * 2 * 17 120 = 2 * 2 * 2 * 15
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
Module 1 Program Write a complete Java program in a file called Module1Program.java that reads all...
Module 1 Program Write a complete Java program in a file called Module1Program.java that reads all the lyrics from a file named lyrics.txt that is to be found in the same directory as the running program. The program should read the lyrics for each line and treat each word as a token. If the line contains a double (an integer is also treated as a double) it should use the first double it finds in line as the timestamp for...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT