Question: Java What do you need to know in order to do this lab? Input, Output, Validation, Compound Conditions, Functions, Loops and Decisions What you will
Java
What do you need to know in order to do this lab?
Input, Output, Validation, Compound Conditions, Functions, Loops and Decisions
What you will do:
For your third lab, you will use the files in JavaLab3 and you will upload it in your Dr Java environment.
You will then compile it and run it.
The goal of the program is to find the highest run of positive and even numbers higher than 100.
To do this, you will ask the user for numbers, and add them. As soon as the sum of the numbers reaches 100 or the total number of number entered is 5 or greater, you will stop and tell the user what their total for this run is.
You will then ask the user if they want to play again. You will keep track of the highest run, and display it when the user is done playing.
Note: you will need to use exactly 3 loops to get the maximum credit, and use compound conditions where applicable.
You will also need to have a minimum of two functions, one of these returning a value.
Example:
Example: Please enter a number: <5 odd numbers are not allowed. Please enter a number: < 100 The total for this run is 100 -----------
Do you want to play again ?Do you want to play again ?
ask java code and pseudocode
make up the java code :
import java.io.*;
public class JavaLab3 {
public static void main(String[] args) {
// first we define our input streams.
InputStreamReader input = new InputStreamReader(System.in);
BufferedReader reader = new BufferedReader(input);
// constant declarations
final Integer MAX = 100;
final Integer MAX_NUMBER = 4;
// variable declarations
String sName;
Integer currentRun;
Integer currentNumber;
Integer maxRunToDate = 0;
// we catch exceptions if some are thrown.
// an exception would be entering a string when a number is expected
try {
System.out.println("what is your name?");
// we read a string from the stream
sName = reader.readLine();
currentRun = 0;
System.out.println("Please enter a number");
currentNumber = Integer.parseInt(reader.readLine());
currentRun = currentRun + currentNumber;
System.out.println("The total for this run is "+ currentRun);
} catch (IOException e){
System.out.println("Error reading from user");
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
