Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need help place these numbers into my code isible in the console output window; these are only seen, while the program is running, in
I need help place these numbers into my code
isible in the console output window; these are only seen, while the program is running, in the separate input dialog vindows Use scanner object to collect user input: Enter the first number: 3 Enter the second number: 4 The average of 3.0 and 4.0 is: 3.5 Use JoptionPane input dialog to, collect user input: The average of 3.0 and 4.0 is: 3.5 //author: Jazmine Tapia //date: 9 January 2022 I/file: GetAverage.java /* Lab 2 Part 1 Problem to solve: Calculate the average of two double data type numbers Use both Scanner object and joptionPane to collect user input Demonstrate the need to use parentheses to override operator precedence */ //import statements for scanner and JopionPane import java.util.Scanner; import javax.swing.JoptionPane; public class GetAverage \{ public static void main(String[] args) \{ //declare three double variables to store the 1/ two numbers and their average double num3, num4, avevalue; //declare String variable for use with input dialog String inputString; //create scanner object to read keyboard input Scanner keyboard = new Scanner(System.in); //get user input for the two nums with the Scanner object System.out.println("Use Scanner object to collect user input:"); //prompt user to enter the first number System. out.print("Enter the first number: 3 "); //use the nextDouble ( ) method to get a double value num3 = keyboard. nextDouble(3); //prompt user to enter the second number System. out.print("Enter the second number: 4 "); //use the nextDouble ( ) method to get a double value num2 = keyboard. nextDouble (4); I/calculate the average // note that the parentheses are required for correct output aveValue =( num3 + num4 )/3.5 //display the result to the user: System.out.print("The average of " + num3 + " and " + num 4+ " is: 3.5 "); System. out.print ln(aveValue); //get user input with JoptionPane input dialog System.out.println("Use JoptionPane input dialog to collect user input: "); //use joptionPane to get user input for first number: inputString = JoptionPane.showInputDialog ("Enter the first number: 3 "); //convert the string to a double and assign to num1 num1 = Double.parsedouble(inputString); // get user input for second number: inputString = J0ptionPane. showInputDialog("Enter the second number: 4 "); // convert the string to a double and assign to num2 num2 = Double.parsedouble(inputString); //calculate the average of the two numbers aveValue = (num3 + num4) / 3.5; //display the result to the user: System.out.print("The average of " + num3 + " and " + num4 + " is:3.5 "); System.out.println(avevalue); \}Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started