● Firstly, without running the program, determine what the above code does. Write your answer in a text file called answers.txt. What is the output of this programme? (Provide your own input data if necessary) Write your answer in the answers.txt file. Rewrite this programme so that it is easier to read. Make sure your code has: o descriptive variable names descriptive class names O at least 3 comments consistent indentation O O code Grouping Please remember to also submit your Java source files or project.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

task 5 using intellij IDE

Firstly, without running the program, determine what the above code
does. Write your answer in a text file called answers.txt.
What is the output of this programme? (Provide your own input data if
necessary) Write your answer in the answers.txt file.
Rewrite this programme so that it is easier to read. Make sure your code
has:
O descriptive variable names
O descriptive class names
O at least 3 comments
O consistent indentation
O code Grouping
Please remember to also submit your Java source files or project.
Transcribed Image Text:Firstly, without running the program, determine what the above code does. Write your answer in a text file called answers.txt. What is the output of this programme? (Provide your own input data if necessary) Write your answer in the answers.txt file. Rewrite this programme so that it is easier to read. Make sure your code has: O descriptive variable names O descriptive class names O at least 3 comments O consistent indentation O code Grouping Please remember to also submit your Java source files or project.
Follow these steps:
Look at the poorly written, difficult to read program below:
import java.util.Scanner;
public class What Does ThisAppDo {
public static void main(String[] args) {
final int NUMBER = 5;
int int2 = 0; int int1 = 0; long startTime = System.currentTimeMillis();
string string1 = ""; Scanner string2 = new Scanner(System.in);
while (int1 < NUMBER) {
int number1 = (int) (Math.random() * 10);
int number2 = (int) (Math.random() * 10);
if (number1 < number2) {
int temp = number1; number1= number2; number2 = temp;
}
System.out.print(
"What is " + number1 +
int answer = string2.nextInt();
if (number1 - number2 == answer) { System.out.println("You are correct!");
int2++; // Increase the correct answer count
}
else
number2 + "? ");
System.out.println("Your answer is wrong.\n"
number1
+ " - " + number2 + " should be " + (number1 - number 2));
int1++;
string1 += "\n" + number1 + * + number2 + "=" + answer +
((number1 - number2 = answer) ? " correct" : "wrong");
}
long endTime = System.currentTimeMillis();
long testTime = endTime - startTime;
System.out.println("Correct count is " + int2 +
"\nTest time is " + testTime / 1000 + " seconds\n" + string1);
Transcribed Image Text:Follow these steps: Look at the poorly written, difficult to read program below: import java.util.Scanner; public class What Does ThisAppDo { public static void main(String[] args) { final int NUMBER = 5; int int2 = 0; int int1 = 0; long startTime = System.currentTimeMillis(); string string1 = ""; Scanner string2 = new Scanner(System.in); while (int1 < NUMBER) { int number1 = (int) (Math.random() * 10); int number2 = (int) (Math.random() * 10); if (number1 < number2) { int temp = number1; number1= number2; number2 = temp; } System.out.print( "What is " + number1 + int answer = string2.nextInt(); if (number1 - number2 == answer) { System.out.println("You are correct!"); int2++; // Increase the correct answer count } else number2 + "? "); System.out.println("Your answer is wrong.\n" number1 + " - " + number2 + " should be " + (number1 - number 2)); int1++; string1 += "\n" + number1 + * + number2 + "=" + answer + ((number1 - number2 = answer) ? " correct" : "wrong"); } long endTime = System.currentTimeMillis(); long testTime = endTime - startTime; System.out.println("Correct count is " + int2 + "\nTest time is " + testTime / 1000 + " seconds\n" + string1);
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY