Question
Please help and please satisfy the directions. The directions are under program 3.

port JavaScore. public class Example 4 [ public static int getint String strum - JOptionPane.showinput Dialog(Enter an integ
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

// Program3.java

import java.util.Scanner;

import javax.swing.JOptionPane;

public class Program3 {

    // method to read and return a real number using GUI

    static float getFloat() {

         String input = JOptionPane.showInputDialog("Enter a real number: ");

         return Float.parseFloat(input);

    }

    public static void main(String[] args) {

         // reading three real numbers using GUI

         float a = getFloat();

         float b = getFloat();

         float c = getFloat();

         // checking if all three are positive, assuming 0 is also positive

         if (a >= 0 && b >= 0 && c >= 0) {

             // displaying the sum of numbers using both GUI and console

             JOptionPane.showMessageDialog(null,

                      String.format("Sum of all three numbers is: %.2f", (a + b + c)));

             System.out.printf("Sum of all three numbers is: %.2f\n", (a + b + c));

         }

         // otherwise checking if only one number is negative and other two are

         // positive

         else if ((a < 0 && b >= 0 && c >= 0) || (b < 0 && c >= 0 && a >= 0)

                 || (c < 0 && a >= 0 && b >= 0)) {

             //using a nested if, finding out which number is negative

             if (a < 0) {

                 //a is negative, displaying product of b and c

                 JOptionPane.showMessageDialog(null, String.format(

                          "Product of two positive numbers is: %.2f", (b * c)));

                 System.out.printf("Product of two positive numbers is: %.2f\n",

                          (b * c));

             } else if (b < 0) {

                 //b is negative, displaying product of a and c

                 JOptionPane.showMessageDialog(null, String.format(

                          "Product of two positive numbers is: %.2f", (a * c)));

                 System.out.printf("Product of two positive numbers is: %.2f\n",

                          (a * c));

             } else {

                 //c is negative, displaying product of a and b

                 JOptionPane.showMessageDialog(null, String.format(

                          "Product of two positive numbers is: %.2f", (a * b)));

                 System.out.printf("Product of two positive numbers is: %.2f\n",

                          (a * b));

             }

         }

        

         //declaring a Scanner, reading two real numbers from console

         Scanner scanner = new Scanner(System.in);

         System.out.println("Enter two real numbers: ");

         float d = scanner.nextFloat();

         float e = scanner.nextFloat();

         //if both are negative, displaying their quotient

         if (d < 0 && e < 0) {

             JOptionPane.showMessageDialog(null, String.format(

                      "Quotient of these numbers is: %.2f", (d / e)));

             System.out.printf("Quotient of these numbers is: %.2f", (d / e));

         }

    }

}

/*OUTPUT (in the order of their appearance)*/


Input Enter a real number: 10 OK Cancel

Input Enter a real number: OK Cancel

Input Enter a real number: 11 OK Cancel

Message U Product of two positive numbers is: 110.00 TOK

Product of two positive numbers is: 110.00 Enter two real numbers: -9 -0.51

Message 0 Quotient of these numbers is: 18.00 OK

Product of two positive numbers is: 110.00 Enter two real numbers: -9 -0.5 Quotient of these numbers is: 18.00

Add a comment
Know the answer?
Add Answer to:
Please help and please satisfy the directions. The directions are under program 3. port JavaScore. public...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVA HELP: Directions Write a program that will create an array of random numbers and output...

    JAVA HELP: Directions Write a program that will create an array of random numbers and output the values. Then output the values in the array backwards. Here is my code, I am having a problem with the second method. import java.util.Scanner; import java.util.Random; public class ArrayBackwards { public static void main(String[] args) { genrate(); print(); } public static void generate() { Scanner scanner = new Scanner(System.in);    System.out.println("Seed:"); int seed = scanner.nextInt();    System.out.println("Length"); int length = scanner.nextInt(); Random random...

  • Complete the following Java program by writing the missing methods. public class 02 { public static...

    Complete the following Java program by writing the missing methods. public class 02 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("Enter a number: int n = scan.nextInt(); if (isOdd (n)) { //Print n to 1 System.out.println("Print all numbers from "+n+" to 1"); printNumToOne (n); } else { System.out.println(n + " is //End of main()

  • import java.util.Scanner; public class creditScore { public static void main(String[]args) { // declare and initialize variables...

    import java.util.Scanner; public class creditScore { public static void main(String[]args) { // declare and initialize variables int creditScore; double loanAmount,interestRate,interestAmount; final double I_a = 5.56,I_b = 6.38,I_c = 7.12,I_d = 9.34,I_e = 12.45,I_f = 0; String instructions = "This program calculates annual interest\n"+"based on a credit score.\n\n"; String output; Scanner input = new Scanner(System.in);// for receiving input from keyboard // get input from user System.out.println(instructions ); System.out.println("Enter the loan amount: $"); loanAmount = input.nextDouble(); System.out.println("Enter the credit score: "); creditScore...

  • Correct the five syntax, run-time or logic errors that are found in the CountAndAverageNumbers.java file. Link...

    Correct the five syntax, run-time or logic errors that are found in the CountAndAverageNumbers.java file. Link to the file: CountAndAverageNumbers.javaPreview the document. Make sure you include comments in your code where errors were corrected. If you do not flag each error with a comment, points will be deducted. Upload the corrected .java file here. The output of the corrected file looks like the following: Debug4Output.PNG This program reads an unspecified number of integers, determines how many positive and negative values...

  • Project 7-3 Guessing Game import java.util.Scanner; public class GuessNumberApp {    public static void main(String[] args)...

    Project 7-3 Guessing Game import java.util.Scanner; public class GuessNumberApp {    public static void main(String[] args) { displayWelcomeMessage(); // create the Scanner object Scanner sc = new Scanner(System.in); String choice = "y"; while (choice.equalsIgnoreCase("y")) { // generate the random number and invite user to guess it int number = getRandomNumber(); displayPleaseGuessMessage(); // continue until the user guesses the number int guessNumber = 0; int counter = 1; while (guessNumber != number) { // get a valid int from user guessNumber...

  • Been working on this program for hours and keep getting error. PLEASE help and show a...

    Been working on this program for hours and keep getting error. PLEASE help and show a working output, Thank you Step 2: Declaring variables Examining the problem we need to have 2 variable to store integer input given by the user.     int x,y; Step 3: setting up Scanner object and scanning the inputs import java.util.Scanner; Create Scanner class object by using following syntax Scanner=new Scanner(System.in); /* give some name to the object which ever you want */ Ask the...

  • Java programming 1. Write a program that reads an unspecified number of integers, determines how many...

    Java programming 1. Write a program that reads an unspecified number of integers, determines how many positive and negative value have been read, and computes the total and average of the input values (not counting zeros. Your program ends with the input 0. Display the average as a floating point number Here are sample runs: (red indicates a user input) Enter an integer, the input ends if it is 0: 1 2 -1 3 0 The number of positives is...

  • Need help debugging. first class seems fine. second class is shooting an error on s =...

    Need help debugging. first class seems fine. second class is shooting an error on s = super.getString(prompt);   third class is giving me an error in the while loop where int num = console.getInt("Enter an integer:"); //-------------------------------------------------------------------------- import java.util.Scanner; public class Console {     private Scanner sc;     boolean isValid;     int i;     double d;        public Console()     {         sc = new Scanner(System.in);     }     public String getString(String prompt)     {         System.out.print(prompt);         return sc.nextLine();...

  • Why does my program generate [] when viewing all guests names? ----------------------------------------------- import java.util.*; public class...

    Why does my program generate [] when viewing all guests names? ----------------------------------------------- import java.util.*; public class Delete extends Info { String name; int Id; int del; public Delete() { } public void display() { Scanner key = new Scanner(System.in); System.out.println("Input Customer Name: "); name = key.nextLine(); System.out.println("Enter ID Number: "); Id = key.nextInt(); System.out.println("Would you like to Delete? Enter 1 for yes or 2 for no. "); del = key.nextInt(); if (del == 1) { int flag = 0; //learned...

  • I have the following java-program, that creates a random walk starting at (0,0) and continuing until...

    I have the following java-program, that creates a random walk starting at (0,0) and continuing until x or y is greater than abs(n). First: I get an error, when I try closing the Scanner by inserting "reader.close(); " in line 28. It says "Unreachable code". How can I fix that? Second: Is it possible to create a different colour for the StdDraw.point when it reaches a point on one of the edges "n+1" or "n-1" ? 1 import java.util.*; 3...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT