1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
laila [671]
3 years ago
7

write a program that first asks the user to enter three real numbers using GUI input. Print the sum if all three numbers are pos

itive, print the product of the two positive numbers if only one is negative - use a nested if. Then, ask the user to enter two real numbers from the console. If both numbers are negative, print the quotient.
Computers and Technology
1 answer:
den301095 [7]3 years ago
4 0

Answer:

Here is the complete program:

import javax.swing.JOptionPane;  //to use GUI in JAVA application

import java.util.Scanner;  //to take input from user at console

public class Main {

public static void main(String[] args) {  //start of main function body

 String num1, num2,num3;  //declare three variables to store strings of numbers for input dialog

 double number1, number2, number3, sum,product; //declare three double type variables to hold the real numbers  

 num1 = JOptionPane.showInputDialog("num1");  //shows a dialog box prompting user to enter value of first number i.e. num1

 number1 = Double.parseDouble(num1);  //scans and reads the value of first input number i.e. number1    

 num2 = JOptionPane.showInputDialog("num2");  //shows a dialog box prompting user to enter value of second number i.e. num2

 number2 = Double.parseDouble(num2);   //reads number2  

               num3 = JOptionPane.showInputDialog("num3");  //shows a dialog box prompting user to enter value of third number i.e. num3

 number3 = Double.parseDouble(num3);   //reads number3  

   if(number1>0&& number2>0 && number3>0){  //checks if all three numbers are positive

   sum = number1 + number2+ number3;  //displays the sum by adding all three positive numbers

   JOptionPane.showMessageDialog(null, "the sum is : " + sum , "Results", JOptionPane.PLAIN_MESSAGE );      }   // displays the result of sum in a message dialog box

 

    if(number1<0 && number2>0 && number3>0)      {  //checks if number2 and number3 are positive

   product = number2*number3;  //computes product

   JOptionPane.showMessageDialog(null, "the product is : " + product , "Results", JOptionPane.PLAIN_MESSAGE );      }  //displays the result

   else if (number2<0&&number1>0&&number3>0){  //checks if number1 and number3 are positive

    product = number1*number3;  //computes product

JOptionPane.showMessageDialog(null, "the product is : " + product , "Results", JOptionPane.PLAIN_MESSAGE );      }  //displays the result

   else if (number3<0 && number1>0 && number2>0)     {  //checks if number1 and number2 are positive

     product = number1*number2;  //computes product of 2 positive numbers

     JOptionPane.showMessageDialog(null, "the product is : " + product , "Results", JOptionPane.PLAIN_MESSAGE );      }  //displays the result

   else     {  /.if all the numbers are positive.

/*However this part is optional. You can just use else part for above else if statement and exclude this else part. In this way the product of all three positive numbers is not computed and product is only computed when only two numbers of the three are positive */

     product = number1*number2*number3;  //computes product of all three positive numbers

     JOptionPane.showMessageDialog(null, "the product is : " + product , "Results", JOptionPane.PLAIN_MESSAGE );      }   //displays the result

Scanner scan = new Scanner(System.in);  //creates a Scanner class object

double value1 , value2, quotient;  //declares variables to hold the values of two real numbers and the result of division of the two real numbers is stored in quotient variable

System.out.println("Enter the first real number: ");  //prompts user to enter the value of first real number from the console

value1 = scan.nextDouble();  //reads the first number from user

System.out.println("Enter the second real number : ");  //prompts user to enter the value of second real number from the console

value2 = scan.nextDouble();  //reads the second number from user

if(value1<0&&value2<0)  {  //checks if both the numbers are negative

quotient = value1/value2;  //compute the quotient

JOptionPane.showMessageDialog(null, "the quotient is : " + quotient , "Results", JOptionPane.PLAIN_MESSAGE );    }  //displays result

 else  //if both numbers are not negative

JOptionPane.showMessageDialog(null, "Both numbers are not negative" );   //displays this message in a dialog box

  }  }

Explanation:

In the above given code if you want to display the outputs in console then alter the following statements as follows:

   if(number1>0&& number2>0 && number3>0){

   sum = number1 + number2+ number3;

  System.out.println("the sum is :  " + sum); }      

 

    if(number1<0 && number2>0 && number3>0)      {

    product = number2*number3;

      System.out.println("the product is :  " + product); }          

   else if (number2<0&&number1>0&&number3>0){

          product = number1*number3;

System.out.println("the product is :  " + product);      }

   else if (number3<0 && number1>0 && number2>0)     {

     product = number1*number2;

     System.out.println("the product is :  " + product);     }

   else     {

     product = number1*number2*number3;

      System.out.println("the product is :  " + product);      }

Scanner scan = new Scanner(System.in);

double value1 , value2, quotient;

System.out.println("Enter the first real number: ");

value1 = scan.nextDouble();

System.out.println("Enter the second real number : ");

value2 = scan.nextDouble();

if(value1<0&&value2<0)  {

quotient = value1/value2;

 System.out.println("the quotient is :  " + quotient);   }

 else  

System.out.println("Both numbers are not negative");

Notice that all the JOptionPane.showMessageDialog statement are changed with System.out.println which prints the results on the console.

You might be interested in
in a block in a blockchain what represents the transactional data, sender, receiver, and number of coins? group of answer choice
erastova [34]

In a block in a blockchain, a resource which represent the transactional data, sender, receiver, and number of coins is: A. data.

<h3>What is a blockchain?</h3>

A blockchain can be defined as a digital and dynamic financial system that is designed and developed to be used in recording and maintaining transactions that are associated with or made through the use of a bitcoin, usually as a database containing various set of data.

In this context, we can infer and logically deduce that data is a resource that typically represent all of the transactional data, sender, recipient (receiver), and the number of bitcoins in a block in a blockchain.

Read more on blockchain here: brainly.com/question/25700270

#SPJ1

6 0
9 months ago
What is also known as a visual aid in a presentation
kari74 [83]

the answer is slide

I took notes off of plato and it quoted word for word

A slide is a visual aid, also known as a single screen of presentation

:) hope this helps

5 0
3 years ago
Read 2 more answers
To make something ready for some activity is to ________it.
WINSTONCH [101]

Answer:

prepare (e.g. SQL prepared statements)

parse/convert (e.g. parse a string as an int/convert an array to string)

Explanation:

4 0
2 years ago
Suppose that the bag class is efficiently implemented with a fixed array with a capacity of 4000, as in Chapter 3 of the class t
Phoenix [80]

Answer:

b.used is 2, b.data[0] is 4, b.data[1] is 6

Explanation:

bag b;

b.insert(5); // b has 5

b.insert(4); // b has 5,4

b.insert(6); // b has 5,4,6

b.erase_one(5); // now 5 is removed , b has 4,6

so no:of elements b.used is 2

b[0]=4;

b[1]=6;

6 0
3 years ago
What is the output of the following code snippet? int i = 1; while (i != 9) { System.out.print(i + " "); i++; if (i == 9) { Syst
Monica [59]

Answer:

1 2 3 4 5 6 7 8 End

Explanation:

int i = 1;

while (i != 9){

  System.out.print (i + " ");

  i ++;

  if (i == 9){

     System.out.println("End");

  }

}

7 0
2 years ago
Other questions:
  • A banker would like to present a spreadsheet as part of a presentation to potential clients. The spreadsheet makes use of severa
    14·1 answer
  • Given an object context for an Entity Data Model named mmaBooks, which of the following statements would you use to add a Custom
    15·1 answer
  • Identify the four basic categories of hardware in a microcomputer system. system unit, modem, ram, and microprocessor system uni
    5·1 answer
  • What does “human-like” mean when we are talking about a machine?
    7·1 answer
  • Produce definition in computer
    9·2 answers
  • To access documents stored on a "cloud", you'll
    12·1 answer
  • Im boing exam help please In a category-based course grading system, teachers weigh a student's performance in all courses. all
    7·2 answers
  • What is the standard unit used to measure mass?​
    9·1 answer
  • 8.10 quiz edhesive A swap is: a variable used to find the smallest value in an array an algorithm used to find a value in an arr
    12·1 answer
  • Please help me with coding!
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!