I have a simple class named as Invoice, in which I'm taking four instance variables to intialize PART NO, PART DESCRIPTION, QUANTITY PURCHASED & PRICE PER EACH ITEM.
I have made getters and setters for each variable, also a method is created in the same class as InvoiceAmount which Calculates the amount and returns the result.
Now in the main class called InvoiceTest, I am taking inputs for all these values and calling the method InvoiceAmount but the amount which is returned is Always Zero. Can some one help me out and figure out the problem for me?
Here is the code.
Invoice.java
public class Invoice {
String partNumber;
String partDescription;
int quantityPurchased;
double pricePerItem;
public Invoice(String pNumber, String pDesc, int qPurchased, double pItem){
partNumber = pNumber;
partDescription = pDesc;
quantityPurchased = qPurchased;
pricePerItem = pItem;
}
public Invoice() {
// TODO Auto-generated constructor stub
}
public void setPartNumber(String pNumber){
pNumber = partNumber;
}
public String getPartNumber(){
return partNumber;
}
public void setPartDescription(String pDesc){
pDesc = partDescription;
}
public String getPartDescription(){
return partDescription;
}
public void setQuantityPurchased(int qPurchased){
qPurchased = quantityPurchased;
}
public int getQuantityPurchased(){
return quantityPurchased;
}
public void setPricePerItem(double pItem){
pItem = pricePerItem;
}
public double getPricePerItem(){
return pricePerItem;
}
public double InvoiceAmount (double invoiceAmount)
{
invoiceAmount = quantityPurchased * pricePerItem;
return invoiceAmount;
}
}
InvoiceTest.java
import java.io.ObjectInputStream.GetField;
import java.util.Scanner;
public class InvoiceTest {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
Invoice invoice = new Invoice();
System.out.println("Enter the part number: ");
String partNo = input.nextLine();
invoice.setPartNumber(partNo);
System.out.println("Enter the part description: ");
String partDes = input.nextLine();
invoice.setPartDescription(partDes);
System.out.println("Enter the Quantity to want to purchase: ");
int quantity = input.nextInt();
invoice.setQuantityPurchased(quantity);
System.out.println("Enter the Price per each item: ");
double price = input.nextDouble();
invoice.setPricePerItem(price);
double Amount = 0;
System.out.println("Amount calculated: " + invoice.InvoiceAmount(Amount));
}
}