Java HW Help
#1
Senior Member
Posts like a Camaro
Thread Starter
Join Date: Apr 2005
Posts: 1,071
Likes: 0
Received 0 Likes
on
0 Posts
Java HW Help
Hey guys I'm having some problems with my Java program for my CS101 class. It should be easy to figure out for anyone who knows Java but I'm stumped. The assignment:
And what I've got thus far, but it'* producing like 27 errors I can't solve.
Huge karma for any help.
I'll be on aim at sully1742 all night if you've got any info.
rite a program that reads a dollar amount and calculates and displays the conversion of the dollar amount into dollar-bill form -- 20'*, 10'*, 5'*, and 1'*.
Code:
public class Dollars { public Dollars() { purchase = 0; payment= 0; } public void recordPurchase(double amount) { purchase = purchase + amount; } public void enterPayment(int 20s Bills, int 10s Bills, int 5s Bills, int 1s Bills) { payment = 20s Bills * 20_BILLS_VALUE + 10s Bills * 10_BILLS_VALUE + 5s Bills * 5_BILLS_VALUE + 1s Bills * 1_BILLS_VALUE; } public double giveChange() { double change = payment - purchase; purchase=0; payment=0; return change; } public static final double 20_BILLS_VALUE= 20; public static final double 10_BILLS_VALUE= 10; public static final double 5_BILLS_VALUE= 5; public static final double 1_BILLS_VALUE= 1; private double purchase; private double payment; }
I'll be on aim at sully1742 all night if you've got any info.
#2
Guest
Posts: n/a
I don't use AIM so I'll just post it up here for ya.. btw, I'm in CIT 230 (object oriented program with JAVA) @ OU...
it looks like most of your problem is with your variables. I was told that you can't use numbers to start your variables. such as...
int 20s bills //this won't work
int bills_20 //this should work
int twenty //this should work too
what are you using for your development environment? if you aren't using it already might i recommend NetBeans 5.5. Its what my prof swears by and i really like it. I just pasted your code into a blank file and it gave me all the errors underlined in red just like MS word does .
it looks like most of your problem is with your variables. I was told that you can't use numbers to start your variables. such as...
int 20s bills //this won't work
int bills_20 //this should work
int twenty //this should work too
what are you using for your development environment? if you aren't using it already might i recommend NetBeans 5.5. Its what my prof swears by and i really like it. I just pasted your code into a blank file and it gave me all the errors underlined in red just like MS word does .
#3
Senior Member
Posts like a Camaro
Thread Starter
Join Date: Apr 2005
Posts: 1,071
Likes: 0
Received 0 Likes
on
0 Posts
Originally Posted by Darrel
I don't use AIM so I'll just post it up here for ya.. btw, I'm in CIT 230 (object oriented program with JAVA) @ OU...
it looks like most of your problem is with your variables. I was told that you can't use numbers to start your variables. such as...
int 20s bills //this won't work
int bills_20 //this should work
int twenty //this should work too
what are you using for your development environment? if you aren't using it already might i recommend NetBeans 5.5. Its what my prof swears by and i really like it. I just pasted your code into a blank file and it gave me all the errors underlined in red just like MS word does .
it looks like most of your problem is with your variables. I was told that you can't use numbers to start your variables. such as...
int 20s bills //this won't work
int bills_20 //this should work
int twenty //this should work too
what are you using for your development environment? if you aren't using it already might i recommend NetBeans 5.5. Its what my prof swears by and i really like it. I just pasted your code into a blank file and it gave me all the errors underlined in red just like MS word does .
Code:
public class Dollars { public Dollars() { purchase = 0; payment= 0; } public void recordPurchase(double amount) { purchase = purchase + amount; } public void enterPayment(int twenties, int tens, int fives, int ones) { payment = twenties * TWENTIES_BILLS_VALUE + tens * TENS_BILLS_VALUE + fives * FIVES_BILLS_VALUE + ones * ONES_BILLS_VALUE; } public double giveChange() { double change = payment - purchase; purchase=0; payment=0; return change; } public static final double TWENTIES_BILLS_VALUE = 20; public static final double TENS_BILLS_VALUE = 10; public static final double FIVES_BILLS_VALUE = 5; public static final double ONES_BILLS_VALUE = 1; private double purchase; private double payment; }
Code:
----jGRASP exec: java Dollars java.lang.NoSuchMethodError: main Exception in thread "main" ----jGRASP wedge2: exit code for process is 1. ----jGRASP: operation complete.
#4
Guest
Posts: n/a
ok, i'm venturing into some new territory here for me. When i copied your code into netbeans it only gave me one error. it was with the public dollars line. it wanted a return type in there. SOO.... I not sure what it does to it but i changed it to public void dollars and the error is gone. you might know more about that then me though. here is what i got, and it compiles just fine.
public class Dollars
{
public void Dollars()
{
purchase = 0;
payment= 0;
}
public void recordPurchase(double amount)
{
purchase = purchase + amount;
}
public void enterPayment(int twenties, int tens, int fives, int ones)
{
payment = twenties * TWENTIES_BILLS_VALUE + tens * TENS_BILLS_VALUE + fives * FIVES_BILLS_VALUE + ones * ONES_BILLS_VALUE;
}
public double giveChange()
{
double change = payment - purchase;
purchase=0;
payment=0;
return change;
}
public static final double TWENTIES_BILLS_VALUE = 20;
public static final double TENS_BILLS_VALUE = 10;
public static final double FIVES_BILLS_VALUE = 5;
public static final double ONES_BILLS_VALUE = 1;
private double purchase;
private double payment;
}
{
public void Dollars()
{
purchase = 0;
payment= 0;
}
public void recordPurchase(double amount)
{
purchase = purchase + amount;
}
public void enterPayment(int twenties, int tens, int fives, int ones)
{
payment = twenties * TWENTIES_BILLS_VALUE + tens * TENS_BILLS_VALUE + fives * FIVES_BILLS_VALUE + ones * ONES_BILLS_VALUE;
}
public double giveChange()
{
double change = payment - purchase;
purchase=0;
payment=0;
return change;
}
public static final double TWENTIES_BILLS_VALUE = 20;
public static final double TENS_BILLS_VALUE = 10;
public static final double FIVES_BILLS_VALUE = 5;
public static final double ONES_BILLS_VALUE = 1;
private double purchase;
private double payment;
}
#5
Senior Member
Posts like a Camaro
Thread Starter
Join Date: Apr 2005
Posts: 1,071
Likes: 0
Received 0 Likes
on
0 Posts
Thanks... I'm getting them to compile fine, but when I run the files in jGrasp, the run messages are giving me errors.
I thought the output should look like this:
The number of 20'* bills = x
The number of 10'* bills = x
The number of 5'* bills = x
The number of 1'* bills = x
Code:
java.lang.NoSuchMethodError: main Exception in thread "main" ----jGRASP wedge2: exit code for process is 1.
The number of 20'* bills = x
The number of 10'* bills = x
The number of 5'* bills = x
The number of 1'* bills = x
#6
Guest
Posts: n/a
Well, from what i can tell i think its telling you that you don't have a main method. But unfortinetly i cna't help much with that. We just started talking about writing our own classes and methos and such. up untill now we've been very basic with everything. If i think of somehting i'll let ya know. Good Luck!
#7
Senior Member
Posts like a Camaro
Thread Starter
Join Date: Apr 2005
Posts: 1,071
Likes: 0
Received 0 Likes
on
0 Posts
Originally Posted by Darrel
Well, from what i can tell i think its telling you that you don't have a main method. But unfortinetly i cna't help much with that. We just started talking about writing our own classes and methos and such. up untill now we've been very basic with everything. If i think of somehting i'll let ya know. Good Luck!
Thread
Thread Starter
Forum
Replies
Last Post