Results 1 to 9 of 9
  1. #1
    cherians is offline Member
    Join Date
    Oct 2013
    Posts
    5
    Rep Power
    0

    Post Invoice java program

    Hello,
    I was wondering if some one could help me find what I did wrong on this program I got the class for this program to run but running into problems with the constructor. Please help I'm still kind of clueless as far as java goes lol, but excited about learning.
    class: public class Invoice
    {
    private String partNumber;
    private String partDescription;
    private int quantity;
    private double pricePerItem;

    // four-argument constructor
    public Invoice( String part, String description, int count,
    double price )
    {
    partNumber = part;
    partDescription = description;

    if ( count > 0 ) // determine whether count is positive
    quantity = count; // valid count assigned to quantity

    if ( price > 0.0 ) // determine whether price is positive
    pricePerItem = price; // valid price assigned to pricePerItem
    } // end four-argument Invoice constructor

    // set part number
    public void setPartNumber( String part )
    {
    partNumber = part;
    } // end method setPartNumber

    // get part number
    public String getPartNumber()
    {
    return partNumber;
    } // end method getPartNumber

    // set description
    public void setPartDescription( String description )
    {
    partDescription = description;
    } // end method setPartDescription

    // get description
    public String getPartDescription()
    {
    return partDescription;
    } // end method getPartDescription

    // set quantity
    public void setQuantity( int count )
    {
    if ( count > 0 ) // determine whether count is positive
    quantity = count; // valid count assigned to quantity

    if ( count <= 0 ) // determine whether count is zero or negative
    quantity = 0; // invalid count; quantity set to 0
    } // end method setQuantity

    // get quantity
    public int getQuantity()
    {
    return quantity;
    } // end method getQuantity

    // set price per item
    public void setPricePerItem( double price )
    {
    if ( price > 0.0 ) // determine whether price is positive
    pricePerItem = price; // valid price assigned to pricePerItem

    if ( price <= 0.0 ) // determine whether price is zero or negative
    pricePerItem = 0.0; // invalid price; pricePerItem set to 0.0
    } // end method setPricePerItem

    // get price per item
    public double getPricePerItem()
    {
    return pricePerItem;
    } // end method getPricePerItem

    // calculates and returns the invoice amount
    public double getInvoiceAmount()
    {
    return getQuantity() * getPricePerItem(); // calculate total cost
    } // end method getPaymentAmount
    } // end class Invoice


    Constructor: import java.util.Scanner;
    public class InvoiceApp
    {

    public static void main (String [] args)
    {
    Invoice totalInvoice = new Invoice ();
    Scanner input = new Scanner (System.in);
    int quantity;
    double price;
    double invoiceAmount;

    System.out.print("Enter quantity for purchase: ");
    quantity = input.nextInt();
    System.out.print("Enter item price: ");
    price = input.nextDouble();
    invoiceAmount = quantity * price;
    System.out.printf ( "\nMultiplying Quantity by Price per Item\n\n",
    invoiceAmount);

    System.out.printf( "invoice total: ", totalInvoice.getInvoiceAmount() );
    }

    }

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default Re: Invoice java program

    Saying you have a problem is not very informative. You wouldn't be here unless you had a problem. You need to provide as many details as you can.

    Do you get errors when you compile or run your code? Then post the exact message here.
    Does the program not behave as expected? Then post what your input was, what incorrect output or behaviour you got and what you expected to happen instead.

  3. #3
    cherians is offline Member
    Join Date
    Oct 2013
    Posts
    5
    Rep Power
    0

    Default Re: Invoice java program

    My apologize for not being clear about it. But whenever I try to compile InvoiceApp I'm getting a error that says "constructor Invoice in class cannot be applied"

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default Re: Invoice java program

    I'll repeat myself with emphasis:

    Do you get errors when you compile or run your code? Then post the EXACT message here.

  5. #5
    cherians is offline Member
    Join Date
    Oct 2013
    Posts
    5
    Rep Power
    0

    Default Re: Invoice java program

    When i compile.....the error message is InvoiceApp.java:7: error: constructor Invoice in class Invoice cannot be applied to given types;
    Invoice totalInvoice = new Invoice ();
    ^
    required: String,String,int,double
    found: no arguments
    reason: actual and formal argument lists differ in length
    1 error
    Attached Thumbnails Attached Thumbnails Invoice java program-screen-shot-2013-10-09-8.08.00-pm.png  

  6. #6
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default Re: Invoice java program

    Invoice totalInvoice = new Invoice ();
    ^
    required: String,String,int,double

    Well there you go. The error message tells you all you need to know. How are you calling the constructor and what does the constructor expect?

  7. #7
    cherians is offline Member
    Join Date
    Oct 2013
    Posts
    5
    Rep Power
    0

    Default Re: Invoice java program

    this is what I called the constructor: public Invoice( String part, String description, int count,
    double price )

  8. #8
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default Re: Invoice java program

    Yep, those are the parameters for the constructor but how many parameters are you passing when you create a new Invoice object? The error messages tells you.

  9. #9
    cherians is offline Member
    Join Date
    Oct 2013
    Posts
    5
    Rep Power
    0

Similar Threads

  1. Replies: 4
    Last Post: 11-21-2012, 02:19 PM
  2. invoice reciept
    By acelajines in forum NetBeans
    Replies: 0
    Last Post: 01-16-2012, 12:00 PM
  3. Need Help for coding invoice total
    By maxb in forum New To Java
    Replies: 3
    Last Post: 11-22-2008, 05:22 PM
  4. Help with Invoice app
    By callofthektulu in forum Java Applets
    Replies: 1
    Last Post: 08-08-2008, 05:17 AM
  5. Replies: 0
    Last Post: 10-04-2007, 10:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •