Help with basic programing

I'm taking an AP course in high school Java and I have an assignment, in which I have no idea where to start. Unfortunatly my tutour is unavailable until after the due date. Can someone have a look at the 3 of them an offer any code please, I have no idea of what to do?

1)Write a complete Java program that will simulate a magic 8-ball?

The real magic 8-ball provides 20 different answers to yes/no

questions. Our 8-ball will include only eight different possible answers,

one of which will be chosen randomly for each question asked.

Some details:

Your program will do the following:

1. After outputting a brief welcome message, ask the user to enter

a question. Also, mention that the user can press 'q' or 'Q' to

quit.

2. If the question does not end in a question mark, echo the

original input, and then output "That is not a question".

3. If the question ends in a question mark, use Math.random() to

choose a random value between 1 and 8, and use this value to

select one of the below eight answers. Output both the original

question and the selected answer.

4. After the output message, prompt the user to input another

question or press 'q' or 'Q' to quit. After the user chooses to quit,

output a brief farewell message.

Signs point to yes.

It is decidedly so.

Outlook good.

Reply hazy, try again.

Cannot predict now.

My sources say no.

Very doubtful.

Don't count on it.

2)Write a complete Java program that will simulate Lotto 6-49.

For those of you who don't know the rules of Lotto 6-49, here's a brief

overview:

Tickets cost $2 each. For each ticket, customers pick 6 numbers

between (and including) 1 and 49. On Saturdays, the lotto organizers

pick 6 numbers and 1 bonus number.

Write a program that will simulate how much money a million dollars

worth of lottery tickets (that is, 500,000 tickets) would have won on

the draw of Saturday, October 8.

IMPORTANT NOTE: In this version of the simulation, you will randomly

generate a number, and then essentially put the number back into the

pool of possible numbers. In the actual Lotto 6-49, once a number is

drawn it cannot be drawn again. So, remember this simulation is not

accurate! Expect unusually lucky results from this version of the

program. And don't go and spend all of your money on lottery

tickets!

Overview:

The user will enter the 6 winning numbers, plus the bonus number.

The program will simulate the purchase of 500,000 randomly-

generated tickets, and output the winnings earned from these tickets.

Your program will do the following:

1. After outputting a brief welcome message, ask the user to pick

the 6 winning numbers. Also prompt the user to enter a bonus

number.

2. Then, use Math.random() to generate a random number

between 1 and 49. This number will represent one of the

numbers on a lottery ticket.

3. Compare this random ticket number to the winning numbers.

Keep track of any matches. Generate and compare numbers six

times.

4. Calculate how much money the lottery ticket made, using the

above table from Saturday, Oct. 8.

5. Now, repeat the above 4 steps half-a-million times to represent

a million dollars of lottery tickets! Remember to keep a running

total of the income.

6. Output the final winnings.

Thanks in advance to anyone who can help me, like I said before, I'm in the dark and really can't afford to loose the marks.

[3788 byte] By [BigBa] at [2007-10-2 3:28:56]
# 1

<standard reply>

the correct way to get help in forums like this is to post:

1) the specific problem you have

2) the code you have tried

3) the 'output you expect'

4) the 'output you get'

5) any relevant error messages

posting the assignment makes it look like just another

"do my homework for me" plea - even though that may not be your intention.

Michael_Dunna at 2007-7-15 22:38:34 > top of Java-index,Java Essentials,Java Programming...
# 2
Don't post a school assignment sheet on the forum.You shall fall a prey to angry monsters and be eaten by them.Post a result of your own effort and the description of the problem encounteredtherein.
hiwaa at 2007-7-15 22:38:34 > top of Java-index,Java Essentials,Java Programming...
# 3

import javax.swing.*;

public class A2Question1{

public static void main (String [] args) {

//Declare variables and initializing.

int randomNumber=0;

String input;

String ballSays = null;

//Welcome Message and prompt for input (priming read).

input = JOptionPane.showInputDialog ("Welcome to the Magic 8 Ball."+

'\n'+"You may leave by entering 'q' or 'Q'."+

'\n'+"Please enter your question.");

System.out.println ("Welcome to the Magic 8-ball!"+'\n');

//While loop, checks for Q or q from user.

while (!input.equalsIgnoreCase("q")){

//if else that checks for a "Q" or "q".

if(input.endsWith("?")){

//Generating a random integer between 1 & 8.

randomNumber = (int) (Math.random () * 8) + 1;

//If else to find matching randomNumber

if (randomNumber == 1) {

ballSays = "Signs point to yes.";

}

else

if (randomNumber == 2) {

ballSays = "It is decidedly so.";

}

else

if (randomNumber == 3) {

ballSays = "Outlook good.";

}

else

if (randomNumber == 4) {

ballSays = "Reply hazy, try again.";

}

else

if (randomNumber == 5) {

ballSays = "Cannot predict now.";

}

else

if (randomNumber == 6) {

ballSays = "My sources say no.";

}

else

if (randomNumber == 7) {

ballSays = "Very doubtful.";

}

else

if (randomNumber == 8) {

ballSays = "Don't count on it.";

}

JOptionPane.showMessageDialog (null, "You asked: "+ input +

'\n'+"The answer: "+ballSays);

System.out.println ("You asked: "+input);

System.out.println ("The answer: "+ballSays);

}

else

{

JOptionPane.showMessageDialog (null, "That is not a question.");

System.out.println ("You asked: "+input+'\n'+

"That is not a question."+'\n');

}

//Asking user for input again.

input = JOptionPane.showInputDialog ("Please enter your question."+

'\n'+"You may leave by entering 'q' or 'Q'.");

}

JOptionPane.showMessageDialog (null, "Thank-you for consulting the magic 8-ball. Good-bye.");

System.out.println ("Thank-you for consulting the magic 8-ball. Good-bye."+'\n');

System.exit(0);

}

}

wessona at 2007-7-15 22:38:34 > top of Java-index,Java Essentials,Java Programming...
# 4

import javax.swing.*;

public class A2Question2{

public static void main (String [] args){

//Declaring variables and initializing final variables.

int num1,num2,num3,num4,num5,num6,bonusNum,randPic,match,totalWin=0;

final int PRIZE2B=5,PRIZE3=10,PRIZE4=48,PRIZE5=1372,PRIZE5B=49826,PRIZE6=7359178;

boolean bonusMatch;

String input;

//Getting input from the user.

JOptionPane.showMessageDialog (null,"Welcome to the 6/49 program."+'\n'+

"Enter unique positive integers from "+'\n'+

"1 to 49 in the following input windows");

input=JOptionPane.showInputDialog ("Enter winning number 1.");

num1=Integer.parseInt(input);

input=JOptionPane.showInputDialog ("Enter winning number 2.");

num2=Integer.parseInt(input);

input=JOptionPane.showInputDialog ("Enter winning number 3.");

num3=Integer.parseInt(input);

input=JOptionPane.showInputDialog ("Enter winning number 4.");

num4=Integer.parseInt(input);

input=JOptionPane.showInputDialog (null, "Enter winning number 5.");

num5=Integer.parseInt(input);

input=JOptionPane.showInputDialog (null, "Enter winning number 6.");

num6=Integer.parseInt(input);

input=JOptionPane.showInputDialog (null, "Enter bonus number.");

bonusNum=Integer.parseInt(input);

//For loop that runs 500,000 times.

for (int i=1; i<=500000; i++){

//Initializing variables inside loop to reset them

//for each of the 500,000 tickets.

bonusMatch=false;

match=0;

//For loop that runs 6 times, generates random integer

//between 1 & 49, uses boolean to check for bonus number match,

//checks for number matches accumulatively.

for (int j=1; j<=6; j++){

randPic=(int)(Math.random()*49)+1;

if (randPic==bonusNum){bonusMatch=true;

}

if (randPic==num1){match++;

}

else

if (randPic==num2){match++;

}

else

if (randPic==num3){match++;

}

else

if (randPic==num4){match++;

}

else

if (randPic==num5){match++;

}

else

if (randPic==num6){match++;

}

}

//Adding PRIZE to totalWin (accumulatively).

if (match==2 && bonusMatch==true)totalWin+=PRIZE2B;

if (match==3)totalWin+=PRIZE3;

if (match==4)totalWin+=PRIZE4;

if (match==5)totalWin+=PRIZE5;

if (match==5 && bonusMatch==true)totalWin+=PRIZE5B;

if (match==6)totalWin+=PRIZE6;

}

System.out.println ("Total 649 winnings"+'\n'+

"with a million dollar investment:"+'\n'+

"$ "+totalWin);

System.exit(0);

}

}

wessona at 2007-7-15 22:38:34 > top of Java-index,Java Essentials,Java Programming...
# 5
nice one wesson ;-)
ravis_31a at 2007-7-15 22:38:34 > top of Java-index,Java Essentials,Java Programming...
# 6
did that wesson guy actually do his homework for him? i wish my homework would be that easy... they told him exactly what to do.. and that's AP...? my AP next semester will be 3D... im scared
deanat78a at 2007-7-15 22:38:34 > top of Java-index,Java Essentials,Java Programming...
# 7
What is AP?
macrules2a at 2007-7-15 22:38:34 > top of Java-index,Java Essentials,Java Programming...
# 8
> What is AP?i am guessing that it's Advanced Programming.
aniseeda at 2007-7-15 22:38:34 > top of Java-index,Java Essentials,Java Programming...
# 9
> > What is AP?> > i am guessing that it's Advanced Programming.That question came from an advanced programming class.... FFS no wonder we can't find decent developers from colleges.
macrules2a at 2007-7-15 22:38:34 > top of Java-index,Java Essentials,Java Programming...
# 10

>> What is AP?

> i am guessing that it's Advanced Programming.

AP stands for "Advanced Placement" which indicates that the course is intended to give the student enough of a background in computer science to complete the AP exam at the end of the year which, given a high enough score, is worth college credit.

Not that we have to worry about the OP receiving such credit should this prove to be an accurate example of his work ethic.

KyleWCartmella at 2007-7-15 22:38:34 > top of Java-index,Java Essentials,Java Programming...
# 11

> >> What is AP?

> > i am guessing that it's Advanced Programming.

>

> AP stands for "Advanced Placement" which indicates

> that the course is intended to give the student

> enough of a background in computer science to

> complete the AP exam at the end of the year which,

> given a high enough score, is worth college credit.

>

> Not that we have to worry about the OP receiving such

> credit should this prove to be an accurate example of

> his work ethic.

It should be ok, Wesson is free that day to take it for him :)

macrules2a at 2007-7-15 22:38:34 > top of Java-index,Java Essentials,Java Programming...