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
Regarding the Internet of Things (IoT), a business involved in utilities, critical infrastructure, or environmental services can
jeka94

Answer:

A. true

Explanation:

Based on the information provided within the question it can be said that the statement is completely true. This is because, traffic-monitoring applications have the main function of monitoring and analyzing the flow of traffic of one or various different items. Which can be applied to the business involving utility, infrastructure, and environmental services by monitoring the specific items regarding each business. Therefore making sure that enough product is entering or leaving each business as it is suppose to. As well as providing stock analysis and defective product alerts.

6 0
3 years ago
What is the purpose of flight simulator programs, and what are some of the benefits of using them?
saw5 [17]

Answer:

Flight simulators provide a cost-effective way for pilots to practice both routine and rarely-used skills. With simulator training, you can refine your skills in a variety of different flight scenarios that can be tailored to your specific goals.

Explanation:

hope this helps <3

6 0
2 years ago
Read 2 more answers
The science of networking is attributed to which government's involvement?
worty [1.4K]

Answer:

The United States

if I am not mistaken

6 0
2 years ago
Understanding Sequential Statements Summary
Kisachek [45]

Answer:

// Payroll.java

public class Payroll

{

int numOfDependents;

double salary;

double salaryToHome;

double Federal_Tax,TAX_RATE,Depen_tax;

 

Payroll(double salry,int nod)

{

numOfDependents=nod;

salary=salry;

Federal_Tax=6.5;

TAX_RATE=28.0;

Depen_tax=2.5;

}

 

double getTAX_RATE()

{

return TAX_RATE*salary/100;

}

double Federal_Tax()

{

return Federal_Tax*salary/100;

}

double getDepenAmount()

{

return numOfDependents*(Depen_tax*salary/100);

}

double getTakeHomeSalary()

{

return salary+getDepenAmount()-(getTAX_RATE()+Federal_Tax());

}

void printOutput()

{

System.out.print("\nState Tax: $"+getTAX_RATE());

System.out.print("\nFederal Tax: $"+Federal_Tax());

System.out.print("\nDependents: $"+getDepenAmount());

System.out.print("\nSalary: $"+salary);

System.out.println("\nTake Home Pay: $"+getTakeHomeSalary());

 

}

public static void main(String args[])

{

Payroll obj=new Payroll(1250,2);

obj.printOutput();

}

}

// ModifiedPayroll.java

import java.util.Scanner;

public class ModifiedPayroll

{

 

int numOfDependents;

double salary;

double salaryToHome;

double Federal_Tax,TAX_RATE,Depen_tax;

 

ModifiedPayroll(double salry,int nod)

{

//initialise variables

numOfDependents=nod;

salary=salry;

Federal_Tax=6.5;

TAX_RATE=28.0;

Depen_tax=2.5;

}

 

double getTAX_RATE()

{

return TAX_RATE*salary/100;

}

double Federal_Tax()

{

return Federal_Tax*salary/100;

}

double getDepenAmount()

{

return numOfDependents*(Depen_tax*salary/100);

}

double getTakeHomeSalary()

{

return salary+getDepenAmount()-(getTAX_RATE()+Federal_Tax());

}

void printOutput()

{

System.out.print("\nState Tax: $"+getTAX_RATE());

System.out.print("\nFederal Tax: $"+Federal_Tax());

System.out.print("\nDependents: $"+getDepenAmount());

System.out.print("\nSalary: $"+salary);

System.out.println("\nTake Home Pay: $"+getTakeHomeSalary());

 

}

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

System.out.print("\nEnter Salary: $");

double salary=sc.nextDouble();

System.out.print("\nEnter number Of Dependents:$");

int nob=sc.nextInt();

ModifiedPayroll obj=new ModifiedPayroll(salary,nob);

obj.printOutput();

}

}

Explanation/Output:

// For Payroll.java

State Tax: $350.0

Federal Tax: $81.25

Dependents: $62.5

Salary: $1250.0

Take Home Pay: $881.25

// For ModifiedPayroll.java

Enter Salary:$1550.0

Enter number of Dependents:$3

State Tax: $434.0

Federal Tax: $100.75

Dependents: $116.25

Salary: $1550.0

Take Home Pay: $1131.5

8 0
3 years ago
Who wants to be my tutor?
anzhelika [568]

Answer:

i would but im not big brain

Explanation:

8 0
3 years ago
Read 2 more answers
Other questions:
  • What does iSCSI stand for?
    5·2 answers
  • Jason is an aspiring filmmaker. He manages finance and makes sure that everyone is involved in the project. Which role is Jason
    12·1 answer
  • One type of technology that can verify a person's identity is _____.
    6·2 answers
  • What test is most similar to binary​
    9·1 answer
  • What is a good way to minimize technical problems with your computer
    10·1 answer
  • Which type of cloud computing offers easily accessible software and applications on the machines?
    7·1 answer
  • Match the installation type to its description.
    9·1 answer
  • You work in an office that uses Linux and Windows servers. The network uses the IP protocol. You are sitting at a Windows workst
    13·1 answer
  • Which part of project management considers if employees will work at home or in the office?
    10·2 answers
  • WHICH PROGRAMMING LANGUAGES ARE THE BEST FOR PROGRAMMING?
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!