0% found this document useful (0 votes)
8 views

Document

The document contains code for three Java programs: 1) A program that checks if a given year is a leap year or not using the modulo operator and conditional statements. 2) An Employee class with private member variables and public getter/setter methods that also includes a method to calculate net salary by subtracting PF amount. 3) A program that takes three integer inputs and uses if-else conditional statements to find and print the largest number among the three.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Document

The document contains code for three Java programs: 1) A program that checks if a given year is a leap year or not using the modulo operator and conditional statements. 2) An Employee class with private member variables and public getter/setter methods that also includes a method to calculate net salary by subtracting PF amount. 3) A program that takes three integer inputs and uses if-else conditional statements to find and print the largest number among the three.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Assignment 2 Submission

EDINAH GETANGE

Public class Main {

Public static void main(String[] args) {

// year to be checked

Int year = 2000;

Boolean leap = false;

// if the year is divided by 4

If (year % 4 == 0) {

// if the year is century

If (year % 100 == 0) {

// if year is divided by 400

// then it is a leap year

If (year % 400 == 0)

Leap = true;

Else

Leap = false;

// if the year is not century

Else

Leap = true;

}
Else

Leap = false;

If (leap)

System.out.println(year + “ LEAP YEAR.”);

Else

System.out.println(year + “ is not a leap year.”);

CAT 2 EDINAH GETANGE

Java programming

(a) Advantages of encapsulation

Encapsulation protects an object from unwanted access by clients.

Encapsulation allows access to a level without revealing the complex details below that level.

It reduces human errors.

Simplifies the maintenance of the application

Makes the application easier to understand

(b)
Employee.java

Public class Employee{

Private int employeeId;

Private String employeeName;

Private double salary;

Private double netSalary;

//setters

Public void setEmployeeId(int employeeId){

This.employeeId=employeeId;

Public void setEmployeeName(String employeeName){

This.employeeName=employeeName;
}

Public void setSalary(double salary){

This.salary=salary;

Public void netSalary(double netSalary){

This.netSalary=netSalary;

//getters

Public int getEmployeeId(){

Return employeeId;

Public String getEmployeeName(){

Return employeeName;
}

Public double getSalary(){

Return salary;

Public double getNetSalary(){

Return netSalary;

Public void calculateNetSalary(int pfpercentage){

Pfamount=salary*pfpercentage;

netSalary=salary-pfamount;

}
Public void main(String[] args){

Scanner sc = new Scanner(System.in);

Employee emp = new Employee();

Emp.setEmployeeId(sc.nextInt());

Emp.setEmployeeName(sc.next()) ;

Emp.setSalary(sc.nextDouble());

System.out.println(“Enter PF percentage:”);

Double pfpercentage = sc.nextDouble();

Emp.calculateNetSalary(pfpercentage);

System.out.println(“Salay is “ + emp.getNetSalary());

}
(C)

Import java.util.Scanner;

Public class Biggest_Number

Public static void main(String[] args)

Int x, y, z;

Scanner s = new Scanner(System.in);

System.out.print(“Enter the first number:”);

X = s.nextInt();

System.out.print(“Enter the second number:”);

Y = s.nextInt();

System.out.print(“Enter the third number:”);

Z = s.nextInt();
If(x > y && x > z)

System.out.println(“Largest number is:”+x);

Else if(y > z)

System.out.println(“Largest number is:”+y);

Else

System.out.println(“Largest number is:”+z);

}
}

You might also like