473,396 Members | 2,052 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

need help with my code

I am having hard time completing my java lottery program. i am trying to write two public function play()and score. Play supposed to prompt the user to input $1 in the machine. Score should calculate the number of picks that match the winning number. Please help me. here is my code that is what i got so far.

Expand|Select|Wrap|Line Numbers
  1. import  java.util.*;
  2.  
  3.  
  4. public class Lottery {
  5.  
  6. //private int[] winner;
  7.  
  8. //private int[] picks;
  9.  
  10. int play;
  11.  
  12. int score;
  13.  
  14. //winner =int [5];
  15.  
  16.  
  17.  
  18. public static void main(String[] args) {
  19.  
  20. //Random generator and scanner
  21.  
  22. Scanner sc = new Scanner(System.in);
  23.  
  24. Random generator = new Random();
  25.  
  26. System.out.println("Enter a number between 1-35.");
  27.  
  28. int ch =sc.nextInt();
  29.  
  30. int winner = (int) (Math.random() *35) + 1;
  31.  
  32. if(ch == 10)
  33.  
  34. System.out.println("Congrast, you have won!");
  35.  
  36. else
  37.  
  38. System.out.println("Sorry, you did not have the winning number\n."
  39.  
  40. +"The winning number is " + winner + ",");
  41.  
  42. //class play{
  43.  
  44. //int paly = 0;
  45.  
  46. for(int i = 1;i < 35; i++){
  47.  
  48. Scanner diceRoller = new Scanner(System.in);
  49.  
  50. int roll = diceRoller.nextInt(5)+1;
  51.  
  52. System.out.println(roll);
  53.  
  54. }
  55.  
  56.  
  57. }
  58.  
  59. }
Feb 19 '12 #1

✓ answered by r035198x

play and score are methods but you haven't defined them as such:

Expand|Select|Wrap|Line Numbers
  1. import java.util.Scanner;
  2.  
  3. public class Lottery {
  4.     public void play() {
  5.         //your code goes here
  6.     Scanner sc = new Scanner(System.in);
  7.     }
  8.  
  9.     public void score() {
  10.          //your code goes here
  11.  
  12.     }
  13.  
  14.     public static void main(String[] args) {
  15.     new Lottery().play();
  16.  
  17.     }
  18. }

1 1540
r035198x
13,262 8TB
play and score are methods but you haven't defined them as such:

Expand|Select|Wrap|Line Numbers
  1. import java.util.Scanner;
  2.  
  3. public class Lottery {
  4.     public void play() {
  5.         //your code goes here
  6.     Scanner sc = new Scanner(System.in);
  7.     }
  8.  
  9.     public void score() {
  10.          //your code goes here
  11.  
  12.     }
  13.  
  14.     public static void main(String[] args) {
  15.     new Lottery().play();
  16.  
  17.     }
  18. }
Feb 20 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Cibulya Dmitriy | last post by:
Hi All, I want to catch the next MSSQL error in my SQL code with following continue calculations Server: Msg 17, Level 16, State 1, Line 1 SQL Server does not exist or access denied.
1
by: chuayongquan | last post by:
i am doing a dll debugging and kept getting this error: The thread 0x880 has exited with code 0 (0x0). then vs c++ gave me memory leak detected and start to memory dump. but i am getting another...
8
by: alanstew | last post by:
With the body tag calling out 'window onload', a function with a 'window.open' fails at the 'window.open' line. If I cut out the body tag, the function executes as normal. At first I thought it...
34
by: Mark Kamoski | last post by:
Hi-- Please help. I need a code sample for bubble sort. Thank you. --Mark
2
by: Mark Kamoski | last post by:
Hi Everyone-- Please help. I need a code sample for merge sort. Thank you. --Mark
2
by: Steve | last post by:
I have a combo box that I would like to expand or "drop down" programmatically. The Simple style won't work because I still need the control to contract or "roll up" after a selection is made, I...
10
by: HK | last post by:
With VB.NET 2005, and a Windows Form, running on a dual CPU box, I need to take a recordset (e.g. 100,000 records) and spawn a thread to handle an internet XML transaction routine for each of the...
8
by: JEO | last post by:
I have a Visual basic 3 App that I am converting to VBA in Microsoft Access 2003. The VB3 app successfully recolors a bitmap image with code using pixel locations when clicking on option buttons...
1
by: saravanatmm | last post by:
I need javascript code for validate the email address. Email address field cannot allowed the capital letters, special characters except '@' symbol. But can allowed the small letters, numeric...
0
by: P.K Sahu | last post by:
hello there, i'm new to web service but i have a difficulty to understand web services. See, I created the webservice through the default template of visual studio & " hello world" but that does...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.