Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-05-2008, 02:57 AM
Member
 
Join Date: Feb 2008
Posts: 1
callofthektulu is on a distinguished road
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());
}
}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-08-2008, 05:17 AM
tux tux is offline
Member
 
Join Date: Aug 2008
Posts: 1
tux is on a distinguished road
Ever Find Your Answer
Hi There, did you ever find your answer. If so, could you please help me?

Thank you!
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +3. The time now is 02:36 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org