HELP NEEDED! Electronic submission : You must submit a single .zip archive file
ID: 640728 • Letter: H
Question
HELP NEEDED!
Electronic submission:
You must submit a single .zip archive file of your project folder. Use a utility that produces .zip
files (Windows or Mac compression utility).
Objectives:
- To generate random numbers
- To use decision and repetition
- To make use of methods and passing values
Project setup:
Use your Net beans IDE to create the project hw04. This project should have a single class file, Main.java.
Refer to the appropriate "how to" tutorials available on the course website, for instructions on
how to create a project and manage its files.
Language features used:
- Math.random() method
- if statement
- do/while statement
- methods
Problem Description:
RUN 1
_________________________________________________
Welcome to the online PowerBall site.
What is your first name? Michael
Ok then Michael, let me generate a quick pick for you.
Your quick pick:
37 04 29 07 09 : 19
The drawing numbers:
16 24 41 45 43 : 02
Sorry Michael but you lost. Here is how close you were.
Your number deviations:
21 -20 -12 -38 -34 : 17
Play again [1-yes, 0-no]: 1
Ok then Michael, let me generate a quick pick for you.
Your quick pick:
10 27 59 14 49 : 32
The drawing numbers:
49 04 26 59 12 : 25
Sorry Michael but you lost. Here is how close you were.
Your number deviations:
-39 23 33 -45 37 : 7
Play again [1-yes, 0-no]: 0
BUILD SUCCESSFUL (total time: 45 seconds)
________________________________________________
Do you feel lucky version 2.0. In this programming exercise you are to write a power ball
generating application that makes use of methods.
Program requirements:
The requirements for this program are as follows:
(1) All the methods you are to add will include code that you already have in main(). You should
move this code out of main() and put it inside each of the methods. This will clean up main()
and make your code a lot more modular.
(2) Add the following methods to your program and move the relevant code into it, and make
the needed adjustments to each. I recommend highly that you implement one method at a
time, checking the program after each change.
(3) You will follow the same technique; Add a method, move the code from
main() into it, run the code. Lather, scrub, rinse.
public static void welcomeMessage(String message) - displays the message to the
screen.
public static String inputPlayerName(Scanner keyboard, String prompt) -
prompts the user to enter their name, reads the name and returns it.
public static int generatePickInRange(int lowerBound, int upperBound) -
generates a number that is within the specified range. Be alert with this one, cause you need
to make it work for any range, e.g. 5-10, not just 1-upperBound.
public static void displayPick(String label, int n1, int n2, int n3, int
n4, int n5, int pb) - displays the lotto pick to the screen. Same format as before.
public static boolean isAWinner(int playerNumber1, int playerNumber2,
int playerNumber3, int playerNumber4,
int playerNumber5, int playerPowerBall,
int drawingNumber1, int drawingNumber2,
int drawingNumber3, int drawingNumber4,
int drawingNumber5, int drawingPowerBall) -
returns true is the player's pick matches the drawing pick, false otherwise.
public static void displayDeviation(int playerNumber1, int playerNumber2,
int playerNumber3, int playerNumber4,
int playerNumber5, int playerPowerBall,
int drawingNumber1, int drawingNumber2,
int drawingNumber3, int drawingNumber4,
int drawingNumber5, int drawingPowerBall)
- displays the player's number deviations from the drawing numbers, like before.
public static boolean playAgain(Scanner keyboard, String prompt) - prompts
the user for their choice to continue or not. Same as before.
As you write your programs from here on out, documentation will be desirable and an essential
part of your code. Add the following section to each of your programs to identify relevant
information to anyone reading your code. The sample below is what I used for Main.java, so
make the appropriate changes to reflect your current/accurate information.
/* File: Main.java
* Name: Michael Smith
* Date: 2/14/2015
* Course: CS140 - Introduction to Computing I- Spring 15
*
* Desc: This program reads the user's name and outputs a welcome message.
*/
Administrative Requirements
- Add your name, date, description as comments at the top of your program.
- Make sure your output is formatted exactly as shown.
Explanation / Answer
hard to understand such big question..but i have idea about powerball which I done simply...hope it helps
import java.util.Random;
import java.util.Scanner;
public class Powerball
{
public static void main( String args[] )
{
final int LOW = 1;
final int HIGH = 35;
final int ARRAY_LENGTH = 35; // constant
boolean bolarray[] = new boolean[ ARRAY_LENGTH ]; // create array
// create Scanner for input from command window
Scanner input = new Scanner( System.in );
Random randomNumbers = new Random();
System.out.println("This program generates 7/35 numbers.");
System.out.println("How many sets of 7/35 numbers would you like to generate?");
int iSets = input.nextInt();
System.out.printf("This program will generate %d sets of 7/35 numbers. ",iSets);
for (int iCnt = 1; iCnt <= iSets; iCnt++)
{
int iNumPicked = 0;
for (int iNum = 1; iNum <bolarray.length; iNum++)
bolarray[iNum] = false;
do
{
int iRandomNum = LOW + randomNumbers.nextInt(HIGH - LOW + 1);
if (!(bolarray[iRandomNum]))
{
bolarray[iRandomNum] = true;
iNumPicked++;
}
} while (iNumPicked < 7);
for ( int counter = 0; counter < bolarray.length; counter++ )
if (bolarray[ counter ])
System.out.printf("%3d ",counter);
System.out.println();
}
// Print the powerball number
System.out.print( (int) (10 * Math.random() ) + 1);
} // end method main
} // end class Powerball
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.