Help: Methods and Arguments
Hi I'm writing a program about Kitchen Sales.
In this program, it will have to work out the total amount and the current unit price, the kind of fittings chosen from Basic, Standard and Deluxe and whether the units are to be installed or not.
There will a method that works out the basic price for the number of cupboard units the user input. This method will then be passes the number of of units and the unit price and return the result of multiplying them together.
The answer is passes back to the main method and it will print out this basic price.
The result of the calculation should then be passes by the main method to a second method that works out the total cost taking into account the kind of cupboard installed. The cost is unchanged for basic units, is multiplied by 2 for standard units and multiplied by 3 for deluxe units.
if the kitchen is to be installed(1000 added) otherwise nothing will be added to the cost
This is what I have done
Code:
public static void main(String[] param)
{
fittedkitchen();
System.exit(0);
}
public static void fittedkitchen()
{
String cupboardunits = getText("Please type in the number of cupboard units.");
int numofunits = Integer.parseInt(cupboardunits);
String pricePerUnits = getText("Please type in the individual unit price.");
int unitPrice = Integer.parseInt(pricePerUnits);
JOptionPane.showMessageDialog(null,"The basic price is " + calculatePrice(numofunits,unitPrice));
String fittings = getText("Type in the fittings according to the number given:\n\n1.Basic\n2.Standard\n3.Deluxe");
int fitted = JOptionPane.showConfirmDialog(null, "Is the kitchen to be installed ?","", JOptionPane.YES_NO_OPTION);
int cost =0;
if(fittings.equalsIgnoreCase("B")){
cost =1;
}else if(fittings.equalsIgnoreCase("S")){
cost =2;
}else if(fittings.equalsIgnoreCase("D")){
cost =3;
}
//if ((number-1) <= types.length)
//{
int price = cost*calculatePrice(numofunits,unitPrice);
if(fitted == 0)
{
price = price + 1000;
}
else
{
}
JOptionPane.showMessageDialog(null, price + " pounds");
}
public static int calculatePrice(int unit, int price){
return unit * price;
}
public static String getText(String msg)
{
String txt = null;
while (txt == null || txt.trim().equals(""))
{
txt = JOptionPane.showInputDialog(msg);
}
return txt;
}
Basically the main method should ask for the base price, number of units and pass them to the first method to work out the basic cost. This basic cost will be returned to main which prints it out. The main should then asks for the kind of fitting and whether it is to be installed or not and passes the information along with basic cost to the second method. It then returns the final overall estimate to the main.
But the I only have one extra method to work the base price. How should I do the rest?
Any help would be greatly appreciated.