B
beyonder74
I have to write a program that lets the user input three numbers
between 1 and 10, the system generates three numbers between 1 and 10.
It must calculate the max of the three system and user numbers. If the
max of each do not match, ask the user for another three and the
system will generate another three and compare again until the max of
each matches. There has to be a counter for the number of times it
runs until it matches. Here is what I have so far, but I can not get
it to return the max.
Here is the main program:
import cs1.Keyboard;
public class Application2_A1
{
public static void main (String args[])
{
int first;int second;int third;int userMax;
int sys1;int sys2;int sys3;int sysMax;
System.out.println("Enter first number: ");
first=Keyboard.readInt();
System.out.println("Enter second number: ");
second=Keyboard.readInt();
System.out.println("Enter third number: ");
third=Keyboard.readInt();
System.out.println(first+" "+second+" "+third);
RandomMaxNum a=new RandomMaxNum();
a.print();
sys1=a.returnFirst();
sys2=a.returnSecond();
sys3=a.returnThird();
}
}
Here is the RandomMaxNum class:
import cs1.Keyboard;
public class Application2_A1
{
public static void main (String args[])
{
int first;int second;int third;int userMax;
int sys1;int sys2;int sys3;int sysMax;
System.out.println("Enter first number: ");
first=Keyboard.readInt();
System.out.println("Enter second number: ");
second=Keyboard.readInt();
System.out.println("Enter third number: ");
third=Keyboard.readInt();
System.out.println(first+" "+second+" "+third);
RandomMaxNum a=new RandomMaxNum();
a.print();
sys1=a.returnFirst();
sys2=a.returnSecond();
sys3=a.returnThird();
}
}
And finally, the MaxNum class:
public class MaxNum
{
private int num1;
private int num2;
private int num3;
public MaxNum()
{
this.num1=num1;
this.num2=num2;
this.num3=num3;
}
public int getMax(int num1,int num2,int num3)
{
int tempMax=Math.max(num1,num2);
int max=Math.max(tempMax,num3);
return max;
}
public int returnMax()
{
MaxNum a=new MaxNum();
int b=a.getMax(num1,num2,num3);
return b;
}
}
between 1 and 10, the system generates three numbers between 1 and 10.
It must calculate the max of the three system and user numbers. If the
max of each do not match, ask the user for another three and the
system will generate another three and compare again until the max of
each matches. There has to be a counter for the number of times it
runs until it matches. Here is what I have so far, but I can not get
it to return the max.
Here is the main program:
import cs1.Keyboard;
public class Application2_A1
{
public static void main (String args[])
{
int first;int second;int third;int userMax;
int sys1;int sys2;int sys3;int sysMax;
System.out.println("Enter first number: ");
first=Keyboard.readInt();
System.out.println("Enter second number: ");
second=Keyboard.readInt();
System.out.println("Enter third number: ");
third=Keyboard.readInt();
System.out.println(first+" "+second+" "+third);
RandomMaxNum a=new RandomMaxNum();
a.print();
sys1=a.returnFirst();
sys2=a.returnSecond();
sys3=a.returnThird();
}
}
Here is the RandomMaxNum class:
import cs1.Keyboard;
public class Application2_A1
{
public static void main (String args[])
{
int first;int second;int third;int userMax;
int sys1;int sys2;int sys3;int sysMax;
System.out.println("Enter first number: ");
first=Keyboard.readInt();
System.out.println("Enter second number: ");
second=Keyboard.readInt();
System.out.println("Enter third number: ");
third=Keyboard.readInt();
System.out.println(first+" "+second+" "+third);
RandomMaxNum a=new RandomMaxNum();
a.print();
sys1=a.returnFirst();
sys2=a.returnSecond();
sys3=a.returnThird();
}
}
And finally, the MaxNum class:
public class MaxNum
{
private int num1;
private int num2;
private int num3;
public MaxNum()
{
this.num1=num1;
this.num2=num2;
this.num3=num3;
}
public int getMax(int num1,int num2,int num3)
{
int tempMax=Math.max(num1,num2);
int max=Math.max(tempMax,num3);
return max;
}
public int returnMax()
{
MaxNum a=new MaxNum();
int b=a.getMax(num1,num2,num3);
return b;
}
}