Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Retail Price Calculator Write a JAVA program that asks the user to enter an item

ID: 3789823 • Letter: R

Question

Retail Price Calculator

Write a JAVA program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: (If an item's wholesale cost is 5.00 and its markup percentage is 100 percent, then the item's retail price is 10.00).

Use a method (called getInput) - this will be used twice with unique prompts for the different types of input required

Use a method (called calculateRetail) - that receives the wholesale cost and the markup percentage as arguments, and returns the retail price of the item.

Use a method (called displayAll) - that will display the wholesale cost, the markup percentage, and the retail price of the item (all displayed to 2 decimal places)

Explanation / Answer

PriceCalculator.java

import java.util.Scanner;;

public class PriceCalculator {
  
   public static void main(String[] args) {

       //Declaring the variables
       double item_wholesale_cost,markup_perc,retail_price;
      
      
       //Getting the whole sale price of an item
       System.out.print("Enter the Wholesale price of an item :$");
       item_wholesale_cost=getInput();
      
       //Getting the markup percentage
       System.out.print("Enter the markup percentage :%");
       markup_perc=getInput();
      
       /* calling the method calculateRetail() by passing
       * the whole sale price and markup percentage as arguments
       */
       retail_price=calculateRetail(item_wholesale_cost,markup_perc);
      
       //Calling the method which will display the result
       displayAll(item_wholesale_cost,markup_perc,retail_price);

   }

   //This method will display the output
   private static void displayAll(double item_wholesale_cost,
           double markup_perc, double retail_price) {
                  
               //Displaying the results
       System.out.printf("The Wholesale cost of an item is :$%.2f",item_wholesale_cost);
       System.out.println(" Markup percentage is :%"+markup_perc);
       System.out.printf("The Retail Price of an item is :$%.2f",retail_price);
          
      
   }

   //this method will calculate the retail price of an item
   private static double calculateRetail(double item_wholesale_cost,
           double markup_perc) {
      
       return (item_wholesale_cost+(item_wholesale_cost*(markup_perc/100)));
   }

   //This method is used to get the inputs
   private static double getInput() {
       double val;
      
       //Scanner object is used to get the inputs entered by the user
       Scanner sc=new Scanner(System.in);
      
       val=sc.nextDouble();
       return val;
   }

}

______________________

output:

Enter the Wholesale price of an item :$625
Enter the markup percentage :%50
The Wholesale cost of an item is :$625.00
Markup percentage is :%50.0
The Retail Price of an item is :$937.50

_____________Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote