Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

using java. using eclipse. write a program that asks to enter 3 real numbers usi

ID: 3791025 • Letter: U

Question

using java. using eclipse. write a program that asks to enter 3 real numbers using GUI. print the sum if all 3 numbers are positive, print the product of the 2 positive numbers if one is negative, use one nested if statement. all output should be to dialog and the console. ...... So i have most of this program done, i just cant figure out how to get the product of the 2 positve numbers to print to the console and dialog. Here is what I have so far.... i know the if and else if statements are correct, i just dont know how to get the if and else if to print to console and dialog correctly for the product.

import java.util.Scanner;
import javax.swing.JOptionPane;
public class Project3 {
public static float getFloat(){
  String s = JOptionPane.showInputDialog("Enter a real number");
  return Float.parseFloat(s);
}

public static void main(String[] args) {
  float x = getFloat();
  float y = getFloat();
  float z = getFloat();
  // if all three are positive print the sum
  if(x>0 && y>0 && z>0) System.out.printf("Sum:%8.2f ", (x+y+z));
  //if two of the three are positive print the product
  else if((x>0 && y>0 && z<0)||(x>0 && y<0 && z>0)||(x<0 && y>0 && z>0));
  System.out.printf("Product:%8.2f",((x*y)||(x*z)||(y*z)));
  
  
  JOptionPane.showMessageDialog(null, "Sum:"+(x+y+z)+" Product:"+((x*y)||(x*z)||(y*z)));
  
  
  Scanner scan=new Scanner(System.in);
  System.out.println(" Enter 2 real numbers");
  // if both are negative print the quotient
  float a = scan.nextFloat();
  float b = scan.nextFloat();
  if(a<0 && b<0) System.out.printf("Quotient:%8.2f", (a/b));
  JOptionPane.showMessageDialog(null, "Quotient:"+(a/b));
  
  
  System.exit(0);
}

}

Explanation / Answer

import java.util.Scanner;
import javax.swing.JOptionPane;
public class Project3 {
public static float getFloat(){
String s = JOptionPane.showInputDialog("Enter a real number");
return Float.parseFloat(s);
}
public static void main(String[] args) {
float x = getFloat();
float y = getFloat();
float z = getFloat();
float sum=x+y+z;
float product=0.0f;
// if all three are positive print the sum
if(x>0 && y>0 && z>0) System.out.printf("Sum:'%8.2f' ", sum );
//if two of the three are positive print the product
else if((x>0 && y>0 && z<0)||(x>0 && y<0 && z>0)||(x<0 && y>0 && z>0))
{
if(x>0 && y>0 && z<0)
{
product=x*y;
System.out.printf("Product:'%8.2f'", product);
}
else if(x>0 && y<0 && z>0)
{
product=x*z;
System.out.printf("Product:'%8.2f'" ,product);
}
else if(x<0 && y>0 && z>0)
{
product=y*z;
System.out.printf("Product:'%8.2f'", product);
}
}

String Result="Sum:" + sum + "&Product:" +product ;
JOptionPane.showMessageDialog(null, Result);
  
  
Scanner scan=new Scanner(System.in);
System.out.println(" Enter 2 real numbers");
// if both are negative print the quotient
float a = scan.nextFloat();
float b = scan.nextFloat();
if(a<0 && b<0) System.out.printf("Quotient:%8.2f", (a/b));
JOptionPane.showMessageDialog(null, "Quotient:"+(a/b));
  
  
System.exit(0);
}
}