Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2008
    Posts
    1
    Rep Power
    0

    Default Help with Invoice app

    Hi, im relatively unfamiliar with java and i need help developing and invoice class. Basically i already have the InvoiceAPP done which is the first code ill show. now i had to create another class named Invoice that provides data and processing for an invoice object. The constructor has to have subtotal and customer type as its only parameters and the instance variables are discount percent, invoice total, and discount amount. The methods have got to have the needed get and set methods and an extra method named invoice that returns a string for all the data. i'm pretty sure im not following the proper logic on it so any help i can get is greatly appreciated.

    import java.text.NumberFormat;
    import java.util.Scanner;

    public class InvoiceApp
    {
    public static void main(String[] args)
    {
    // display a welcome message
    System.out.println("Welcome to the Invoice Total Calculator");
    System.out.println(); // print a blank line

    Scanner sc = new Scanner(System.in);
    String choice = "y";
    while(choice.equalsIgnoreCase("y"))
    {
    // get user entries
    String customerType = Validator.getString(sc,
    "Enter customer type (r/c): ");
    double subtotal = Validator.getDouble(sc,
    "Enter subtotal: ", 0, 10000);

    // calculate the discount amount and total
    double discountPercent = getDiscountPercent(subtotal, customerType);
    double discountAmount = subtotal * discountPercent;
    double total = subtotal - discountAmount;

    // format the values
    NumberFormat currency = NumberFormat.getCurrencyInstance();
    NumberFormat percent = NumberFormat.getPercentInstance();
    String sSubtotal = currency.format(subtotal);
    String sCustomerType = "";
    if (customerType.equalsIgnoreCase("r"))
    sCustomerType = "Retail";
    else if (customerType.equalsIgnoreCase("c"))
    sCustomerType = "College";
    String sDiscountPercent = percent.format(discountPercent);
    String sDiscountAmount = currency.format(discountAmount);
    String sTotal = currency.format(total);

    // format and display the results
    String message = "Subtotal: " + sSubtotal + "\n"
    + "Customer type: " + sCustomerType + "\n"
    + "Discount percent: " + sDiscountPercent + "\n"
    + "Discount amount: " + sDiscountAmount + "\n"
    + "Total: " + sTotal + "\n";
    System.out.println();
    System.out.println(message);

    System.out.print("Continue? (y/n): ");
    choice = sc.next();
    System.out.println();
    }
    ----------------------------------------------------------------------------
    the Invoice class

    import java.text.NumberFormat;

    public class Invoice
    {
    //instance variables
    private double discountPercent;
    private int discountAmount;
    private double invoiceTotal;
    // the constructor
    public Invoice(SubTotal, CustomerType)
    {
    this.SubTotal;
    this.CustomerType;
    }

    public double setdiscountPercent(double discountPercent)
    {
    this.discountPercent = discountPercent;
    }

    public double getdiscountPercent()
    {
    return discountPercent;
    }

    public double setdiscountAmount(int discountAmount)
    {
    this.discountAmount = discountAmount;
    }

    public int getdiscountAmount()
    {
    return discountAmount;
    }

    public double setinvoiceTotal(double invoiceTotal)
    {
    this.invoiceTotal = invoiceTotal;
    }

    public double getinvoiceTotal()
    {
    this.calculateTotal();
    return invoiceTotal;
    }

    private void calculateTotal()
    {
    double invoiceTotal = discountPercent * discountAmount;
    }

    public String getInvoice()
    {
    NumberFormat currency = NumberFormat.getCurrencyInstance();
    return currency.format(this.getinvoiceTotal());
    }
    }

  2. #2
    tux
    tux is offline Member
    Join Date
    Aug 2008
    Posts
    1
    Rep Power
    0

    Question Ever Find Your Answer

    Hi There, did you ever find your answer. If so, could you please help me?

    Thank you!

Posting Permissions

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