I have created a invoice class that asks the user to enter different information about a part, I have also created a loop which goes through three times. the problems I am having are listed below i have been working at this for ages and just cant see what i need to do for it. the program and driver program are listed below also.
oCreate an object eg if num = 0 this will create an object in the first cell of the array:
inv [num] = new Invoice();
oUse the dialog boxes and setters to capture the data as before but include the invoice number ie 1 to 3 as shown below in the dialog box. eg
inv[num].setPartNumber(partNo);
•Print the Invoice heading as before
•Then use another For loop using the getter methods to display the values of each instance variable and the new method getInvoiceAmount to display the total of each line.
•Add each line total and print the overall total.
• have the final dialog box show like below,
part description qty price total
nun01 nut 12 2 $24
bol01 bolt 12 3 $36
scw01 screw 24 1 $24
$84
CODE
/**
* This program demonstrates classes.
*
* @author (Simon Orazi)
* @version (11/05/07)
*/
public class Invoice
{
private String partNumber;
private String description;
private double quantity;
private double price;
public Invoice()
{
partNumber = "";
description = "";
quantity = 0;
price = 0;
}
/**
* The setPart method stores value in part field.
* @param partNumber the value to store in part.
*/
public void setPartNumber(String piece)
{
partNumber = piece;
}
/**
* The setDescription method stores value in part field.
* @param desc the value to store in description.
*/
public void setDescription(String desc)
{
description = desc;
}
/**
* The setQuantity method stores value in part field.
* @param quan the value to store in quantity.
*/
public void setQuantity(double quan)
{
quantity = quan;
}
/**
* The setPrice method stores value in part field.
* @param amount the value to store in price.
*/
public void setPrice(double amount)
{
price = amount;
}
/**
* The getPart method returns value.
* @return the value in the part field.
*/
public String getPartNumber()
{
return partNumber;
}
/**
* The getdescription method returns value.
* @return the value in the description field.
*/
public String getDescription()
{
return description;
}
/**
* The getQuantity method returns value.
* @return the value in the quantity field.
*/
public double getQuantity()
{
return quantity;
}
/**
* The getPrice method returns value.
* @return the value in the price field.
*/
public double getPrice()
{
return price;
}
public double getTotal()
{
return quantity * price;
}
}
And now the Driver ProgramCODE
import javax.swing.JOptionPane;
/**
* This program demonstrates classes.
*
* @author (Simon Orazi)
* @version (11/05/07)
*/
public class TestInvoice
{
public static void main(String[] args)
{
String input;
double number;
double partTotal;
double invoiceTotal;
Invoice myInvoice = new Invoice();
for (int index = 0; index < 3; index++)
{
input = JOptionPane.showInputDialog("Please enter Part " + (index + 1) + " Number");
myInvoice.setPartNumber(input);
input = JOptionPane.showInputDialog("Please enter Part " + (index + 1) + " Description");
myInvoice.setDescription(input);
input = JOptionPane.showInputDialog("Please Enter Quantity of Part " + (index + 1) + " Required");
number = Double.parseDouble(input);
myInvoice.setQuantity(number);
input = JOptionPane.showInputDialog("Please enter Part " + (index + 1) + " Price");
number = Double.parseDouble(input);
myInvoice.setPrice(number);
partTotal = myInvoice.getQuantity() * myInvoice.getPrice();
}
invoiceTotal =
JOptionPane.showMessageDialog(null, "Part " + " " + "Description" + " " + "Qty" + " " + "Price\n" +
" $" + myInvoice.getPartNumber() + " $" + myInvoice.getDescription() + " $" +
myInvoice.getQuantity() + " $" + myInvoice.getPrice() + "\n" + " $" + partTotal);
}
}