You are on page 1of 2

GRADE-8

JAVA WORKSHEET HW
1) Write a JAVA program that performs the following:
Ask a user to enter a number.
• If the number is between 0 and 10, write the word blue.
• If the number is between 10 and 20, write the word red.
• If the number is between 20 and 30, write the word green.
• If it is any other number, write that it is not a correct color option.

2) Horses are entered for a horse race. A horse may have to carry a penalty
weight in addition to the rider. This weight is added to the saddle. The penalty
weight (if any) depends on the number of wins the horse has achieved in
previous races.
The penalty weight is calculated as follows:

Number of previous wins Penalty weight (kg)


Penalty weight (kg)

0 0
1 or 24 4
Over 28 8

Write a JAVA program that displays the following:-


1 INPUT name of horse
2 INPUT number of previous wins
3 CALCULATE penalty weight
4 STORE penalty weight
5 OUTPUT name of horse, penalty weight

3) Write a program in JAVA to print the RailwayTicket with the following


description.

String name: to store the name of the customer.


String coach: to store the type of coach customer wants to travel.
long mobno: to store customer’s mobile number.
int amt: to store basic amount of ticket.
int totalamt: to store the amount to be paid after updating the original amount.
To take input for name, coach, mobile number and amount. Calculate and print
the updated the amount as per the coach selected. Extra amount to be added in
the amount as follows:
GRADE-8
JAVA WORKSHEET HW
Type of coaches Amount
First_AC 700
Second_AC 500
Third_AC 250
sleeper None
To display all details of a customer such as name, coach, total amount and
mobile number.

4) Write a JAVA program that calculates the current balance in


a savings account.
The program should obtain from the user the following information:
• the starting balance
• the total amount of deposits made
• the total amount of withdrawals made
• the monthly interest rate
After the program has calculated the current balance, it should be displayed on
the screen. Assume one input for deposits and one input for withdrawals.

5) Write a java class to calculate and print the electricity bill to be paid by a
customer. Assume that the customer pays a rent of Rs. 250.00 .
No. of units Charge per unit
Upto 100 units Rs. 1.50
For the next 100 units Rs. 2.00
For next 50 units Rs. 2.50
Beyond 250 units Rs. 4.00

You might also like