Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Complete the following program to implement the user interface of the preceding exercise. For simplicity, only the uimport java.util.Scanner; public class UnitConverter { public static
Complete the following program to implement the user interface of the preceding exercise. For simplicity, only the uimport java.util.Scanner; public class UnitConverter public static void mainString args Scanner in new ScannerSystemin; boolean done false; double factor; double factor; String unit; String unit; while done boolean getSecond true; String command innext; System.out.printlnFrom unit in cm m again, quit: command; if commandequalsin factor; Convert to cm unit command; else if commandequalscm factor; Already in cm unit command; else if commandequalsm factor; Convert to cm unit command; else if commandequalsagain getSecond false; else if commandequalsquit done true; getSecond false; else System.out.printlnSorry unknown unit. ; getSecond false; if getSecond System.out.printTo unit: ; unit innext; if unitequalsin System.out.printlnunit; factor; Convert from cm else if unitequalscm System.out.printlnunit; factor; Already in cm else if unitequalsm System.out.printlnunit; factor; Convert from cm else System.out.printlnSorry unknown unit. ; getSecond false; if getSecond double value innextDouble; double result value factor factor; System.out.printlnvalue unit result unit ; nits cm m and in are supported.
Complete the following program to implement the user interface of the preceding exercise. For simplicity, only the uimport java.util.Scanner;
public class UnitConverter
public static void mainString args
Scanner in new ScannerSystemin;
boolean done false;
double factor;
double factor;
String unit;
String unit;
while done
boolean getSecond true;
String command innext;
System.out.printlnFrom unit in cm m again, quit: command;
if commandequalsin
factor; Convert to cm
unit command;
else if commandequalscm
factor; Already in cm
unit command;
else if commandequalsm
factor; Convert to cm
unit command;
else if commandequalsagain
getSecond false;
else if commandequalsquit
done true;
getSecond false;
else
System.out.printlnSorry unknown unit.
;
getSecond false;
if getSecond
System.out.printTo unit: ;
unit innext;
if unitequalsin
System.out.printlnunit;
factor; Convert from cm
else if unitequalscm
System.out.printlnunit;
factor; Already in cm
else if unitequalsm
System.out.printlnunit;
factor; Convert from cm
else
System.out.printlnSorry unknown unit.
;
getSecond false;
if getSecond
double value innextDouble;
double result value factor factor;
System.out.printlnvalue unit result unit
;
nits cm m and in are supported.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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