Skip to main content

programming project help needed!! See attachment for the program that i need to do.. =)

No replies
padiclub
Offline
Joined: 2013-07-24
Points: 0

So far this is what i did.. but im not sure if its the right thing ..
Please help.. Your help will be greatly appreciated
Oh.. and im required to use math.random,math.max,math.min for the program..

import java.util.*;
public class NumberFun2
{
static Scanner input = new Scanner(System.in).useDelimiter("\r\n");

/**
* @param args
*/

public static void main(String[] args)
{
// TODO Auto-generated method stub

String a="\t\tFun with Numbers";
String b="\t\t=================";

System.out.println(a);
System.out.println(b);
System.out.println("Pls enter your name: ");
input.next();

System.out.println("Lets begin...");
System.out.println("");

int choice,num1,num2,generatedNum,count=0;
boolean redo=true;
boolean redo2=true;

do

{
System.out.println(a);
System.out.println(b);
System.out.println("1. Set number of random numbers and the highest possible value to generate");
System.out.println("2. Show statistic for each run");
System.out.println("3. Exit");
System.out.println("Please enter your choice(1-3): ");
System.out.println("--------------------------------");
choice = input.nextInt();
System.out.println("");
switch(choice)

{
case 1 :
count++;
do
{

System.out.print("Pls enter the number of random numbers to generate (between 2 - 10): ");
num1 = input.nextInt();
if ((num1>=2)&&(num1<=10))
redo=false;
else
System.out.println("*** Numbers should be between 2 - 10 ***");
}
while(redo);

do
{System.out.println("Pls enter the highest possible value generated 10 - 50: ");
num2 = input.nextInt();
if ((num2>=10)&&(num2<=50))
redo2=false;
else
System.out.println("*** Numbers should be between 10 - 50 ***");
System.out.println("");
}
while (redo2);

System.out.println("The following numbers are generated : run #"+count);
System.out.println("=============================================");

int numOne = 0;
while (numOne < num1)
{
generatedNum = randomGenerator(num2);
System.out.print(generatedNum+"\t");
numOne++;

}

System.out.println("");
System.out.println("");

break;
case 2 :
System.out.println("Run\t\t"+"Lowest\t"+"Highest\t"+"Average");
System.out.println("---\t\t"+"------\t"+"-------\t"+"------");

break;

case 3 :
System.out.println("Hope you enjoyed the game. BYE.");

break;

default :
System.out.println("Please choose number between (1 - 3).Thank you.");

}

}while (choice!=3);

} static int randomGenerator (int x)

{
return (int)(x * Math.random());

}

}

AttachmentSize
starting.jpg1.47 MB