[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

invoice code written in java

Posted on 2003-11-10
5
Medium Priority
?
453 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
5 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 200 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

650 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