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

Assignment 2 - Decision - 1

Uploaded by

saad.ahm.salama
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)
8 views2 pages

Assignment 2 - Decision - 1

Uploaded by

saad.ahm.salama
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

Code Masry www.codemasry.

com

Programming Assignment #2

Decisions
1- Leap Year

A year with 366 days is called a leap year. A year is a leap year if it is divisible by 4 (for example,
the year 1980), except it is not a leap year if it is divisible by 100 (for example, the year 1900);
however, it is a leap year if it is divisible by 400 (for example, the year 2000).

There were no exceptions before the introduction of the Gregorian calendar on October 15, 1582
(for example, the year 1500 was a leap year). Write a program that asks the user for a year and
computes whether that year is a leap year or not.

Here are some sample runs of such a program:

Enter the year then press Enter : 1500

Leap year: 1500

Enter the year then press Enter : 1900

1900 not a leap year!

Enter the year then press Enter : 1996

Leap year: 1996

Enter the year then press Enter : 1997

1997 not a leap year!

Enter the year then press Enter : 2000

Leap year: 2000

Page 1
2- Calculator

Write a Java program that designs a calculator. The program should read from the user two
integer numbers and a character which indicates the type of operation desired.

3- Salary

Complete the following program to determine the raise and new salary for an employee by adding
if -else statements to compute the raise. The input to program includes the current annual salary
for the employee and a number indicating the performance rating (1=excellent, 2=good, and
3=poor). An employee with a rating of 1 will receive a 6% raise, an employee with a rating of 2
will receive a 4% raise, and one with a rating of 3 will receive a 1.5% raise.

4- Sorting Three Floating Numbers

Write a program that reads in three floating-point numbers and sorts them. For example

Use only conditional statements.

5- Min-Max

How can you find the minimum/maximum of three numbers using the conditional operator, in
just one line?

Hint: Google for ternary operator in Java.

Page 2

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy