Posted by Elaine on Tuesday, September 8, 2009 at 12:35am.
The instructions to the question is very clear and objectives are clearly defined. I assume that you have already taken a Java course before, so you would know how to create a class, the state variables and the methods. Also, I assume you are capable of reading the Java API in order to use the Random class.
Looking at the evaluation criteria, the Lottery class seems easier to create, and yet it carries 18 points out of 25. It would therefore be a good point to start.
If you post the source code, I would be glad to give you comments or help you debug if there is a problem. Here's a pseudocode to help you get going. Sorry for the indentation which is removed by the forum's formating.
public class Lottery
{
private int[] lotteryNumbers=new int[5];
public Lottery() // constructor
{
// call method drawNumbers() to create array
}
private void drawNumbers()
{
// use Random to create numbers within
range
// be sure not to generate duplicate numbers
}
public int[] getNumbers()
{
// return array of 5 numbers
}
public int match(int[] picks)
{
// match all 5 numbers to the ticket and return the number of matches
}
public String toString()
{
// return a string which is the concatenation of all the lottery numbers
}
}
I took Java 1 but really I did not understand. :( I dont even understand this. I have been sitting here and confused going through my books etc. So I have to have 2 classes but what goes where? Thanks so much for the help. I have 24hours and im so stuck...
im really stuck. I am taking this online course online. this is what i have so far.
public class Lottery
{
int lotteryNumbers = new int[5];
public lotteryNumbers();// constructor
If you took Java I and did not understand, how did you pass the course?
What this question requires is expected of Java I students towards the end.
What I suggest is you redo Java I and make sure you understand every part of it. Java is like math, if you miss one link, you will get stuck in no time.
Although the Object-Oriented concepts are not completely introduced, but the basic elements of programming are required (learned in Java 1). Your teacher has guided you in every detail, and all he is expecting of you is the coding part. The design is all done.
Have you looked at my pseudo-code, or skeleton? Can you make something out of it? If you fill in some meat (but make sure it compiles, or you will get a zero), you may salvage some points.
Try to put some meat in the Lottery class and I will be glad to look over it for you. I will be at school all day tomorrow till the end of the day, so that gives you some time to get the work done!
Good luck, and bon travail!
Thank you...i will post something up when i wake up. Java 1 i took in class-teacher was not the best and being from another country most in the class new more than me. So I had to just try my best. Now im taking Java2 but im doing it online. Im working with a textbook too. Wish i could retake classes but being from another country i pay out of state tution...so :( yes...I have to just give it my best shot...Thanks a lot...
If you have time to do practice problems in Java 1 (or 2) and need help, I'll be here. It is important that you understand the basics.
Ok, here is what i have done so far. But there are a million errors coming up...I tried my best please help and thanks so much again...
import java.util.Random;
import java.io.*;
public class Lottery
{
int[] LottoNumbers = new int[5];
String LottoString = new string;
public Lottery()
{
Random sequence = new Random();
for (i = 0; i <= 4; i++){
LottoNumbers[i] = sequence.nextInt(10) + 1;
}
}
public int Match(int TicketNumbers[])
{
int Matches = 0;
for(i = 0; i <= 4; i++){
for(j = 0; j <= 4; j++){
if(LottoNumbers[i] == TicketNumbers[j])
Matches++;
}
}
return Matches;
}
public String toString()
{
LottoString = "The lottery numbers were ";
for (i = 0; i <= 2; i++){
LottoString = LottoString + LottoNumbers[i] + ", ";
}
LottoString = LottoString + LottoNumbers[3] + " and " + LottoNumbers[4] + ".";
return LottoString;
}
}
class Lab1
{
public static void main(String args[])
{
String HaveTicket = new String;
HaveTicket = "Y";
Lottery NewLottery = new Lottery();
int[] TicketNumbers = new int[5];
int Number = new int;
int Matches = new int;
InputStreamReader istream = new InputStreamReader(System.in);
BufferedReader bufRead = new BufferedReader(istream);
while(HaveTicket == "Y"){
System.out.println ("Please enter your lottery ticket numbers: ")
for(i = 0; i <= 4; i++){
Number = Integer.parseInt(bufRead.readLine());
TicketNumbers[i] = Number;
}
System.out.println (" ");
System.out.println (Lottery.toString());
Matches = Lottery.Match(TicketNumbers);
if(Matches == 5)
System.out.println ("Congratulations!! You have 5 numbers matched and are the Grand Prize Winner!");
else
System.out.println ("You matched " + Matches + " numbers!");
System.out.println ("Do you have another ticket to check? (Y or N): ");
HaveTicket = bufRead.readLine();
}
}
}
did you get all the source code?
ill paste again...
class Lab1
{
public static void main(String args[])
{
String HaveTicket = new String;
HaveTicket = "Y";
Lottery NewLottery = new Lottery();
int[] TicketNumbers = new int[5];
int Number = new int;
int Matches = new int;
InputStreamReader istream = new InputStreamReader(System.in);
BufferedReader bufRead = new BufferedReader(istream);
while(HaveTicket == "Y"){
System.out.println ("Please enter your lottery ticket numbers: ")
for(i = 0; i <= 4; i++){
Number = Integer.parseInt(bufRead.readLine());
TicketNumbers[i] = Number;
}
System.out.println (" ");
System.out.println (Lottery.toString());
Matches = Lottery.Match(TicketNumbers);
if(Matches == 5)
System.out.println ("Congratulations!! You have 5 numbers matched and are the Grand Prize Winner!");
else
System.out.println ("You matched " + Matches + " numbers!");
System.out.println ("Do you have another ticket to check? (Y or N): ");
HaveTicket = bufRead.readLine();
}
}
}
import java.util.Random;
import java.io.*;
public class Lottery
{
int[] LottoNumbers = new int[5];
String LottoString = new string;
public Lottery()
{
Random sequence = new Random();
for (i = 0; i <= 4; i++){
LottoNumbers[i] = sequence.nextInt(10) + 1;
}
}
public int Match(int TicketNumbers[])
{
int Matches = 0;
for(i = 0; i <= 4; i++){
for(j = 0; j <= 4; j++){
if(LottoNumbers[i] == TicketNumbers[j])
Matches++;
}
}
return Matches;
}
public String toString()
{
LottoString = "The lottery numbers were ";
for (i = 0; i <= 2; i++){
LottoString = LottoString + LottoNumbers[i] + ", ";
}
LottoString = LottoString + LottoNumbers[3] + " and " + LottoNumbers[4] + ".";
return LottoString;
}
}
Sorry, pasting does not work here. If you have a file server site, or a photo site, you can post them there. A file server site would be preferable because if it is a .jpg file, I would have to type them up to compile.
Also, you cannot, theoretically, post links either. If you are ingeneous, you may get around it.
Related Questions
stu - An individual with utility function U(X) = X2 bought Lottery A and Lottery...
mathematics - the theoretical probability of winning the lottery is 1/1,000,000,...
maths - lisa won the lottery she used 1/2 of her lottery win to buy a house she ...
java programming - Create a program that will generate lottery numbers for the ...
English - The climax of "The Lottery" is when: A.The Hutchinson family...
Statistics - "Buy a Match 6 lottery ticket every day until you win the ...
programming.Java language - Write a program to plot a face. Provide a class ...
MATH Help! - Can some one help?? A class elects two officers, a president and a ...
programming - Design a class named Book that holds a stock number, author, title...
Programming - Here is the question that I need help to write the code for the ...
For Further Reading