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.

Java HW Help

Thread Tools
 
Old 02-07-2007, 10:10 PM
  #1  
Senior Member
Posts like a Camaro
Thread Starter
 
Sully1742's Avatar
 
Join Date: Apr 2005
Posts: 1,071
Likes: 0
Received 0 Likes on 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:
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.
Old 02-07-2007, 10:51 PM
  #3  
Senior Member
Posts like a Camaro
Thread Starter
 
Sully1742's Avatar
 
Join Date: Apr 2005
Posts: 1,071
Likes: 0
Received 0 Likes on 0 Posts
Sully1742 is on a distinguished road
Default

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.
Old 02-07-2007, 11:43 PM
  #5  
Senior Member
Posts like a Camaro
Thread Starter
 
Sully1742's Avatar
 
Join Date: Apr 2005
Posts: 1,071
Likes: 0
Received 0 Likes on 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
Old 02-08-2007, 11:18 AM
  #7  
Senior Member
Posts like a Camaro
Thread Starter
 
Sully1742's Avatar
 
Join Date: Apr 2005
Posts: 1,071
Likes: 0
Received 0 Likes on 0 Posts
Sully1742 is on a distinguished road
Default

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.
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
bastard
Lounge
5
11-08-2007 09:34 AM
Drifty
Lounge
1
08-04-2007 02:59 AM
Darrel
Lounge
0
02-08-2007 10:50 PM
zzzzzeke
Lounge
11
11-11-2003 03:58 PM
Damemorder
Lounge
20
08-13-2003 03:01 AM



Quick Reply: Java HW Help



All times are GMT -4. The time now is 01:49 PM.