Java Programming Write a program that computes the total cost of purchasing a va
ID: 638639 • Letter: J
Question
Java Programming
Write a program that computes the total cost of purchasing a variable number of three different items.Your program reads in three decimal numbers (item costs) and three integers (the number of each item purchased) from the console. You are to multiply the decimal numbers representing the costs times the integer specifying the number of that item purchased for each item purchased to get the total cost of each item. You must then compute the sum of these three costs and print it out on the console in US currency format with the label:
Explanation / Answer
package inventory2;
public class Items
{
private String Name;
private double pNumber, Units, Price;
public Items()
{
Name = "";
pNumber = 0.0;
Units = 0.0;
Price = 0.0;
}
//constructor
public Items(String productName, double productNumber, double unitsInStock, double unitPrice)
{
Name = productName;
pNumber = productNumber;
Units = unitsInStock;
Price = unitPrice;
}
//setter methods
public void setName(String n)
{
Name = n;
}
public void setpNumber(double no)
{
pNumber = no;
}
public void setUnits(double u)
{
Units = u;
}
public void setPrice(double p)
{
Price = p;
}
//getter methods
public String getName()
{
return Name;
}
public double getpNumber()
{
return pNumber;
}
public double getUnits()
{
return Units;
}
public double getPrice()
{
return Price;
}
public double calculateTotalPrice()
{
return (Units * Price);
}
public double calculateAllItemsTotalPrice() //i need method to calculate total cost for all items in array
{
return (TotalPrice );
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.