Hi, thanks for reading my post. A brief background, I just started a Business Information Systems program. I am three weeks into my Java program so my experience with Java is little.

The problem I am trying to solve is a 2 part question. I take pride in my work and I never ask for free answers. The only way to move forward is to solve the problem in front of you.

I have a working solution below but it doesn't meet the requirements. I have made another attempt but it isn't working. Also shown below. Here is the question I am trying to solve:

Part A: Create a class named Invoice containing fields for an item number, name, quantity, price, and total cost. Create instance methods that set the item name, quantity, and price. Also, include a display( ) method that calculates the total cost for the item (as price times quantity), then displays the item number, name, quantity, price, and total cost. Save the class as Invoice.java

Part B: Create a class named TestInvoice whose main( ) method declares three Invoice items. Provide values for each, and display them. Save the application as TestInvoice.java

Here is my working solution, but it does not meet the requirements:

public class Invoice 
{
	
		
		private int itemNum;
		private String itemName;
		private int itemQuant;
		private double itemPrice;
		
		// constructor
		public Invoice()
		{
			itemNum = 0;
			itemName = "";
			itemQuant = 0;
			itemPrice = 0;
		}

		//accessor methods(set/get methods)
		
		public void setitemNum(int a_itemNum) 
		{
			itemNum = a_itemNum;
		}
		
		public int getitemNum()
		{
			return itemNum;
		}
		
		public void setitemName( String a_itemName)
		{
			itemName = a_itemName;
		}
		
		public String getitemName()
		{
			return itemName;
		}
		
		public void setitemQuant(int a_itemQuant)
		{
			itemQuant = a_itemQuant;
		}
		
		public int getitemQuant()
		{
			return itemQuant;
		}
		
		public void setitemPrice(double a_itemPrice)
		{
			itemPrice = a_itemPrice;
		}
		
		public double getitemPrice()
		{
			return itemPrice;
		}
		
		public double getTotal()
		{
			double total = itemPrice * itemQuant;
			return total;
			
		}

	}
public class TestInvoice 
{
	public static void main(String[] args)
	{
	Invoice inv1 = new Invoice();
	
	inv1.setitemNum(12345);
	inv1.setitemName("Shoes");
	inv1.setitemQuant(13);
	inv1.setitemPrice(79.99);
	
	System.out.println("Item #" + inv1.getitemNum() + " | Name: " + inv1.getitemName() + " | Quantity:  " +  inv1.getitemQuant()
			+ " | Price: " + inv1.getitemPrice()+ " | Total Cost: " + inv1.getTotal());
	
	Invoice inv2 = new Invoice();
	
	inv2.setitemNum(54321);
	inv2.setitemName("Pants");
	inv2.setitemQuant(12);
	inv2.setitemPrice(59.99);
	
	System.out.println("Item #" + inv2.getitemNum() + " | Name: " + inv2.getitemName() + " | Quantity:  " +  inv2.getitemQuant()
			+ " | Price: " + inv2.getitemPrice()+ " | Total Cost: " + inv2.getTotal());
	
Invoice inv3 = new Invoice();
	
	inv3.setitemNum(13579);
	inv3.setitemName("Shirt");
	inv3.setitemQuant(15);
	inv3.setitemPrice(49.99);
	
	System.out.println("Item #" + inv3.getitemNum() + " | Name: " + inv3.getitemName() + " | Quantity:  " +  inv3.getitemQuant()
			+ " | Price: " + inv3.getitemPrice()+ " | Total Cost: " + inv3.getTotal());
	}
}

As you can see, I do not have the displayLine() method in the Invoice.java file is missing. Every attempt I make fails.

My attempts to include the displayLine() method look something likethis...

At the bottom of the Invoice.java file...

public static void displayLine(int itemNum, String itemName,int itemQuant,double itemPrice)
		  	   {   
		  	    
			  	double totalCost = itemPrice * itemQuant;
			  	
			  	System.out.println(itemNum); 
		  	    System.out.println(itemName); 
		  	    System.out.println(itemQuant); 
		  	    System.out.println(itemPrice); 
		  	    System.out.println(totalCost);
		  	  
		  	    }

And I insert the following in the TestInvoice.java file under every instance of Inventory..

inv1.displayLine(itemNum, itemName,itemQuant,itemPrice);
inv2.displayLine(itemNum, itemName,itemQuant,itemPrice);
inv3.displayLine(itemNum, itemName,itemQuant,itemPrice);

Sorry for the long message, but I wanted to show my effort. Can anybody out there help me finish this problem.I am STUCK. I really appreciate all the help.

Thanks!

Every attempt I make fails

Please copy and paste the error messages here.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.