Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Closed Thread
 
Thread Tools Display Modes
Old Nov 20th, 2005, 9:24 PM   #1
mcl1008
Newbie
 
Join Date: Nov 2005
Posts: 1
Rep Power: 0 mcl1008 is on a distinguished road
programming problem

I am a student in a java programming class. We have to write a program as described below. The teacher is not giving us any help. I don't have a whole lot of programming experience and am not sure what to do. Can anyone explain what the code should look like?

Thanks in advance for any help.

-----------------------------------------------------------------------

Write a program to create an Instant Lottery.

It cost one dollar to play. A player enters 6 numbers between 1 and 40. After the last number is entered, the computer generates a 6 number winning ticket and compares the player’s numbers to the winning numbers. Payout is according to the following table:

Number matched Printed Result
0 Sorry, Better luck next time.
1 Congratulations, you won $1.
2 Congratulations, you won $5.
3 Congratulations, you won $100.
4 Congratulations, you won $1000.
5 Congratulations, you won $10000.
6 Jackpot!!! You won $1 million.

Run the game 10 or more times. For each play, print out the player’s numbers, the computer’s numbers, and the results from the table above.

At the end, report the total number of games played, the amount wagered, the amount won, and the net gain (won – wagered).
mcl1008 is offline  
Old Nov 20th, 2005, 11:04 PM   #2
JDStud6
Programmer
 
Join Date: Jan 2005
Location: Charleston, SC www.wareonearth.com
Posts: 57
Rep Power: 4 JDStud6 is on a distinguished road
Send a message via AIM to JDStud6
Quote:
Originally Posted by mcl1008
Can anyone explain what the code should look like?
Should start with the word "Class" and end with a "}"

We arent going to do your homework for you, sorry. Post the code that you have now. If you have none, start by making a simple program to input numbers between 1 and 40 from a user and printing them out. You probably want to use arrays to store the input numbers, and the generated numbers.

JD
JDStud6 is offline  
Old Nov 20th, 2005, 11:18 PM   #3
Lich
Professional Programmer
 
Lich's Avatar
 
Join Date: May 2005
Location: Detroit
Posts: 254
Rep Power: 4 Lich is on a distinguished road
Send a message via AIM to Lich Send a message via MSN to Lich
Read your book, mate. A lot of times the instructors will take examples right from the textbook and tweak them, but it's essentially the same program as what has already been written.
__________________
--John Cruz
Web Developer
www.cruzweb.net
Lich is offline  
Old Nov 21st, 2005, 3:31 PM   #4
2roll4life7
Programmer
 
2roll4life7's Avatar
 
Join Date: Aug 2005
Location: 0x0010 * 0x0091 + 0x0004
Posts: 65
Rep Power: 4 2roll4life7 is on a distinguished road
Quote:
Originally Posted by JDStud6
Should start with the word "Class" and end with a "}"
Actually, class should be lower case for this particular example. The file could also start with package, or import, or public, etc.
__________________
#if 0 /* in case someone actually tries to compile this */
- libpng version 1.2.8 (example.c)

<Jim_McNeat> Is there like a way to put a compiler in "Just trust me on that one" mode?
2roll4life7 is offline  
Old Nov 21st, 2005, 10:21 PM   #5
JDStud6
Programmer
 
Join Date: Jan 2005
Location: Charleston, SC www.wareonearth.com
Posts: 57
Rep Power: 4 JDStud6 is on a distinguished road
Send a message via AIM to JDStud6
wow its a joke, hence no code tags
JDStud6 is offline  
Old Nov 21st, 2005, 11:58 PM   #6
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5 bl00dninja is on a distinguished road
fuck syntax. c++, c, delphi, java, python, or d. get a pen and paper and think about the problem. draw pictures, make flowcharts. work out situations in your head. this is a pretty simple example but the hardest thing to do in programming is using abstract thought to analyze the problem. it gets easier with time. take lots of math. it takes a lot of abstraction to move from an apple falling from a tree to calculating instantaneous velocity and later on, the theory of gravity. the more you do stuff like this, you'll start to see the world in a different way, like in "interview with the vampire" when brad pitt first saw the world with his "vampire eyes", it's amazing what the world turns into when you look at it with your "CS/math eyes".

edit...how much money do you start with? it costs $1 to play, but a computer will let you play with negative money. don't let this happen, unless of course you want to extend credit to a player and then give them a virus or something if they don't pay up. :p
__________________
i put on my robe and wizard hat...

Have you ever heard of Plato, Aristotle, Socrates?...Morons.
bl00dninja is offline  
Old Nov 6th, 2006, 1:59 PM   #7
jamesdman
Newbie
 
Join Date: Apr 2005
Location: NC,USA
Posts: 17
Rep Power: 0 jamesdman is on a distinguished road
public class Lottery
{
  public static void main(String[] args)
	{
		int[] a= {0,0,0,0,0,0};
		
		while(a[5]==0)
		{
			int n=(int)Math.ceil(Math.random()*49);
			
			if(a[0]==0) a[0]=n;
			else
			if(a[1]==0 && n!=a[0]) a[1]=n;
			else
			if(a[2]==0 && n!=a[0] && n!=a[1]) a[2]=n;
      else
			if(a[3]==0 && n!=a[0] && n!=a[1] && n!=a[2]) a[3]=n;
		  else
			if(a[4]==0 && n!=a[0] && n!=a[1] && n!=a[2] && n!=a[3]) a[4]=n;
		  else
			if(a[5]==0 && n!=a[0] && n!=a[1] && n!=a[2] && n!=a[3] && n!=a[5]) 
				a[5]=n;
		}
		System.out.print("LUCKY NUMBERS: ");
		
		for(int i=0; i<6; i++)
		{
			System.out.print(a[i]+" ");
		}
	}
}
A bit late i presume.
jamesdman is offline  
Closed Thread

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:26 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC