Sale!

CSC 1301 Assignment 5 solved

Original price was: $35.00.Current price is: $30.00. $25.50

Category:

Description

5/5 - (8 votes)

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.

/*
* Trying nested-if and switch-case statements.
*/
public classPrintNumberInWord { // Save as “PrintNumberToWordie.java”
public static void main(String[] args) {
int number = 5; // Set the value of “number” here!
// Using nested-if
if (number == 1) {
System.out.println( …….);
} else if ( ……) {
……
} else if ( ……) {
……
……
} else {
……
}
// Using switch-case to do the same
switch(number) {
case 1: System.out.println( …… ); break; // Don’t forget “break”
case2:System.out.println( ……); break;
……
……
default: System.out.println( …… );
}
}
}
// Demo sample for user input
// Use as a guide
import java.util.Scanner;
Program #2: Convert Program #1 into using some sort of switch- case statement this
program should be name PrintNumberToWordie2
Hints:
class IfElse_Demo {
public static void main(String[] args) {
int marksObtained, passingMarks;
passingMarks = 40;
Scanner input = new Scanner(System.in);
System.out.println(“Input marks scored by you”);
marksObtained = input.nextInt();
if (marksObtained >= passingMarks) {
System.out.println(“You passed the exam.”);
}
else {
System.out.println(“Unfortunately,youfailedtopassthe exam.”);
}
}
}
//check Code logic below
if ()
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
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.