Java HW Help - GM Forum - Buick, Cadillac, Chev, Olds, GMC & Pontiac chat


Lounge For casual talk about things unrelated to General Motors. In other words, off-topic stuff. And anything else that does not fit Section Description.

Reply
 
 
 
Thread Tools Search this Thread
Old 02-07-2007, 11:10 PM   #1
Senior Member
Posts like a Camaro
Thread Starter
 
Join Date: Apr 2005
Posts: 1,071
Thanks: 0
Thanked 0 Times in 0 Posts
Sully1742 is on a distinguished road
Default 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:
Quote:
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'*.
And what I've got thus far, but it'* producing like 27 errors I can't solve.
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;
	}
Huge karma for any help.

I'll be on aim at sully1742 all night if you've got any info.
Sully1742 is offline   Reply With Quote
Old 02-07-2007, 11:32 PM   #2
Darrel
Guest
 
Posts: n/a
Default

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 .
  Reply With Quote
Old 02-07-2007, 11:51 PM   #3
Senior Member
Posts like a Camaro
Thread Starter
 
Join Date: Apr 2005
Posts: 1,071
Thanks: 0
Thanked 0 Times in 0 Posts
Sully1742 is on a distinguished road
Default

Quote:
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 .
Thanks! Eliminating all numbers and replacing them with words worked awesome. But now I am getting a run message.


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;
	}
Run:
Code:
 ----jGRASP exec: java Dollars

java.lang.NoSuchMethodError: main
Exception in thread "main" 
 ----jGRASP wedge2: exit code for process is 1.
 ----jGRASP: operation complete.
Sully1742 is offline   Reply With Quote
Old 02-08-2007, 12:13 AM   #4
Darrel
Guest
 
Posts: n/a
Default

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.

Quote:
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;
}
  Reply With Quote
Old 02-08-2007, 12:43 AM   #5
Senior Member
Posts like a Camaro
Thread Starter
 
Join Date: Apr 2005
Posts: 1,071
Thanks: 0
Thanked 0 Times in 0 Posts
Sully1742 is on a distinguished road
Default

Thanks... I'm getting them to compile fine, but when I run the files in jGrasp, the run messages are giving me errors.

Code:
java.lang.NoSuchMethodError: main
Exception in thread "main" 
 ----jGRASP wedge2: exit code for process is 1.
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
Sully1742 is offline   Reply With Quote
Old 02-08-2007, 07:26 AM   #6
Darrel
Guest
 
Posts: n/a
Default

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!
  Reply With Quote
Old 02-08-2007, 12:18 PM   #7
Senior Member
Posts like a Camaro
Thread Starter
 
Join Date: Apr 2005
Posts: 1,071
Thanks: 0
Thanked 0 Times in 0 Posts
Sully1742 is on a distinguished road
Default

Quote:
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!
Thanks for your help. Turned out the professor assigned the wrong thing anyways, and hadn't taught us how to do this yet. Oh well, thanks again.
Sully1742 is offline   Reply With Quote
Old 02-08-2007, 01:39 PM   #8
Darrel
Guest
 
Posts: n/a
Default

gotta love when they do that!!!

actually, helping you figure that out helps me too. because i'm still learning its good for me to look for errors.
  Reply With Quote
 
 
Reply

Related Topics
Thread Thread Starter Forum Replies Last Post
My Java broke bastard Lounge 5 11-08-2007 10:34 AM
java script off? Drifty Lounge 1 08-04-2007 03:59 AM
Java... I need a hand Darrel Lounge 0 02-08-2007 11:50 PM
i have a java assignment...LOL (input NEEDED) zzzzzeke Lounge 11 11-11-2003 04:58 PM
BonnevilleClub IRC had to move... now with Java Chat! Damemorder Lounge 20 08-13-2003 04:01 AM


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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



All times are GMT -4. The time now is 05:10 AM.


We are a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for us to earn fees by linking to Amazon.com and affiliated sites.