Question
Main topics: User validated input Basic String Methods if & if - else Statements Loop Statements Program Specication: Write a Java program that emulates a
Main topics: User validated input Basic String Methods if & if - else Statements Loop Statements
Program Specication: Write a Java program that emulates a simple calculator: Declare and initialize a String variable (bitstring) to "" Declare and initialize an int variable (base10) to 0 Repeat the following until the ( Exit ) option is selected:
1. Display a menu which gives the user the choice of the following menu options: 0 -> Concatenate a 0 1 -> Concatenate a 1 2 -> Exit and uses a user validation loop to read their response into a String variable. Note: You must repeatedly get the users response until it is exactly one of the characters 0 1 2 2. If ( Exit ) was NOT selected: (a) Add the selected bit (as a String) to the end of the bitstring string: ''0'' or ''1'' (b) Display the current bitstring to the screen (c) Update the base10 variable - the (base 10) equivalent of the current form of bitstring: base10 *= 2 or base10 = 2 * base10 + 1
Display the final form of bitstring with the corresponding final value of base10. equivalent.
Sample run(s): Welcome to the bitstring coverter --------------------------------------------- 0 -> Concatenate a 0 1 -> Concatenate a 1 2 -> Exit --------------------------------------------- Choose an operator from the menu above : 1 --------------------------------------------- 1 --------------------------------------------- 0 -> Concatenate a 0 1 -> Concatenate a 1 2 -> Exit --------------------------------------------- Choose an operator from the menu above : 1 --------------------------------------------- 11 --------------------------------------------- 0 -> Concatenate a 0 1 -> Concatenate a 1 2 -> Exit --------------------------------------------- Choose an operator from the menu above : 0 --------------------------------------------- 110 --------------------------------------------- 0 -> Concatenate a 0 1 -> Concatenate a 1 2 -> Exit --------------------------------------------- Choose an operator from the menu above : 0 --------------------------------------------- 1100 --------------------------------------------- 0 -> Concatenate a 0 1 -> Concatenate a 1 2 -> Exit --------------------------------------------- Choose an operator from the menu above : 1 --------------------------------------------- 11001 --------------------------------------------- 0 -> Concatenate a 0 1 -> Concatenate a 1 2 -> Exit --------------------------------------------- Choose an operator from the menu above : 1 --------------------------------------------- 110011 --------------------------------------------- 0 -> Concatenate a 0 1 -> Concatenate a 1 2 -> Exit --------------------------------------------- Choose an operator from the menu above : 2 --------------------------------------------- 110011 = 51 ---------------------------------------------
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