58.9k views
3 votes
Caitlyn's Crafty Creations computes a retail price for each product as the cost of materials plus $14 multiplied by the number of hours of work required to create the product, plus $6 shipping and handling. Caitlyn’s Crafty Creations is having a semi-annual sale now, and everything is 25% off before shipping and handling: Retail price = 0.75 * (cost of materials + (14 * hours of work)) + 6 Create a class that contains a main () method that prompts the user for the name of a product (for example, "woven purse"), the cost of materials before discount and the number of hours of work required. Pass the numeric data to a method that computes the retail price of the product and returns the computed value to the main () method where the product name and retail price are displayed.

User GuiSim
by
5.9k points

1 Answer

2 votes

Answer:

The Java code is given below with appropriate comments and output

Step-by-step explanation:

CaitlynsCraftyCreations.java

package org.students;

import java.util.Scanner;

public class CaitlynsCraftyCreations {

public static void main(String[] args) {

//Scanner object is used to read the values entered by the user.

Scanner sc = new Scanner(System.in);

//Getting Product Name From the User

System.out.print("The name of a product :");

String nameOfProduct=sc.nextLine();

//Getting the cost of the material entered by the user.

System.out.print("The cost of materials : $");

double costOfMaterials=sc.nextDouble();

//Getting the Hours of work entered by the user..

System.out.print("Enter the hours of work :");

double hoursOfWork =sc.nextDouble();

/*

* Calling the method

* by passing the costOfMeterials and hoursOfWork as parameters.

* Get the Returned value and stored into a varible of type double.

*/

double retailPrice= findRetailPrice(costOfMaterials,hoursOfWork);

//Displaying the Product name and Its retail price after discount.

System.out.println("The Name of the Product is :"+nameOfProduct);

System.out.println("The Retail Price after Discount is : $"+retailPrice);

}

/*

* This method will find the retail price of the Product after discount.

* @Param costOfMaterials,hoursOfWork

* Return discounted retail price of double type.

*/

private static double findRetailPrice(double costOfMaterials,double hoursOfWork)

{

return 0.75 * (costOfMaterials + (14 * hoursOfWork)) + 6 ;

}

}

___________________________________________________________________________

Output:

The name of a product :Woven Purse

The cost of materials : $500

Enter the hours of work :25

The Name of the Product is :Woven Purse

The Retail Price after Discount is : $643.5

__________________________________________________________________________

User Allyraza
by
4.9k points