Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 454
  • Last Modified:

invoice code written in java

I have to write a program that displays an invoice of several items such as item name, item id number, quantity, proce, and total cost on each line for the quantity and item cost. I have to use two classes, the first class Inv contains the item data and methods to get and set the item name, quantity, and price. The other class created objects for the items and uses the objects to call the set and get methods. Below is what I have so far, I'm not sure what to do next, I'm a beginner at this.
public class Invoice
{
      private int itemIdNumber;
      private String itemName;
      private int itemQuantity;
      private float itemPrice;
      private float itemTotalCost;
      
      public int getitemIdNumber ( )
      {
            return itemIdNumber;
      }
      public void setItemIdNum (int num)
      {
            itemIdNumber = num;
      }
      public StringgetName ( )
      {
            return itemName;
      }
      public void setName (String name)
      {
            itemName=name;
      }
      public int getQuantity ( )
      {      
            return itemQuantity;
      }
      public void setQuantity (int qua)
      {
            itemQuantity = qua;
      }
      public float getPrice ( )
      {
            return itemPrice;
      }
      public void setPrice (float pri)
      {
            itemPrice = pri;
      }
      public float getTotalCost ( )
      {
            return itemTotalCost;
      }
      public void setTotalCost (float tot)
      {
            itemTotalCost=tot;
      }
}
0
dam5800
Asked:
dam5800
  • 4
1 Solution
 
CEHJCommented:
That's OK. What you should do, with most classes anyway actually, is override the toString method of your class:

public String toString() {
   return "Name=" + name;
}

and put the other variables in
0
 
CEHJCommented:
That should be 'itemName' of course.

Your 'controlling' class can then say

System.out.println(myInvoice);

where 'myInvoice' is a variable of type Invoice
0
 
DanninCommented:
Honestly I think an invoice and item should be 2 different classes since 1 invoice will have or could possibly have more then 1 item in it. or an inner class that more up to you. For handeling it I suggest you with another class as u say what you can do it make a small text menu with serveral options depending on the option selected for example:


1: Display an Item/Invoice
2: Buy(Set) and item or make a new purchase
3: Quit this menu

I'll select option 2 and in doing this I'll call the set methods and att info to it. After your done u can redisplay the menu and make another selection for example option 1 which will display the info your inputed last. Hope this is a good guide line=)
0
 
CEHJCommented:
In the real world, this sort of thing is reasonably complex as there are one-to-many realtionships involved. But keep it simple for now - you can extend it later maybe.
0
 
CEHJCommented:
:-)
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now