Question

In this lab, you complete a partially written Java program that includes methods that require multiple...

In this lab, you complete a partially written Java program that includes methods that require multiple parameters (arguments). The program prompts the user for two numeric values. Both values should be passed to methods named calculateSum(), calculateDifference(), and calculateProduct(). The methods compute the sum of the two values, the difference between the two values, and the product of the two values. Each method should perform the appropriate computation and display the results. The source code file provided for this lab includes the variable declarations and the input statements. Comments are included in the file to help you write the remainder of the program. Instructions Write the Java statements as indicated by the comments. Execute the program. // Computation.java - This program calculates sum, difference, and product of two values. // Input: Interactive. // Output: Sum, difference, and product of two values. import java.util.Scanner; public class Computation { public static void main(String args[]) { double value1; String value1String; double value2; String value2String; Scanner input = new Scanner(System.in); System.out.println("Enter the first numeric value: "); value1String = input.nextLine(); value1 = Double.parseDouble(value1String); System.out.println("Enter second numeric value: "); value2String = input.nextLine(); value2 = Double.parseDouble(value2String); // Call calculateSum() here // Call calculateDifference() here // Call calculateProduct() here System.exit(0); } // End of main() method. // Write calculateSum() method here. // Write calculateDifference() method here. // Write calculateProduct() method here. } // End of Computation class.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
// Computation.java - This program calculates sum, difference, and product of two values.
// Input: Interactive.
// Output: Sum, difference, and product of two values.

import java.util.Scanner;

public class Computation {
    public static void main(String args[]) {
        double value1;
        String value1String;
        double value2;
        String value2String;
        Scanner input = new Scanner(System.in);
        System.out.println("Enter the first numeric value: ");
        value1String = input.nextLine();
        value1 = Double.parseDouble(value1String);
        System.out.println("Enter second numeric value: ");
        value2String = input.nextLine();
        value2 = Double.parseDouble(value2String);
        // Call calculateSum() here
        calculateSum(value1, value2);
        // Call calculateDifference() here
        calculateDifference(value1, value2);
        // Call calculateProduct() here
        calculateProduct(value1, value2);
        System.exit(0);
    } // End of main() method.

    // Write calculateSum() method here.
    public static void calculateSum(double value1, double value2) {
        System.out.println(value1 + " + " + value2 + " = " + (value1 + value2));
    }

    // Write calculateDifference() method here.
    public static void calculateDifference(double value1, double value2) {
        System.out.println(value1 + " - " + value2 + " = " + (value1 - value2));
    }

    // Write calculateProduct() method here.
    public static void calculateProduct(double value1, double value2) {
        System.out.println(value1 + " * " + value2 + " = " + (value1 * value2));
    }
} // End of Computation class.
Add a comment
Know the answer?
Add Answer to:
In this lab, you complete a partially written Java program that includes methods that require multiple...
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
  • In this lab, you complete a partially written Java program that includes two methods that require...

    In this lab, you complete a partially written Java program that includes two methods that require a single parameter. The program continuously prompts the user for an integer until the user enters 0. The program then passes the value to a method that computes the sum of all the whole numbers from 1 up to and including the entered number. Next, the program passes the value to another method that computes the product of all the whole numbers up to...

  • In this lab, you complete a partially written Java program that includes two methods that require...

    In this lab, you complete a partially written Java program that includes two methods that require a single parameter. The program continuously prompts the user for an integer until the user enters 0. The program then passes the value to a method that computes the sum of all the whole numbers from 1 up to and including the entered number. Next, the program passes the value to another method that computes the product of all the whole numbers up to...

  • Complete a partially written C++ program that includes a function that return a value. The program...

    Complete a partially written C++ program that includes a function that return a value. The program is a simple calculator that prompts the user of 2 number and an operation (+, -, * or, /). The two number and the operator are passed to the function where the appropriate arithmetic operation is performed. The result is return to the main function () where the arithmetic operation and result are displayed. For example 3 * 4 = 12 The source code...

  • IT Java code In Lab 8, we are going to re-write Lab 3 and add code...

    IT Java code In Lab 8, we are going to re-write Lab 3 and add code to validate user input. The Body Mass Index (BMI) is a calculation used to categorize whether a person’s weight is at a healthy level for a given height. The formula is as follows:                 bmi = kilograms / (meters2)                 where kilograms = person’s weight in kilograms, meters = person’s height in meters BMI is then categorized as follows: Classification BMI Range Underweight Less...

  • You will write a single java program called MadLibs. java.

    You will write a single java program called MadLibs. java. This file will hold and allow access to the values needed to handle the details for a "MadLibs" game. This class will not contain a maino method. It will not ask the user for any input, nor will it display (via System.out.print/In()) information to the user. The job of this class is to manage information, not to interact with the user.I am providing a MadLibsDriver.java e^{*} program that you can...

  • read the code and comments, and fix the program by INSERTING the missing code in Java...

    read the code and comments, and fix the program by INSERTING the missing code in Java THank you please import java.util.Scanner; public class ExtractNames { // Extract (and print to standard output) the first and last names in "Last, First" (read from standard input). public static void main(String[] args) { // Set up a Scanner object for reading input from the user (keyboard). Scanner scan = new Scanner (System.in); // Read a full name from the user as "Last, First"....

  • ********** PLEASE PROVIDE IN JAVA & NEW SET OF ALGORITHM For this lab use the program...

    ********** PLEASE PROVIDE IN JAVA & NEW SET OF ALGORITHM For this lab use the program at the bottom to sort an array using selection sort. Write a selection sort to report out the sorted low values: lowest to highest. Write another to report out the sorted high values – highest to lowest. Last but not least, the program should output all the values in the array AND then output the 2 requested sorted outputs. -----> MY OLD PROGRAM BELOW...

  • Implement a Java program using simple console input & output and logical control structures such that...

    Implement a Java program using simple console input & output and logical control structures such that the program prompts the user to enter 5 integer scores between 0 to 100 as inputs and does the following tasks For each input score, the program determines whether the corresponding score maps to a pass or a fail. If the input score is greater than or equal to 60, then it should print “Pass”, otherwise, it should print “Fail”. After the 5 integer...

  • Lab #4 – Recursive Methods for Generic ArrayList ----- JAVA The problem Use recursion to implement...

    Lab #4 – Recursive Methods for Generic ArrayList ----- JAVA The problem Use recursion to implement some list functionalities on an ArrrayList of generic type using type parameters in method definition Our goal for this lab is to continue using the divide and conquer approach of splitting a list into its head and tail and keep recursing on the tail (which happens to be smaller). However, instead of trying the approach on a string (a list of characters) we would...

  • // Arithmetic2.java - This program performs arithmetic, ( +. -, *. /, % ) on two...

    // Arithmetic2.java - This program performs arithmetic, ( +. -, *. /, % ) on two numbers // Input: Interactive. // Output: Result of arithmetic operation import javax.swing.*; public class Arithmetic2 { public static void main(String args[]) { double numberOne, numberTwo; String numberOneString, numberTwoString; String operation; double result; numberOneString = JOptionPane.showInputDialog("Enter the first number: "); numberOne = Double.parseDouble(numberOneString); numberTwoString = JOptionPane.showInputDialog("Enter the second number: "); numberTwo = Double.parseDouble(numberTwoString); operation = JOptionPane.showInputDialog("Enter an operator (+.-.*,/,%): "); // Call performOperation method here...

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