I know I am missing somethings in my code not sure what I am supposed to put in. Here is what I have so far.

import javax.swing.JOptionPane;
public class Main_Class {


/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String firstNumber;//first number entered by user
String secondNumber;//second number entered by user
int input1;//converted first number that was entered
int input2;//converted second number that was entered
int sum;//sum of entered numbers
int difference;//difference of entered numbers
int product;//product of entered numbers
int absolute;
int num1, num2, min, max;
double average;//average of entered numbers


do {
//get the two numbers
//do the calculations
//display results
} while ( JOptionPane.showConfirmDialog(null, "Do it again?") == JOptionPane.YES_OPTION);



//read first number as a string
firstNumber = JOptionPane.showInputDialog("Enter first integer");


//read second number as a string
secondNumber = JOptionPane.showInputDialog("Enter second integer");


//convert strings to integers
input1 = Integer.parseInt(firstNumber);
input2 = Integer.parseInt(secondNumber);


//add the numbers together
sum = input1 + input2;


//calculate the difference
difference = input1 - input2;


//multiply the numbers
product = input1 * input2;


//calculate the average
average = (input1 + input2)/2;
//calculate the absolute value of the difference
int num, abs;
//get number
if (num < 0)
abs= -num;
else
abs = num;


//calculate the maximum
max = (num1 < num2) ? num1 : num2;
//calculate the minimum
min = (num1 < num2) ? num1 : num2;
//place the desired output for each variable into a string
String sumOutput = " The sum of your integers is: " +input1+ " + " +input2+ " = " +sum+ "\n";
String differenceOutput = " The difference of your integers is: " +input1+ " - " +input2+ " = " +difference+ "\n";
String productOutput = " The product of your integers is: " +input1+ " x " +input2+ " = " +product+ "\n";
String averageOutput = " The average of your integers is: (" +input1+ " + " +input2+ ") / 2  =  "+average+ "\n";
String absoluteOutput = " The absolute value of your integers is: " +input1+ " - " +input2+ " = " +absolute+ "\n";
String maxOuput = "The maximum of your integers is: " +num1+ " + " +num2+ " = " +max+ "\n";
String minOuput = "The minimum of your integers is: " +num1+ " + " +num2+ " = " +min+ "\n";
//place all strings into one string
String totalOutput = sumOutput + differenceOutput + productOutput + averageOutput + absoluteOutput + maxiOutput + minOutput;


//display the results of your calculations and strings
JOptionPane.showMessageDialog(null, totalOutput);


//program termination message
JOptionPane.showMessageDialog(null,"This concludes the program");


System.exit(0);//terminate the application
}


}

Recommended Answers

All 9 Replies

We don't know what you are supposed to put in either because you haven't told us anything about what the program is supposed to do, whether it compiles, what lines give errors, and what those errors are.

Also, please use code tags.

These are the diresctions I got for doing this program.

Their sum
Their difference
Their product
Their average
This week we will add the following operations:

The absolute value of the difference
The maximum
The minimum
If both numbers entered are over 100, then subtract 100 from each
If both numbers are negative then add 200 to their sum.
Repeat the operations until the user asks to quit.

Using your output method of choice, console, or dialog boxes, which are demonstrated in the lecture and textbook create the statements to display the results. Ensure that you provide the following:

Header for each of the operations
Output string showing the operation and results (e.g., 3 + 7 = 10)
Compile and test your program to ensure that you get the correct results of a single execution of the program.
Write code to encapsulate the algorithm from above to repeat the operation. Ask the user at the end of each iteration whether they want to perform another input operation or terminate the program.

Instead of giving us th broad description of what you were supposed to do to start out with, where we have to figure out each and everything like the logic, methods, variables etc., give us directly the error that the compiler is throwing at you or tell us where you are stuck.

I am getting an error for the last line it is saying the maxOutput and minOutput can't be resolved.
And with the loop I am having trouble figuring out what to put in to make it work.

String sumOutput = " The sum of your integers is: " +input1+ " + " +input2+ " = " +sum+ "\n";
String differenceOutput = " The difference of your integers is: " +input1+ " - " +input2+ " = " +difference+ "\n";
String productOutput = " The product of your integers is: " +input1+ " x " +input2+ " = " +product+ "\n";
String averageOutput = " The average of your integers is: (" +input1+ " + " +input2+ ") / 2  =  "+average+ "\n";
String absoluteOutput = " The absolute value of your integers is: " +input1+ " - " +input2+ " = " +absolute+ "\n";
String maxOuput = "The maximum of your integers is: " +num1+ " + " +num2+ " = " +max+ "\n";
String minOuput = "The minimum of your integers is: " +num1+ " + " +num2+ " = " +min+ "\n";
//place all strings into one string
String totalOutput = sumOutput + differenceOutput + productOutput + averageOutput + absoluteOutput + maxOutput + minOutput;


do {
//get the two numbers
//do the calculations
//display results
} while ( JOptionPane.showConfirmDialog(null, "Do it again?") == JOptionPane.YES_OPTION);
and this is what is supposed to be in the loop.
-If both numbers entered are over 100, then subtract 100 from each
If both numbers are negative then add 200 to their sum.
Repeat the operations until the user asks to quit.

>I am getting an error for the last line it is saying the maxOutput and minOutput can't be resolved.

Thats quite accurate on the part of the compiler. The reason it says this is because of this :

String maxOuput = "The maximum of your integers is: " +num1+ " + " +num2+ " = " +max+ "\n";
String minOuput = "The minimum of your integers is: " +num1+ " + " +num2+ " = " +min+ "\n";

In both places you are missing the 't' in the Output.

That was a stupid mistake I should have caught it. With the loop how do i make it work.

>If both numbers entered are over 100, then subtract 100 from each
>If both numbers are negative then add 200 to their sum.

Isn't this what you want to put in in the loop ?

Yes it is I am working on it still just could use a hint on how to word it.

This is pretty straightforward. you just need to convert these conditions into langauge syntax. You would need an if construct over here and since you need to check both the numbers you need a conditional operator. You can check these things out on the java tutorial site.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.