Java !!! Overview This task involves creating a class that will simulate a simple terminal / command interpreter. I.e. the program interprets and executes commands that the user enters into the program. The purpose of the laboratory is to get acquainted with different control flow constructions, how to compare strings with each other, and how strings are read in from the keyboard. Task Create a class whose task is to simulate a simple command interpreter that reads commands from the user and then executes them. Commands from the user should be loaded from the keyboard. The application is intended to function in a similar way as a terminal / command interpreter where we can write commands to e.g. compile javacode (javac) or list files in a directory (dir). When the application is started, a "prompt" must be printed (eg input>) whereupon the user can enter a command. The prompt is just a text that is printed while waiting for the user to enter a command. For example. in the command prompt in Windows, the prompt corresponds to the directory we are currently in. be H: \ java \ lab4> or C: \> (if using Windows). The command that is entered should then be interpreted and executed by your program. If an incorrect command is specified, an error message, as well as the commands that can be interpreted, must be printed. After the command is executed, the prompt should reappear and a new command can be entered by the user. This is repeated until the exit command is entered. The commands that can be interpreted are: • help: prints a help text similar to this • q: exits • quit: same as q • hello: Prints the text HelloWorld! • odd: determines whether a number is odd or not • repeat: prints any text x number of times Calc: performs a simple mathematical calculation • calculate: same as calc You must write a class named CommandPrompt which contains a class constant (public static final) and whose value is "input>". This is the prompt to be printed before each new command entry. Each command must be handled in its own private method in the class. See design suggestions on the right of the class diagram (more members need to be added) When an object of CommandPrompt is created, the start method should be called which then prints the prompt and waits for the user to enter a command. When a command is entered, the method should examine which it is and call the corresponding private method which in turn executes the command itself (see requirements below for what should happen for each command). When the command is executed, the prompt should be reprinted and a new command should be able to be entered by the user. This continues until the user enters a command to exit. Requirement • help - should print a help text of which commands can be interpreted and what each command does. • q or quit - should end the program. • hello - will print the text HelloWorld! on the screen. Odd - should ask the user for an integer and check if the number is odd or even. A printout that clearly shows whether the number is even or odd should be made. • repeat - should ask the user for an integer and a text. Then this text should be printed as many times as the integer requested. Calc or calculate - should ask the user for two numbers and a calculation method (+, -, / or *). Check what the calculation method is and then calculate the result and show it to the user. • All commands must be executed in their own methods, i.e. there should be a method that handles the command hello, one for odd, one for repeat, etc. • All screen prints should be well-structured and easy to understand. Tip • Use some form of loop in the start () method to load the command and interpret it. • To convert a string to e.g. a double, you must use the Double wrapper class. Example: String piAsStrings = "3.14"; double pi = Double.parseDouble (piAsString); • To compare one string with another string, call the equals () method on one of the string objects. Example: String s = "hello"; if (s.equals ("hello")) {// The strings are equal} else {// The strings are not equal} It is wrong to compare strings using ==. • To end the execution somewhere in the code, use System.exit (0); • Do not forget to import the correct class to be able to read from the keyboard. Declare the object, which reads from the keyboard, as an instance variable in the class so that the object can be used throughout the class. Examples of driving: in the attached pic

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

Java !!!

Overview
This task involves creating a class that will simulate a simple terminal / command interpreter. I.e. the program interprets and executes commands that the user enters into the program. The purpose of the laboratory is to get acquainted with different control flow constructions, how to compare strings with each other, and how strings are read in from the keyboard.
Task
Create a class whose task is to simulate a simple command interpreter that reads commands from the user and then executes them. Commands from the user should be loaded from the keyboard. The application is intended to function in a similar way as a terminal / command interpreter where we can write commands to e.g. compile javacode (javac) or list files in a directory (dir).
When the application is started, a "prompt" must be printed (eg input>) whereupon the user can enter a command. The prompt is just a text that is printed while waiting for the user to enter a command. For example. in the command prompt in Windows, the prompt corresponds to the directory we are currently in. be H: \ java \ lab4> or C: \> (if using Windows).
The command that is entered should then be interpreted and executed by your program. If an incorrect command is specified, an error message, as well as the commands that can be interpreted, must be printed. After the command is executed, the prompt should reappear and a new command can be entered by the user. This is repeated until the exit command is entered.
The commands that can be interpreted are:
• help: prints a help text similar to this
• q: exits
• quit: same as q
• hello: Prints the text HelloWorld!
• odd: determines whether a number is odd or not
• repeat: prints any text x number of times
Calc: performs a simple mathematical calculation
• calculate: same as calc

You must write a class named CommandPrompt which contains a class constant (public static final) and whose value is "input>". This is the prompt to be printed before each new command entry. Each command must be handled in its own private method in the class. See design suggestions on the right of the class diagram (more members need to be added)

When an object of CommandPrompt is created, the start method should be called which then prints the prompt and waits for the user to enter a command.
When a command is entered, the method should examine which it is and call the corresponding private method which in turn executes the command itself (see requirements below for what should happen for each command). When the command is executed, the prompt should be reprinted and a new command should be able to be entered by the user. This continues until the user enters a command to exit.
Requirement
• help - should print a help text of which commands can be interpreted and what each command does.
• q or quit - should end the program.
• hello - will print the text HelloWorld! on the screen.
Odd - should ask the user for an integer and check if the number is odd or even. A printout that clearly shows whether the number is even or odd should be made.
• repeat - should ask the user for an integer and a text. Then this text should be printed as many times as the integer requested.
Calc or calculate - should ask the user for two numbers and a calculation method (+, -, / or *). Check what the calculation method is and then calculate the result and show it to the user.
• All commands must be executed in their own methods, i.e. there should be a method that handles the command hello, one for odd, one for repeat, etc.
• All screen prints should be well-structured and easy to understand.
Tip
• Use some form of loop in the start () method to load the command and interpret it.
• To convert a string to e.g. a double, you must use the Double wrapper class. Example: String piAsStrings = "3.14"; double pi = Double.parseDouble (piAsString);
• To compare one string with another string, call the equals () method on one of the string objects. Example: String s = "hello"; if (s.equals ("hello")) {// The strings are equal} else {// The strings are not equal} It is wrong to compare strings using ==.
• To end the execution somewhere in the code, use System.exit (0);
• Do not forget to import the correct class to be able to read from the keyboard.

Declare the object, which reads from the keyboard, as an instance variable in the class so that the object can be used throughout the class.
Examples of driving: in the attached pic

CommandPrompt
- PROMPT : String = "input>"
+ start()
- help()
- odd()
+ main(args : String[])
Transcribed Image Text:CommandPrompt - PROMPT : String = "input>" + start() - help() - odd() + main(args : String[])
input>help
The following commands are valid:
calculate
Perform a simple mathematical calculation
calc
Same as 'calculate'
hello
Print greeting to screen
odd
Check if a certain number is odd or even
repeat
quit
Repeat a given string a certain number of times
Quit the program
Quit the program
input>hello
HelloWorld!
input>odd
Enter an integer value: 3
The number 3 is odd.
input>repeat
Enter a string: Java
Number of times to print the string: 4
Java
Java
Java
Java
input>calc
To perform this operation you have to enter 2 operands and one
operator.
Operand 1: 3
Operator: +
Operand 2: 4.5
3.0 + 4.5 = 7.5
input>java
Command unknown!
The following commands are valid:
calculate
Perform a simple mathematical calculation
calc
Same as 'calculate'
Print greeting to screen
Check if a certain number is odd or even
Repeat a given string a certain number of times
Quit the program
Quit the program
hello
odd
repeat
quit
input>
Transcribed Image Text:input>help The following commands are valid: calculate Perform a simple mathematical calculation calc Same as 'calculate' hello Print greeting to screen odd Check if a certain number is odd or even repeat quit Repeat a given string a certain number of times Quit the program Quit the program input>hello HelloWorld! input>odd Enter an integer value: 3 The number 3 is odd. input>repeat Enter a string: Java Number of times to print the string: 4 Java Java Java Java input>calc To perform this operation you have to enter 2 operands and one operator. Operand 1: 3 Operator: + Operand 2: 4.5 3.0 + 4.5 = 7.5 input>java Command unknown! The following commands are valid: calculate Perform a simple mathematical calculation calc Same as 'calculate' Print greeting to screen Check if a certain number is odd or even Repeat a given string a certain number of times Quit the program Quit the program hello odd repeat quit input>
Expert Solution
steps

Step by step

Solved in 4 steps with 4 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