Question: 4 . 9 . 1 : Complete the user interface. - Complete the following program to implement the user interface of the preceding exercise. For
: Complete the user interface.
Complete the following program to implement the user interface of the preceding exercise. For simplicity, only the units cm m and in are supported.
Hint: The value of factor or factor should be the conversion factor from the selected unit to cm Ex: If the selected unit is in factor is because in cm
import 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
Your code goes here
else if commandequalsm
Your code goes here
else if commandequalsagain
getSecond false;
else if commandequalsquit
done true;
getSecond false;
else
System.out.printlnSorry unknown unit.
;
getSecond false;
if getSecond If 'from' unit is valid, get to unit
unit innext;
System.out.printlnTo unit: unit;
if unitequalsin
factor; Convert from cm
else if Your code goes here
else if Your code goes here
else Your code goes here
if Your code goes here
double value innextDouble;
double result value factor factor;
System.out.printlnvalue unit result unit
;
: Reversing digits of an integer.
Write a program that prints all digits of any integer in reverse order.
import java.util.Scanner;
public class ReverseDigits
public static void mainString args
Scanner in new ScannerSystemin;
int n innextInt;
TODO: Print the digits of n in reverse
Your code goes here
if n
Your code goes here
else if n
Your code goes here
while Your code goes here
Your code goes here
System.out.print Your code goes here ;
System.out.println;
: Simple while Loop Exercises.
Let's modify the program from this section so that the user can supply the interest rate. For very small interest rates, it may take a very long time for the balance to double. Assume the user can't wait for more than twenty years. Stop adding interest when the balance has doubled or twenty years have elapsed.
import java.util.Scanner;
This program computes the time required to double an investment.
public class DoubleInvestment
public static void mainString args
final double INITIALBALANCE ;
final double TARGET INITIALBALANCE;
double balance INITIALBALANCE;
int year ;
Scanner in new ScannerSystemin;
System.out.printInterest rate in percent: ;
double rate innextDouble;
TODO: Count the years required for the investment to double
but no more than years
Your code goes here
System.out.printlnYear: year;
System.out.printfBalance: fn balance;
Please follow the format provided thank you soo muchh!!
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
