You must describe what you do every step of the way with comments!!! Write a pro
ID: 3766999 • Letter: Y
Question
You must describe what you do every step of the way with comments!!!
Write a 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
--If an item's wholesale cost is 5.00 and its markup percentage is 50 percent, then the item's retail price is 7.50
The program should have a method named calculateRetail that receives the wholesale cost and the markup percentage as arguments, and returns the retail price of the item. Name the class Lastname05b and save the file as Lastname05b.java. USE YOUR LAST NAME INSTEAD OF THE WORD LASTNAME.
Use the Scanner class to grab the wholesale cost (double) and markup percentage (double).
Tell the user to enter a decimal instead of a percentage (.25, .50, etc)
Display the return value using a println() method in the MAIN method of your code: "The retail price of the item is " + retailPrice
The calculateRetail method should accept two double arguments and return a double.
HINT. You obtain the retail price by multiplying the wholesale cost by the percentage and ADDING it to the wholesale cost.
RETAIL PRICE = (WHOLESALE COST * MARKUP PERCENTAGE) + WHOLESALE COST
or
RETAIL PRICE = WHOLESALE COST * (1 + MARKUP PERCENTAGE)
Not only must your program meet the requirements of the problem,you must also:
Include your name and the program's purpose in a comment that appears before the class declaration.
Comment further in the lab as necessary.
Use the correct comment type for the Method, and parameters and return values
Follow the naming guidelines for Methods.
Your code should be "neat" with the proper indentation.
this an example of what it should look like.
/**
This program demonstrates hierarchical method calls.
*/
public class DeepAndDeeper
{
public static void main(String[] args)
{
System.out.println("I am starting in main.");
deep();
System.out.println("Now I am back in main.");
}
/**
The deep method displays a message and then calls
the deeper method.
*/
public static void deep()
{
System.out.println("I am now in deep.");
deeper();
System.out.println("Now I am back in deep.");
}
/**
The deeper method simply displays a message.
*/
public static void deeper()
{
System.out.println("I am now in deeper.");
}
}
Explanation / Answer
Here is the code for you. If you need any further modifications, just revert to me.
import java.io.*;
import java.util.Scanner;
public class RetailPriceCalculator
{
static double calculateRetail(double wholesalePrice, double markup) //Function to calculate the Retail price.
{
return wholesalePrice * (1 + markup); //Formula to calculate the Retail price.
}
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Enter the items wholesale cost: "); //Prompt the user to enter the wholesale cost.
double wholesalePrice = in.nextDouble(); //Read wholesalecost
System.out.print("Enter the mark up percentage (as a decimal value): "); //Prompt the user to enter the markup.
double markup = in.nextDouble(); //Read markup.
double retailPrice = calculateRetail(wholesalePrice, markup);//Call the function to calculate the Retail Price.
String output = String.format("The retail price of the item is: %.2f",retailPrice); //Convert the retailPrice to 2 digit precision.
System.out.println(output); //Display the output.
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.