Java Student Needs Help

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;
}

}
 
J

Jim Cochrane

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.

If you're serious about needing help, you'll get much better results with
a better subject line, one that gives a short summary of your problem,
or a topic your problem falls under. "Java Student Needs Help" is so
vague, most people will just ignore your post.
 
A

Alex Hunsley

beyonder74 said:
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.

Throw us a bone here. What is the output/behaviour of the code you
posted? What is the expected output/behaviour?
 
J

Joona I Palaste

beyonder74 said:
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
(snip)

Here is the RandomMaxNum class:
import cs1.Keyboard;
public class Application2_A1
(snip)


And finally, the MaxNum class:
public class MaxNum

(snip)

You obviously make use of the c2i.Keyboard class, which is not a
standard Java library class, and whose code you did not show us.
Therefore we have no idea how this class works. Could you also post
the code of the relevant methods in this class? Remember, even though
your instructor has all the material related to your course assignment,
we don't. Most of us aren't even in the same school.

--
/-- Joona Palaste ([email protected]) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"A friend of mine is into Voodoo Acupuncture. You don't have to go into her
office. You'll just be walking down the street and... ohh, that's much better!"
- Stephen Wright
 
S

Scott Ellsworth

Jim Cochrane said:
If you're serious about needing help, you'll get much better results with
a better subject line, one that gives a short summary of your problem,
or a topic your problem falls under. "Java Student Needs Help" is so
vague, most people will just ignore your post.


Hey, at least he posted some source, and said it was for a class. This
is so far beyond what most new posters here do that I am staggered.

I do agree with Alex - post the output your program produces, and the
output you expected. Very often, an answer will leap right out at you
once you have done that.

You are calling returnFirst, returnSecond, and returnThird in the 'a'
instance of the RandomMaxNum class. I do not see the source for that
class, and so no returnFirst, returnSecond, or returnThird methods.

If your question was "what is the syntax for a method returning the
value of num1", a possible answer might be:

public int returnFirst(){
return num1;
}

Scott
 
T

Tris Orendorff

Joona I Palaste said:
beyonder74 <[email protected]> scribbled the following:

You obviously make use of the c2i.Keyboard class, which is not a
standard Java library class, and whose code you did not show us.
Therefore we have no idea how this class works. Could you also post
the code of the relevant methods in this class? Remember, even though
your instructor has all the material related to your course assignment,
we don't. Most of us aren't even in the same school.

I can't beleve you wrote this Joona. I am sure you can figure out what this does:

System.out.println("Enter first number: ");
first=Keyboard.readInt();

Anyhoo,

How about a main() method like this? You have most of the other parts written. Excuse the syntax errors
below:


public static void main(Stirng[]) {
int count = 0;
do {
// read first, second and third.
// generate sys1, sys2, sys3
mine=getMax(first, second, third);
computers-getMax(sys1, sys2, sys3);
count ++;
} while (mine != computers);
// print count
}


--
Sincerely,

Tris Orendorff

-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCS d++ s+:- a+ C+ UL++++ P+ L+ E- W+ N++ o- K++ w+ O+ M !V PS+ PE Y+ PGP t+ !5 X- R- tv--- b++
DI++ D+ G++ e++ h---- r+++ y+++
------END GEEK CODE BLOCK------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top