0% found this document useful (0 votes)
6 views2 pages

Java Ex 2

The document outlines four programming tasks that require knowledge of variables, data types, input/output, and logic in Java. The tasks include creating a grading program that evaluates student grades, a cola machine program that allows users to select beverages, a program to generate prime numbers, and a bracketing search program that involves guessing a random number. Each task specifies error handling for invalid inputs and encourages the use of control structures like if statements and switch statements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Java Ex 2

The document outlines four programming tasks that require knowledge of variables, data types, input/output, and logic in Java. The tasks include creating a grading program that evaluates student grades, a cola machine program that allows users to select beverages, a program to generate prime numbers, and a bracketing search program that involves guessing a random number. Each task specifies error handling for invalid inputs and encourages the use of control structures like if statements and switch statements.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

1.

Grading Program

Requires:

variables, data types, and numerical operators

basic input/output

logic (if statements, switch statements)

Write a program that allows the user to enter the grade scored in a java class (0-100). If the
user scored a 100 then notify the user that they got a perfect score. It should also print the
student grade based on the following scales 0-59 F 60-69 D 70-79 C 80-89 B 90-100 A

a. It should print an error “nun numeric value not allowed” if the user enters a character.

b. It should print an error “A student grade cannot be Negative” if the user enters a
negative value.

c. It should print an error “A student grade cannot exceed maximum” if the grade is
greater than 100.

2. Cola Machine

Requires:

variables, data types, and numerical operators

basic input/output

logic (if statements, switch statements)

Write a program that presents the user w/ a choice of your 5 favorite beverages (Coke, Water,
Sprite, Ambo water, Pepsi). Then to allow the user choose a beverage by entering a number

1-5. Output which beverage they chose.

a. Write the program using switch statement

b. Write the program using if, else condition


3. Generate Prime Nos

Requires:

variables, data types, and numerical operators

basic input/output

logic (if statements, switch statements)

loops (for, while, do-while)

Write a program that ask a user a no. Then the program will generate prime no’s up to a
number that is given by the user.

4. Bracketing Search

Requires:

variables, data types, and numerical operators

basic input/output

logic (if statements, switch statements)

loops (for, while, do-while)

psudo random numbers

Write a program that calculates a random number 1 through 100. The program then asks the
user guesses too high or too low then the program should output "too high" or "too low"

accordingly.

The program the user to guess the number.

It must let the user continue to guess until the user correctly guesses the number.

a. Modify the program to output how many guesses it took the user to correctly guess the
right number.

You might also like