| | |
Pls Help JAVA Program Headaches Not Giving me the right output for user input
![]() |
•
•
Join Date: Sep 2004
Posts: 2
Reputation:
Solved Threads: 0
Hi,
I just want to say thank you in advance to anyone that replies to this. I'm new to JAVA & my 4th assignment has got me stumped. I have to write a program that reads 4 integers and prints the largest and smallest value that the user entered (using joption pane) with no if statements. I also have to modify the addValue method with Math.min & Math.max methods. So far the computer is not responding to the users' input and giving me -.2147483648 for the smallest and .2147483647 for the largest. Please do not laugh I am just starting out. Once again any insight or help will be greatly appreciated. My soucre code is as follows:
class DataSet
{
private int smallest;
private int largest;
//The constructor
public DataSet()
{
smallest = Integer.MIN_VALUE;
largest = Integer.MAX_VALUE;
}
public void addValue(int x)
{
smallest = Math.min(smallest,largest);
largest = Math.max(smallest,largest);
}
public int getSmall()
{
return Math.min(smallest,largest);
}
public int getLarge()
{
return Math.max(smallest,largest);
}
}
import javax.swing.JOptionPane;
class DataSetTest
{
public static void main(String[] args)
{
DataSet myDataSet = new DataSet();
String input = JOptionPane.showInputDialog(
"Please enter the first number:");
int number1 = Integer.parseInt(input);
input = JOptionPane.showInputDialog(
"Please enter the second number:");
int number2 = Integer.parseInt(input);
input = JOptionPane.showInputDialog(
"Please enter the third number:");
int number3 = Integer.parseInt(input);
input = JOptionPane.showInputDialog(
"Please enter the fourth number:");
int number4 = Integer.parseInt(input);
myDataSet.addValue(number1);
myDataSet.addValue(number2);
myDataSet.addValue(number3);
myDataSet.addValue(number4);
System.out.println("The smallest number is " + myDataSet.getSmall());
System.out.println("The largest number is " + myDataSet.getLarge());
System.exit(0);
}
}
I just want to say thank you in advance to anyone that replies to this. I'm new to JAVA & my 4th assignment has got me stumped. I have to write a program that reads 4 integers and prints the largest and smallest value that the user entered (using joption pane) with no if statements. I also have to modify the addValue method with Math.min & Math.max methods. So far the computer is not responding to the users' input and giving me -.2147483648 for the smallest and .2147483647 for the largest. Please do not laugh I am just starting out. Once again any insight or help will be greatly appreciated. My soucre code is as follows:
class DataSet
{
private int smallest;
private int largest;
//The constructor
public DataSet()
{
smallest = Integer.MIN_VALUE;
largest = Integer.MAX_VALUE;
}
public void addValue(int x)
{
smallest = Math.min(smallest,largest);
largest = Math.max(smallest,largest);
}
public int getSmall()
{
return Math.min(smallest,largest);
}
public int getLarge()
{
return Math.max(smallest,largest);
}
}
import javax.swing.JOptionPane;
class DataSetTest
{
public static void main(String[] args)
{
DataSet myDataSet = new DataSet();
String input = JOptionPane.showInputDialog(
"Please enter the first number:");
int number1 = Integer.parseInt(input);
input = JOptionPane.showInputDialog(
"Please enter the second number:");
int number2 = Integer.parseInt(input);
input = JOptionPane.showInputDialog(
"Please enter the third number:");
int number3 = Integer.parseInt(input);
input = JOptionPane.showInputDialog(
"Please enter the fourth number:");
int number4 = Integer.parseInt(input);
myDataSet.addValue(number1);
myDataSet.addValue(number2);
myDataSet.addValue(number3);
myDataSet.addValue(number4);
System.out.println("The smallest number is " + myDataSet.getSmall());
System.out.println("The largest number is " + myDataSet.getLarge());
System.exit(0);
}
}
•
•
Join Date: Mar 2006
Posts: 1
Reputation:
Solved Threads: 0
Re: Pls Help JAVA Program Headaches Not Giving me the right output for user input
0
#2 Mar 15th, 2006
![]() |
Similar Threads
- Java Program Help!! (Java)
- pls help me in my java for loop assignment (Java)
- 2-dimensional array using user input of high /low temps (Java)
- getting the output of a terminal as input into a java program. (Java)
- problem with a java program (Java)
- Java program help!.please (Java)
- Creating a GUI that accepts user input help (Java)
Other Threads in the Java Forum
- Previous Thread: trying to do a date of birth comparison.
- Next Thread: HELP: Line 197 Runtime error
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary blackberry block bluetooth character chat class client code component consumer csv database desktop developmenthelp eclipse error fractal ftp game givemetehcodez graphics gui html ide image integer j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jni jpanel julia lego linked linux list loops mac map method methods mobile netbeans newbie number objects online oriented panel printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server set singleton sms sort sql string swing test textfields threads time title tree tutorial-sample ubuntu update windows working





