Solved

invoice code written in java

Posted on 2003-11-10
5
444 Views
Last Modified: 2006-11-17
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
Comment
Question by:dam5800
  • 4
5 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 50 total points
ID: 9716481
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 9716500
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
 
LVL 2

Expert Comment

by:Dannin
ID: 9716978
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 9717043
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
 
LVL 86

Expert Comment

by:CEHJ
ID: 9718212
:-)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now