Question: Java Code: Console IO Practice Exercise The purpose of this exercise is to practice console input and output with the Java console. Setup: Create a

Java Code:

Console IO Practice Exercise

The purpose of this exercise is to practice console input and output with the Java console.

Setup:

Create a class called ConsolePractice with a main method.

Create a static field in your class that stores a scanner object. You will use this scanner for all user input.

private static Scanner scanner = new Scanner(System.in);

Part A:

Create a static method called divide. Your method should do the following:

Accept two integers as parameters, a numerator and denominator

Compute the quotient and remainder of dividing the numerator by the denominator.

Print the quotient and remainder to the Java console.

Inside your main method, request two integers from the Java console and call your divide method.

Part B:

Create a static method called compare. Your method should do the following:

Accept two arguments of type int. Use the following method header:

public static int compare(int first, int second)

Your method should return the following values:

Return 0, when first and second are equal

Return -1, when first is less than second

Return 1, when first is greater than second

Inside your main method, request two integers from the Java console and pass them to your compare method. Store the result of your method call and print it to the Java console

Part C:

Create a static method called max. Your method should do the following:

Accept three arguments of type int.

Your method should print the largest of the three integers to the Java console.

Inside your main method, read in three integers from the Java console and pass them to your max method

Challenge:

Create a static method called sum. Your method should do the following:

Accept no arguments

Request an integer n from the Java console.

Use the value n to request n double values from the user (use a loop).

Sum each of the double values received and return the result.

Inside your main method, call your sum method and print the results to the Java console.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!