Download Lab 06: Branching Mechanism

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Kingdom of Saudi Arabia
Ministry of Higher Education
University of Hail
College of Computer Science and Engineering
Department of Computer Science and Software Engineering
ICS102: fundamentals of Computer Programming (201602)
preparedd By: Ebtisam Hamed
Lab 06: Branching Mechanism
Objectives
Designing and implementing Java programs that deal with:



if-else
statements.
Multiway if-else statements.
switch statements.
Reminder
1. Scanner class constructors.
2. Scanner class methods:
1.
2.
3.
4.
int nextInt()
double nextDouble()
String next()
String nextLine()
Exercises
Exercise 1:
(even.java)
Write a program that reads an integer x and checks ether it is divisible by 2 , 3 and
5. Print appropriate messages.
Exercise 2:
(HonorCalculator.java)
Design and implement a Java program that takes a student GPA as an input and then
prints a message dialoge with the equavilant distinction (First, second or third
distinction) as follows:
GPA >= 3.75
: First distinction
3.5 <= GPA < 3.75 : Second distinction
3.25 <= GPA < 3.5 : Third distinction
GPA < 3.0
: There is no distinction awarded
Hint: to read double value using Scanner object
Exercise 3:
(Traffic.java)
Design and implement a Java program that get a traffic violation number and output
the traffic violation title and price based on the following table: Hint (use Switch)
Number
1
2
3
4
5
6
else
Title
Not stopping at (STOP) signs
Usage of improper light
Sudden start-up (heeling)
Violating speed limit
Leaving the car unattended on public streets
Destroying the Denver boot
undefined
Price
SR 100
SR 200
SR 200
SR 100
SR 200 + Towing cost
SR 2500 + Dismiss
undefined
Exercise 4:
(Menu.java)
Design and implement a Java program that prompts the user to enter 2 numbers of
type int then displays a menu on the screen as shown below:
a. Print
b. Print
c. Print
- Choose
sum
sum and average
sum, average, and max
an option [a, b, c]: _
The program reads the user’s option as a integer using Scanner object and then
display the result.
Related documents