Directions from book - Write a program that asks the user to enter an item\'s wh
ID: 3763684 • Letter: D
Question
Directions from book - 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. You must ATTACH the .java file before submitting the assignment.
Explanation / Answer
/*The purpose of program is to calculate retail price of item using wholesale cost and markup percentage. I am Mr. Single to help you out*/
// As I do not find any option to attach file so you can copy paste the code in text file and save it with Lastname05b.java
import java.util.Scanner;
public class Lastname05b {
// Method to calculate Retail Price and It is static no need to call using object.
static double calculateRetail(double c,int p)
{
return (c*p)/100+c;
}
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
System.out.println("Enter Whole Cost");
Double Wcost=s.nextDouble();
System.out.println("Enter markup percentage in decimal only like 10,20 etc");
int markup=s.nextInt();
double retailPrice =calculateRetail(Wcost,markup);
System.out.println("The retail price of the item is " +retailPrice);
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.