Solved

invoice code written in java

Posted on 2003-11-10
5
449 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 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to Alipay 10 94
import as existing maven project 3 77
Read CLOB data from Oracle using JAVA 3 40
Eclipse neon2 "Java build path" correctness 7 43
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

732 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