|
-
January 24th, 2012, 07:48 PM
#1
Stupid beginner Mistake, Can you help?
Hello everyone. So I am trying to learn how to program in Java. I am completely self taught, so I predict I will be consulting this site a lot more from now on.
The program I have to make is:
Code:
(Invoice Class) Create a class called Invoice that a hardware store might use to represent
an invoice for an item sold at the store. An Invoice should include four pieces of information as
instance variables—a part number (type String), a part description (type String), a quantity of the
item being purchased (type int) and a price per item (double). Your class should have a constructor
that initializes the four instance variables. Provide a set and a get method for each instance variable.
In addition, provide a method named getInvoiceAmount that calculates the invoice amount (i.e.,
multiplies the quantity by the price per item), then returns the amount as a double value. If the
Making a Difference 101
quantity is not positive, it should be set to 0. If the price per item is not positive, it should be set to
0.0. Write a test application named InvoiceTest that demonstrates class Invoice’s capabilities.
So this is what I wrote:
Code:
public class Invoice{
private String number;
public void setNumber(String num)
{
number = num;
}
public String getNumber()
{
return number;
}
private String description;
public void setDescription(String desc)
{
description = desc;
}
public String getDescription()
{
return description;
}
private int Amount;
public void setAmount(int amo)
{
Amount = amo;
}
public int getAmount()
{
return Amount;
}
private double Price;
public void setPrice(double pri)
{
Price = pri;
}
public double getPrice()
{
return Price;
}
private double InvoiceAmount;
public void setInvoiceAmount(double IA)
{
InvoiceAmount = (Price*Amount);
}
public double getInvoiceAmount()
{
return InvoiceAmount;
}
}
And the test is
Code:
import java.util.Scanner;
public class InvoiceTest{
public static void main(String[]args)
{
Scanner input = new Scanner(System.in);
Invoice Drill = new Invoice();
Invoice Hose = new Invoice();
Invoice Wood = new Invoice();
Invoice Bulb = new Invoice();
Drill.setPrice = 94.00;
Hose.setPrice = 4.50;
Wood.setPrice = 8.32;
Bulb.setPrice = -3.9999;
Drill.setNumber = QWERTY32;
Hose.setNumber = QWOPLOL9;
Wood.setNumber = JIZZPNTZ;
Bulb.setNumber = YUNOCOST;
Drill.setDescription = Jizz;
Hose.setDescription = in;
Wood.setDescription = my;
Bulb.setDescription = pants;
if (Drill.Price < 0)
Drill.setPrice = 0;
if (Hose.Price < 0)
Hose.setPrice = 0;
if (Wood.Price < 0)
Wood.setPrice = 0;
if (Bulb.Price < 0)
Wood.setPrice = 0;
System.out.printf("\n\nPrice for Drills is: $%.2f.\n\nPrice for Hoses is: $%.2f.\n\nPrice for Wood is: $%.2f.\n\nPrice for Bulbs is: $%.2f.",
Drill.getPrice, Hose.getPrice, Wood.getPrice, Bulb.getPrice);
System.out.println();
System.out.println();
System.out.printf("Drill: %s", Drill.getDescription);
System.out.println();
System.out.printf("Hose: %s", Hose.getDescription);
System.out.println();
System.out.printf("Wood: %s", Wood.getDescription);
System.out.println();
System.out.printf("Bulb: %s", Bulb.getDescription);
System.out.println();
System.out.print("How many Drills would you like? ");
Drill.setAmount = input.nextInt();
System.out.println();
System.out.print("How many Hoses would you like? ");
Hose.setAmount = input.nextInt();
System.out.println();
System.out.print("How many Tiles of Wood would you like? ");
Wood.setAmount = input.nextInt();
System.out.println();
System.out.print("How many bulbs would you like? ");
Bulb.setAmount = input.nextInt();
System.out.println();
System.out.println("Number Object Amount Total");
System.out.print("%s Drill %.2f $%.2f", Drill.getNumber,
Drill.getAmount, Drill.getInvoiceAmount);
System.out.println();
System.out.print("%s Hose %.2f $%.2f", Hose.getNumber,
Hose.getAmount, Hose.getInvoiceAmount);
System.out.println();
System.out.print("%s Wood %.2f $%.2f", Wood.getNumber,
Wood.getAmount, Wood.getInvoiceAmount);
System.out.println();
System.out.print("%s Bulb %.2f $%.2f", Bulb.getNumber,
Bulb.getAmount, Bulb.getInvoiceAmount);
System.out.println();
System.out.print("Grand Total: $%.2f", Sum);
Sum = Drill.InvoiceAmount + Hose.InvoiceAmount + Wood.InvoiceAmount + Bulb.InvoiceAmount;
}
}
I would appreciate any help possible. I am getting some errors while compiling. Mostly some problem with symbols and my objects:
Code:
C:\Programs>javac Invoice.java InvoiceTest.java
InvoiceTest.java:21: error: cannot find symbol
Drill.setPrice = 94.00;
^
symbol: variable setPrice
location: variable Drill of type Invoice
InvoiceTest.java:22: error: cannot find symbol
Hose.setPrice = 4.50;
^
symbol: variable setPrice
location: variable Hose of type Invoice
InvoiceTest.java:23: error: cannot find symbol
Wood.setPrice = 8.32;
^
symbol: variable setPrice
location: variable Wood of type Invoice
InvoiceTest.java:24: error: cannot find symbol
Bulb.setPrice = -3.9999;
^
symbol: variable setPrice
location: variable Bulb of type Invoice
InvoiceTest.java:26: error: cannot find symbol
Drill.setNumber = QWERTY32;
^
symbol: variable setNumber
location: variable Drill of type Invoice
InvoiceTest.java:26: error: cannot find symbol
Drill.setNumber = QWERTY32;
^
symbol: variable QWERTY32
location: class InvoiceTest
InvoiceTest.java:27: error: cannot find symbol
Hose.setNumber = QWOPLOL9;
^
symbol: variable setNumber
location: variable Hose of type Invoice
InvoiceTest.java:27: error: cannot find symbol
Hose.setNumber = QWOPLOL9;
^
symbol: variable QWOPLOL9
location: class InvoiceTest
InvoiceTest.java:28: error: cannot find symbol
Wood.setNumber = JIZZPNTZ;
^
symbol: variable setNumber
location: variable Wood of type Invoice
InvoiceTest.java:28: error: cannot find symbol
Wood.setNumber = JIZZPNTZ;
^
symbol: variable JIZZPNTZ
location: class InvoiceTest
InvoiceTest.java:29: error: cannot find symbol
Bulb.setNumber = YUNOCOST;
^
symbol: variable setNumber
location: variable Bulb of type Invoice
InvoiceTest.java:29: error: cannot find symbol
Bulb.setNumber = YUNOCOST;
^
symbol: variable YUNOCOST
location: class InvoiceTest
InvoiceTest.java:31: error: cannot find symbol
Drill.setDescription = Jizz;
^
symbol: variable setDescription
location: variable Drill of type Invoice
InvoiceTest.java:31: error: cannot find symbol
Drill.setDescription = Jizz;
^
symbol: variable Jizz
location: class InvoiceTest
InvoiceTest.java:32: error: cannot find symbol
Hose.setDescription = in;
^
symbol: variable setDescription
location: variable Hose of type Invoice
InvoiceTest.java:32: error: cannot find symbol
Hose.setDescription = in;
^
symbol: variable in
location: class InvoiceTest
InvoiceTest.java:33: error: cannot find symbol
Wood.setDescription = my;
^
symbol: variable setDescription
location: variable Wood of type Invoice
InvoiceTest.java:33: error: cannot find symbol
Wood.setDescription = my;
^
symbol: variable my
location: class InvoiceTest
InvoiceTest.java:34: error: cannot find symbol
Bulb.setDescription = pants;
^
symbol: variable setDescription
location: variable Bulb of type Invoice
InvoiceTest.java:34: error: cannot find symbol
Bulb.setDescription = pants;
^
symbol: variable pants
location: class InvoiceTest
InvoiceTest.java:36: error: Price has private access in Invoice
if (Drill.Price < 0)
^
InvoiceTest.java:37: error: cannot find symbol
Drill.setPrice = 0;
^
symbol: variable setPrice
location: variable Drill of type Invoice
InvoiceTest.java:39: error: Price has private access in Invoice
if (Hose.Price < 0)
^
InvoiceTest.java:40: error: cannot find symbol
Hose.setPrice = 0;
^
symbol: variable setPrice
location: variable Hose of type Invoice
InvoiceTest.java:42: error: Price has private access in Invoice
if (Wood.Price < 0)
^
InvoiceTest.java:43: error: cannot find symbol
Wood.setPrice = 0;
^
symbol: variable setPrice
location: variable Wood of type Invoice
InvoiceTest.java:45: error: Price has private access in Invoice
if (Bulb.Price < 0)
^
InvoiceTest.java:46: error: cannot find symbol
Wood.setPrice = 0;
^
symbol: variable setPrice
location: variable Wood of type Invoice
InvoiceTest.java:50: error: cannot find symbol
Drill.getPrice, Hose.getPrice, Wood.getPrice, Bulb.getPrice);
^
symbol: variable getPrice
location: variable Drill of type Invoice
InvoiceTest.java:50: error: cannot find symbol
Drill.getPrice, Hose.getPrice, Wood.getPrice, Bulb.getPrice);
^
symbol: variable getPrice
location: variable Hose of type Invoice
InvoiceTest.java:50: error: cannot find symbol
Drill.getPrice, Hose.getPrice, Wood.getPrice, Bulb.getPrice);
^
symbol: variable getPrice
location: variable Wood of type Invoice
InvoiceTest.java:50: error: cannot find symbol
Drill.getPrice, Hose.getPrice, Wood.getPrice, Bulb.getPrice);
^
symbol: variable getPrice
location: variable Bulb of type Invoice
InvoiceTest.java:54: error: cannot find symbol
System.out.printf("Drill: %s", Drill.getDescription);
^
symbol: variable getDescription
location: variable Drill of type Invoice
InvoiceTest.java:56: error: cannot find symbol
System.out.printf("Hose: %s", Hose.getDescription);
^
symbol: variable getDescription
location: variable Hose of type Invoice
InvoiceTest.java:58: error: cannot find symbol
System.out.printf("Wood: %s", Wood.getDescription);
^
symbol: variable getDescription
location: variable Wood of type Invoice
InvoiceTest.java:60: error: cannot find symbol
System.out.printf("Bulb: %s", Bulb.getDescription);
^
symbol: variable getDescription
location: variable Bulb of type Invoice
InvoiceTest.java:65: error: cannot find symbol
Drill.setAmount = input.nextInt();
^
symbol: variable setAmount
location: variable Drill of type Invoice
InvoiceTest.java:69: error: cannot find symbol
Hose.setAmount = input.nextInt();
^
symbol: variable setAmount
location: variable Hose of type Invoice
InvoiceTest.java:73: error: cannot find symbol
Wood.setAmount = input.nextInt();
^
symbol: variable setAmount
location: variable Wood of type Invoice
InvoiceTest.java:77: error: cannot find symbol
Bulb.setAmount = input.nextInt();
^
symbol: variable setAmount
location: variable Bulb of type Invoice
InvoiceTest.java:81: error: cannot find symbol
System.out.print("%s Drill %.2f $%.2f", Drill.getNumber,
^
symbol: variable getNumber
location: variable Drill of type Invoice
InvoiceTest.java:82: error: cannot find symbol
Drill.getAmount, Drill.getInvoiceAmount);
^
symbol: variable getAmount
location: variable Drill of type Invoice
InvoiceTest.java:82: error: cannot find symbol
Drill.getAmount, Drill.getInvoiceAmount);
^
symbol: variable getInvoiceAmount
location: variable Drill of type Invoice
InvoiceTest.java:85: error: cannot find symbol
System.out.print("%s Hose %.2f $%.2f", Hose.getNumber,
^
symbol: variable getNumber
location: variable Hose of type Invoice
InvoiceTest.java:86: error: cannot find symbol
Hose.getAmount, Hose.getInvoiceAmount);
^
symbol: variable getAmount
location: variable Hose of type Invoice
InvoiceTest.java:86: error: cannot find symbol
Hose.getAmount, Hose.getInvoiceAmount);
^
symbol: variable getInvoiceAmount
location: variable Hose of type Invoice
InvoiceTest.java:89: error: cannot find symbol
System.out.print("%s Wood %.2f $%.2f", Wood.getNumber,
^
symbol: variable getNumber
location: variable Wood of type Invoice
InvoiceTest.java:90: error: cannot find symbol
Wood.getAmount, Wood.getInvoiceAmount);
^
symbol: variable getAmount
location: variable Wood of type Invoice
InvoiceTest.java:90: error: cannot find symbol
Wood.getAmount, Wood.getInvoiceAmount);
^
symbol: variable getInvoiceAmount
location: variable Wood of type Invoice
InvoiceTest.java:93: error: cannot find symbol
System.out.print("%s Bulb %.2f $%.2f", Bulb.getNumber,
^
symbol: variable getNumber
location: variable Bulb of type Invoice
InvoiceTest.java:94: error: cannot find symbol
Bulb.getAmount, Bulb.getInvoiceAmount);
^
symbol: variable getAmount
location: variable Bulb of type Invoice
InvoiceTest.java:94: error: cannot find symbol
Bulb.getAmount, Bulb.getInvoiceAmount);
^
symbol: variable getInvoiceAmount
location: variable Bulb of type Invoice
InvoiceTest.java:97: error: cannot find symbol
System.out.print("Grand Total: $%.2f", Sum);
^
symbol: variable Sum
location: class InvoiceTest
InvoiceTest.java:100: error: cannot find symbol
Sum = Drill.InvoiceAmount + Hose.InvoiceAmount + Wood.InvoiceAmount + Bu
lb.InvoiceAmount;
^
symbol: variable Sum
location: class InvoiceTest
InvoiceTest.java:100: error: InvoiceAmount has private access in Invoice
Sum = Drill.InvoiceAmount + Hose.InvoiceAmount + Wood.InvoiceAmount + Bu
lb.InvoiceAmount;
^
InvoiceTest.java:100: error: InvoiceAmount has private access in Invoice
Sum = Drill.InvoiceAmount + Hose.InvoiceAmount + Wood.InvoiceAmount + Bu
lb.InvoiceAmount;
^
InvoiceTest.java:100: error: InvoiceAmount has private access in Invoice
Sum = Drill.InvoiceAmount + Hose.InvoiceAmount + Wood.InvoiceAmount + Bu
lb.InvoiceAmount;
^
InvoiceTest.java:100: error: InvoiceAmount has private access in Invoice
Sum = Drill.InvoiceAmount + Hose.InvoiceAmount + Wood.InvoiceAmount + Bu
lb.InvoiceAmount;
^
58 errors
Sorry, I know this is probably trivial for this kind of forum. But I really have no one else to turn to for help. ANY help would be appreciated. Thank you very much! Have a nice day.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|