CS110T Lab6 Student 1446 Wed
CS110T Lab6 Student 1446 Wed
Lab Objectives:
In this lab, the student will practice:
✔ Reading data values from the user.
✔ Using if and nested if statements
✔ Using switch.
2
Lab Exercise 2: Code Writing (1)
Problem Description: Convert the following switch statement into an if-else structure
char grade = 'B';
switch (grade) {
case 'A':
System.out.println("Excellent");
break;
case 'B':
System.out.println("Good");
break;
default:
System.out.println("Needs improvement");
}
Output sample :
Enter the academic standing: freshman
First year
b) Problem description: Write a Java program that takes a BMI category as input and
prints the corresponding BMI range:
• "underweight": "BMI less than 18.5"
• "normal": "BMI between 18.5 and 24.9"
• "overweight": "BMI between 25 and 29.9"
• "obese": "BMI 30 or above"
• If the user enters an invalid choice, print "Invalid choice"
3
You should do the following:
- Write a program that uses a switch statement.
Output sample :
Enter the BMI category: normal
BMI between 18.5 and 24.9
c) Problem description: Write a Java program that takes a weather condition as input and
prints a suggestion based on the weather:
• "sunny": "Wear sunglasses"
• "cloudy": "Take an umbrella just in case"
• "rainy": "Wear a raincoat"
• "snowy": "Wear a heavy coat"
• If the user enters an invalid choice, print "Invalid choice"
Output sample :
Enter the weather condition: sunny
Wear sunglasses
4
LAB6 Assignment Problems
Problem 1 Description:
Elementary students would like your help to solve their simple mathematical operations.
They asked you to create a simple calculator which can solve ( + , - , * , / ) .
Write a java program that gets two integers from the user and the operation they would like
to use, then display the result according to the operation they entered. (Using switch)
A sample Output
Enter the first number:
15
Enter the second number:
3
Enter the arithmetic operation:
/
The result is 5
5
4: Deposit
• The system should ask for amount of money to be deposit. Assume the amount in Integer.
• The system adds the amount to the caller’s account balance and displays the available funds after
deposit.
Your program should use a switch statement to display the menu (4 different options). You should also
have a variable of type Integer to store the callers account balance. You can assume the caller has (SAR
12000).