Description
Topics: (nested-if, switch-case): NO loops is allowed for this homework
x Make sure your program is properly indented. Your program only needs to have a main method.
After you have written it, compile it and run it to make sure it works.
Then submit to icollege your .java file only. I do not need the .class file for this
assignment.
Please use this heading format
//////////////////////////////////////////////////////////////
// Solution to Programming Project 3 homework #4 //
// Name: //
// Lab time: //
// Program description: //
//////////////////////////////////////////////////////////////
Program #1: Write a program which will use user input. The program should be called PrintNumberToWordie which prints “ONE”, “TWO”,… , “FIVE” UP to TEN if the int variable “number” is 1, 2,… , 5, 10, respectively be sure to code for the else/default option if no match is found. This program must Use (a) a “nested-if” statement to complete; (b) Secondly the program must have an additional if statement to check to see if the user input is divisible by 2.
Program #2: Convert Program #1 into using some sort of switch- case statement this program should be name PrintNumberToWordie2
Hints:
Program #3: Write a user input program using if else statements ONLY name of program “Magic number” the user will try guess the Magic number. The user will enters the number to guess and computer will tell the user if the number matches the Magic number and then determine if the number is smaller or greater than the initial number. The Number that is guessed must be of type int and use Math.random() function to give it random value in range 1 thru 100.
Hint**
// Var
Declarations Code goes here //Scanner input Code goes here
//check Code logic below
if ()
System.out.println(“”);
else if ()
System.out.println(“”);
else if ()
System.out.println();
expected output
Secret number is 50 Enter a guess:
50 Your guess is
50
Your guess is correct. Congratulations!
Secret number is 99 Enter a guess:
19 Your guess is
19
Your guess is smaller than the secret number.
Secret number is 72 Enter a guess:
89 Your guess is
89
Your guess is greater than the secret number.
Reviews
There are no reviews yet.