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

Terminals

The document discusses object-oriented programming concepts in Java like inheritance, polymorphism, encapsulation and abstraction. It contains code examples of creating classes for student and faculty management systems with inheritance and method overriding.

Uploaded by

poetanonymous11
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Terminals

The document discusses object-oriented programming concepts in Java like inheritance, polymorphism, encapsulation and abstraction. It contains code examples of creating classes for student and faculty management systems with inheritance and method overriding.

Uploaded by

poetanonymous11
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Terminals

Name : M.Adil Asrar

Roll# FA20-BEE-035

Q#1 Part A

Code:

public class Class {


String name;
int register_no ;

Class(String name, int register_no){

this.name = name;
this.register_no = register_no;

}
}

public class data extends Class {


int age;
String branch, hobby;
data(String name, int register_no,String branch, String hobby,int age) {
super(name, register_no);
this.branch = branch;
this.hobby = hobby;
this.age = age;

}
import java.util.Scanner;

public class main_class {


public static void main(String[] args) {

Scanner sc = new Scanner(System.in);


System.out.println(" enter the student name = ");
String n = sc.next();
System.out.println(" enter the register number = ");
int r = sc.nextInt();
System.out.println(" enter the branch = ");
String b = sc.next();
System.out.println(" enter the hobby = ");
String h = sc.next();
System.out.println(" enter the age = ");
int a = sc.nextInt();
data d = new data(n, r, h, b, a);
System.out.println("student name = " +d.name);
System.out.println(" registeration number = " +d.register_no);
System.out.println(" Branch = " +d.branch);
System.out.println(" Hobby = " +d.hobby);
System.out.println(" age = " +d.age);

Output:
Q#1 Part B

public class array {


static int findMaximum(int arr[], int low, int high)
{
int max = arr[low];
int i;
for (i = low; i <= high; i++)
{
if (arr[i] > max)
max = arr[i];
}
return max;
}

public static void main (String[] args)


{
int arr[] = {1, 30, 40, 50, 60, 70, 23, 20};
int n = arr.length;
System.out.println("The maximum elements are = "+
findMaximum(arr, 0, n-1));
}

}
Output :

Q#2

package terminals_q2;

public class Faculty {


private int id;
private String name;

public Faculty(int id, String name)


{
this.id = id;
this.name = name;
}
public int getId()
{
return id;
}
public void setId(int id)
{
this.id = id;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public double calculateSalary()
{
return 0;
}

package terminals_q2;

public class VisitingFaculty extends Faculty {


private double hours;
private double salaryPerHr;

public VisitingFaculty(int id, String name, double hours, double salaryPerHr)


{
super(id, name);
this.hours = hours;
this.salaryPerHr = salaryPerHr;
}
public double getHours() {
return hours;
}
public void setHours(double hours) {
this.hours = hours;
}
public double getSalaryPerHr() {
return salaryPerHr;
}
public void setSalaryPerHr(double salaryPerHr) {
this.salaryPerHr = salaryPerHr;
}
@Override
public double calculateSalary()
{
return super.calculateSalary()+(hours*salaryPerHr);
}

}
package terminals_q2;

public class PermanentFaculty extends Faculty {


private double salary;

public PermanentFaculty(int id, String name, double salary) {


super(id, name);
this.salary = salary;
}

public double getSalary() {


return salary;
}

public void setSalary(double salary) {


this.salary = salary;
}

@Override
public double calculateSalary()
{
return salary;
}

package terminals_q2;

import java.util.Scanner;

public class Test_class {

public static void main(String[] args) {


Scanner input = new Scanner(System.in);

System.out.print("Enter the numbers of employees = ");

int noe = input.nextInt();

Faculty[] faculty = new Faculty[noe];


for(int i=0 ; i<noe ; i++)
{
System.out.println("\n enter the data that you want to enter =
") ;
System.out.printf("1:PermanentFaculty 2:Visiting ");
System.out.println("\noption = ");
int option = input.nextInt();
if(option ==1)
{
System.out.printf("Enter the id = ");
int id=input.nextInt();
System.out.print("Enter the name =" );
String name=input.next();
System.out.print("Enter the salary =");
double salary=input.nextDouble();

faculty[i] = new PermanentFaculty (id, name, salary);


}
else if (option ==2)
{
System.out.print("Enter the id = ");
int id = input.nextInt();
input.nextLine();

System.out.print("Enter the name = " );

String name = input.nextLine();


System.out.print("Enter the hours =");
double hours = input.nextInt();
System.out.print("Enter the salaryPerHr = ");
double salaryPerHr = input.nextDouble();

faculty[i] = new VisitingFaculty


(id,name,hours,salaryPerHr);
}
else
{
System.out.println("Invalid option selected ");

System.exit(0);
}
}

for(int i=0 ; i<noe ; i++)


{
System.out.println("Name =" + faculty[i].getName() + " :: " + "
Salary = " + faculty[i].calculateSalary());
}
System.out.println("\n Salary of permanent faculty members after 10%
increment = ");

for(int i=0 ; i<noe ; i++)


{
if(faculty[i] instanceof PermanentFaculty)
{
double newSalary = faculty[i].calculateSalary() +
0.1*faculty[i].calculateSalary();
System.out.println("Name = " + faculty[i].getName() +
" :: " + " Salary = " + newSalary);
}
}
}

}
Output :

Q#3

import java.util.Scanner;

public class Adress {private String city;


private String country;

public Adress (String city, String country) {


this.city = city;
this.country = country;
}

public String getCity() {


return city;
}

public void setCity(String city) {


this.city = city;
}
public String getCountry() {
return country;
}

public void setCountry(String country) {


this.country = country;
}

class Person {
private String name;
private Adress address;

public Person(String name, Adress address) {


this.name = name;
this.address = address;
}

public String getName() {


return name;
}

public void setName(String name) {


this.name = name;
}

public Adress getAddress() {


return address;
}

public void setAddress(Adress address) {


this.address = address;
}
}

class Student extends Person{

private String program;


private int year;
private int fee;

public Student(String name, Adress address, String program, int year, int fee)
{
super(name, address);
this.program = program;
this.year = year;
this.fee = fee;
}

public String getProgram() {


return program;
}
public void setProgram(String program) {
this.program = program;
}

public int getYear() {


return year;
}

public void setYear(int year) {


this.year = year;
}

public int getFee() {


return fee;
}

public void setFee(int fee) {


this.fee = fee;
}
}

class Staff extends Person{

private double pay;

public Staff(String name, Adress address, double pay) {


super(name, address);
this.pay = pay;
}

public double getPay() {


return pay;
}

public void setPay(double pay) {


this.pay = pay;
}
}

class Test_class {
public static void main (String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("Enter the student information.");

System.out.println("Enter the Name = ");


String name1 = s.next();

System.out.println("Enter the City = ");


String city1 = s.next();

System.out.println("Enter the Country = ");


String country1 = s.next();

Adress address1 = new Adress(city1,country1);

Person person = new Person(name1, address1);

System.out.println("Enter the Program = ");


String program1 = s.next();

System.out.println("Enter the Year = ");


int year1 = s.nextInt();

System.out.println("Enter the Fee = ");


int fee1 = s.nextInt();

Student student = new Student(name1,address1,program1,year1,fee1);

System.out.println("Enter the staff information !");

System.out.println("Enter the name = ");


String name2 = s.next();

System.out.println("Enter the city = ");


String city2 = s.next();

System.out.println("Enter the country = ");


String country2 = s.next();

System.out.println("Enter the pay = ");


double pay = s.nextDouble();

Adress address2 = new Adress(city2,country2);


Staff staff = new Staff(name2,address2,pay);

System.out.println(" Student information ");

System.out.println("Name = " + student.getName());


System.out.println("Adress =");

System.out.println("Program = " + student.getProgram());

System.out.println("Year = " + student.getYear());


System.out.println("Fee = " + student.getFee());
System.out.println("City = " + student.getAddress().getCity());
System.out.println("Country = " + student.getAddress().getCountry());

System.out.println(" Staff information ");


System.out.println("Name = " + staff.getName());
System.out.println("City = " + staff.getAddress().getCity());
System.out.println("Country = " +staff.getAddress().getCountry());
System.out.println("Pay = " + staff.getPay());

s.close();
}

Output:

You might also like