0% found this document useful (0 votes)
205 views22 pages

Shruti

The document contains code for multiple classes: 1) A Person class with a name attribute is defined, with subclasses Doctor and Student. Doctor displays name and specialization. 2) A Multiplier class with overloaded multiply methods to multiply integers and doubles. 3) An interface Printer with method print is defined, implemented by LaserPrinter class. 4) Classes Student and Hosteller (subclass) to store student details, with get/set methods. Hosteller adds hostel details. 5) A Passenger class to store passenger details like name, id with constructor and get/set methods. Main class accepts passenger details.

Uploaded by

Aashirya Sinha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
205 views22 pages

Shruti

The document contains code for multiple classes: 1) A Person class with a name attribute is defined, with subclasses Doctor and Student. Doctor displays name and specialization. 2) A Multiplier class with overloaded multiply methods to multiply integers and doubles. 3) An interface Printer with method print is defined, implemented by LaserPrinter class. 4) Classes Student and Hosteller (subclass) to store student details, with get/set methods. Hosteller adds hostel details. 5) A Passenger class to store passenger details like name, id with constructor and get/set methods. Main class accepts passenger details.

Uploaded by

Aashirya Sinha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 22

Person.

java
1 public class Person
2 {
3 //include the attribute specified in the question
4 String name;
5 }
Doctor.java
1 public class Doctor extends Person // inherit name from Person in Doctor
class
2 {
3 //inlcude the required attribute and method as per the problem statement
4 String specializationType;
5
6 String displayDetails(){
7 return name+" is a "+this.specializationType;
8 }
9
10 }
Driver.java
1 public class Driver
2 {
3 public static void main(String[] args)
4 {
5 //create a object for Doctor, set the name and specialization, invoke the
method and print the result
6 Doctor obj = new Doctor();
7 obj.specializationType = "Phsician";
8 obj.name = "Sera";
9 String result = obj.displayDetails();
10 System.out.println(result);
11 }

Multiplier.java
1 public class Multiplier{
2
3 //include the overloaded methods and perform the logic as specified in
the problem statement
4
5 public int multiply(int a,int b){
6 int c = a*b;
7 return c;
8 }
9
10 public int multiply(int a,int b,int c){
11 int d = a*b*c;
12 return d;
13 }
14
15 public double multiply(double a, double b){
16 double c =a*b;
17 return c;
18 }
19 }
Driver.java
1 public class Driver{
2
3 public static void main(String[] args){
4
5 //create the object of Multiplier and invoke the overloaded methods
6 int a = 4;
7 int b = 3,c=6;
8 double j = 4.5, k = 4.5;
9 Multiplier obj = new Multiplier();
10 System.out.println(obj.multiply(a,b));
11 System.out.println(obj.multiply(a,b,c));
12 System.out.println(obj.multiply(j,k));
13

Person.java
1 abstract class Person
2 {
3 //include the attribute specified in the question
4 String name;
5 abstract String displayDetails();
6
7 }
Doctor.java
1 public class Doctor extends Person // inherit name from Person in Doctor
class
2 {
3 //inlcude the required attribute and method as per the problem statement
4 String specializationType;
5 String displayDetails(){
6 return name+" is a "+specializationType;
7 }
8
9 }
Driver.java
1 public class Driver
2 {
3 public static void main(String[] args)
4 {
5 //create a object for Doctor, set the name and specialization, invoke the
method and print the result
6 Person obj = new Doctor();
7 Doctor d = (Doctor)obj;
8 obj.name = "Sear";
9 d.specializationType = "Doctor";
10 System.out.println(obj.displayDetails());
11 }

Printer.java
1 //Create a interface Printer with an abstract method print
2 //print method signature: public String print()
3
4 interface Printer{
5 abstract public String print();
6 }
LaserPrinter.java
1 //create a class ,override the print() method and return the String as
expected in the problem statement
2 class LaserPrinter implements Printer{
3 public String print(){
4 String val = "Laser Printer Printing";
5 return val;
6 }
7 }
Driver.java
1 public class Driver{
2
3 public static void main(String[] args)
4 {
5 //create an object of LaserPrinter with reference as Printer and
invoke the print method and display the result
6 LaserPrinter obj = new LaserPrinter();
7 System.out.println(obj.print());
8 }
9
10 }

Student.java
1 public class Student{
2 protected int studentId;
3 protected String name;
4 protected int departmentId;
5 protected String gender;
6 protected String phone;
7
8 public void setPhone(String phone){
9 this.phone = phone;
10 }
11
12 public void setGender(String gender){
13 this.gender = gender;
14 }
15
16 public void setName(String name){
17 this.name = name;
18 }
19
20 public void setStudentId(int id){
21 this.studentId = id;
22 }
23
24 public void setDepartmentId(int id){
25 this.departmentId = id;
26 }
27
28 public int getStudentId(){
29 return this.studentId;
30 }
31
32 public int getDepartmentId(){
33 return this.departmentId;
34 }
35
36 public String getPhone(){
37 return this.phone;
38 }
39
40 public String getGender(){
41 return this.gender;
42 }
43
44 public String getName(){
45 return this.name;
46 }
47
48 }
Hosteller.java
1 public class Hosteller extends Student{
2 private String hostelName;
3 private int roomNumber;
4
5 public int getRoomNumber(){
6 return this.roomNumber;
7 }
8
9 public String getHostelName(){
10 return this.hostelName;
11 }
12
13
14 public void setHostelName(String name){
15 this.hostelName = name;
16 }
17
18
19 public void setRoomNumber(int roomno){
20 this.roomNumber = roomno;
21 }
22
23
24
25
26
27
28
29
30
31 }
Main.java
1 import java.util.*;
2 public class Main{
3 public static void main (String[] args) {
4
5 Scanner in = new Scanner(System.in);
6 Hosteller obj = getHostellerDetails();
7 System.out.println("Modify Room Number(Y/N)");
8 char c = in.next().charAt(0);
9 if(c == 'Y'){
10 System.out.println("New Room Number");
11 obj.setRoomNumber(in.nextInt());
12 }
13 System.out.println("Modify Phone Number");
14 char h = in.next().charAt(0);
15 in.nextLine();
16 if(h == 'Y'){
17 System.out.println("New Phone Number");
18 obj.setPhone(in.nextLine());
19 }
20 display(obj);
21 }
22 public static Hosteller getHostellerDetails(){
23 Scanner in = new Scanner(System.in);
24 Hosteller obj = new Hosteller();
25
26
27 System.out.println("Enter the Details");
28 System.out.println("Student Id");
29 obj.setStudentId(in.nextInt());
30 in.nextLine();
31
32 System.out.println("Student Name");
33 obj.setName(in.nextLine());
34
35 System.out.println("Department Id");
36 obj.setDepartmentId(in.nextInt());
37 in.nextLine();
38
39 System.out.println("Gender");
40 obj.setGender(in.nextLine());
41
42 System.out.println("Phone Number");
43 obj.setPhone(in.nextLine());
44
45 System.out.println("Hostel Name");
46 obj.setHostelName(in.nextLine());
47 System.out.println("Room Number");
48 obj.setRoomNumber(in.nextInt());
49 return obj;
50 }
51 public static void display(Hosteller obj){
52 System.out.println("The Student Details\n"+obj.getStudentId()+"
"+obj.getName()+" "+obj.getDepartmentId()+" "+obj.getGender()+" "+obj.getPhone()+"
"+obj.getHostelName()+" "+obj.getRoomNumber());
53
54 }
55
56 }

Passenger.java
1 public class Passenger{
2 private int ticketid;
3 private String name;
4 private String gender;
5 private String address;
6
7 public Passenger(){
8 this.ticketid = 0;
9 this.name = null;
10 this.gender = null;
11 this.address = null;
12 }
13 public void setAddress(String address){
14 this.address = address;
15 }
16
17 public String getGender(){
18 return this.gender;
19 }
20 public String toString(){
21 return
("ticketid:"+ticketid+",name:"+name+",gender:"+gender+",address:"+address);
22 }
23 public String getAddress(){
24 return this.address;
25 }
26
27 public int getTicketid(){
28 return this.ticketid;
29 }
30
31 public String getName(){
32 return this.name;
33 }
34
35
36 public void setTicketid(int ticketid){
37 this.ticketid = ticketid;
38
39 }
40
41 public void setName(String name){
42 this.name = name;
43 }
44
45 public void setGender(String gender){
46 this.gender = gender;
47 }
48 public Passenger(int ticketid,String name, String gender, String address)
49 {
50 this.ticketid = ticketid;
51 this.name = name;
52 this.gender = gender;
53 this.address = address;
54 }
55
56 }
Main.java
1 import java.util.*;
2
3 public class Main{
4 public static void main (String[] args) {
5 Scanner in = new Scanner(System.in);
6 System.out.println("Enter the no. of passengers:");
7 int num = in.nextInt();in.nextLine();
8 String str[] = new String[num];
9 Passenger obj[] = new Passenger[num];
10 for(int i = 0; i<num; i++){
11 System.out.println("Passenger "+(i+1));
12 System.out.println("Enter the ticketid:");
13 int id = in.nextInt();
14 in.nextLine();
15 System.out.println("Enter the name:");
16 String name = in.nextLine();
17 System.out.println("Enter the gender:");
18 String gender = in.nextLine();
19 System.out.println("Enter the address:");
20 String address = in.nextLine();
21
22 obj[i] = new Passenger(id,name,gender,address);
23 str[i]=obj[i].toString();
24 }
25 for(int i = 0;i<num;i++){
26 System.out.println(str[i]);
27 }
28 }
29 }

Employee.java
1 public class Employee{
2 private String name;
3 private float salary;
4 private float netsalary;
5
6 public void setName(String name){
7 this.name = name;
8 }
9
10 public void setSalary(float salary){
11 this.salary = salary;
12 }
13
14 public void setNetsalary(float netsalary){
15 this.netsalary = netsalary;
16 }
17
18 public String getName(){
19 return this.name;
20 }
21
22 public float getSalary(){
23 return this.salary;
24 }
25
26 public float getNetsalary(){
27 return this.netsalary;
28 }
29 }
PermanentEmployee.java
1 public class PermanentEmployee extends Employee{
2 private float pfpercentage;
3 private float pfamount;
4
5 public float getPfamount(){
6 return this.pfamount;
7 }
8
9 public float getPfpercentage(){
10 return this.pfpercentage;
11 }
12
13 public void setPfpercentage(float pfpercentage){
14 this.pfpercentage = pfpercentage;
15 }
16
17 public void setPfamount(float pfamount){
18 this.pfamount = pfamount;
19 }
20
21 public void findNetSalary(){
22 this.setPfamount(this.getPfpercentage() * this.getSalary() / 100);
23 this.setNetsalary(this.getSalary() - this.getPfamount());
24 }
25 public boolean validateInput(){
26 if(this.getPfpercentage()>=0 && this.getSalary() > 0)
27 {
28 return true;
29 }
30 else {
31 return false;
32 }
33 }
34 }
Main.java
1 import java.util.*;
2 public class Main{
3 public static void main (String[] args) {
4 Scanner in = new Scanner(System.in);
5 PermanentEmployee obj = new PermanentEmployee();
6 System.out.println("Enter the name:");
7 obj.setName(in.nextLine());
8 System.out.println("Enter the salary:");
9 obj.setSalary(in.nextFloat());
10 System.out.println("Enter the pfpercentage:");
11 obj.setPfpercentage(in.nextFloat());
12
13 boolean num = obj.validateInput();
14 if(num == false){
15 System.out.println("Error!!! Unable to calculate the
NetSalary.");
16 return;
17 }
18 else{
19 obj.findNetSalary();
20 System.out.println("Employee Name:"+obj.getName());
21 System.out.printf("PF Amount:%.2f",obj.getPfamount());
22 System.out.printf("\nNetsalary:%.2f",obj.getNetsalary());
23 }
24 }
25 }

Customer.java
1 public class Customer{
2 private String name;
3 private String panno;
4 private String emailid;
5 private int salary;
6
7 public Customer(String name,String panno,String emailid, int salary){
8 this.name = name;
9 this.panno = panno;
10 this.emailid = emailid;
11 this.salary = salary;
12 }
13
14 public boolean equals(Object o){
15 Customer obj1 = (Customer) o;
16 if(obj1.getPanno().equals(this.getPanno()) &&
obj1.getEmailid().equals(this.getEmailid())){
17 return true;
18 }
19 else{
20 return false;
21 }
22 }
23
24 public void setName(String name){
25 this.name = name;
26 }
27
28 public void setPanno(String panno){
29 this.panno =panno;
30 }
31
32 public void setEmailid(String emailid)
33 {
34 this.emailid =emailid;
35 }
36
37 public void setSalary(int salary){
38 this.salary =salary;
39 }
40
41 public int getSalary(){
42 return this.salary;
43 }
44
45 public String getName(){
46 return this.name;
47 }
48
49 public String getEmailid(){
50 return this.emailid;
51 }
52
53 public String getPanno(){
54 return this.panno;
55 }
56
57
58 }
Main.java
1 import java.util.*;
2
3 public class Main{
4 public static void main (String[] args) {
5 Scanner in = new Scanner(System.in);
6 Customer obj[] = new Customer[2];
7 for(int i = 0;i<2;i++){
8 System.out.println("Enter the name:");
9 String name =in.nextLine();
10 System.out.println("Enter the panno:");
11 String no = in.nextLine();
12 System.out.println("Enter the emailid:");
13 String id = in.nextLine();
14 System.out.println("Enter the salary:");
15 int sal = in.nextInt();
16 in.nextLine();
17 obj[i] = new Customer(name,no,id,sal);
18 }
19
20 boolean val = obj[0].equals(obj[1]);
21 if(val == true){
22 System.out.println("Both the objects are equal");
23 }
24 else{
25 System.out.println("Both the objects are not equal");
26 }
27 }
28 }

Shape.java
1 abstract public class Shape{
2 public abstract double calculateArea();
3 }
Circle.java
1 import java.lang.Math;
2 public class Circle extends Shape{
3 private float radius;
4
5 public Circle(float radius){
6 this.radius = radius;
7 }
8
9 public double calculateArea(){
10 double area = Math.PI*this.getRadius()*this.getRadius();
11 return area;
12 }
13
14 public float getRadius(){
15 return this.radius;
16 }
17
18 }
Rectangle.java
1 public class Rectangle extends Shape{
2 private float length;
3 private float breadth;
4 public Rectangle(float length, float breadth){
5 this.length =length;
6 this.breadth =breadth;
7 }
8
9 public float getLength(){
10 return this.length;
11 }
12
13 public float getBreadth(){
14 return this.breadth;
15 }
16
17 public double calculateArea(){
18 double area = this.getBreadth()*this.getLength();
19 return area;
20 }
21 }
Triangle.java
1 public class Triangle extends Shape{
2 private float base;
3 private float height;
4 public Triangle(float base, float height){
5 this.base = base;
6 this.height =height;
7 }
8
9 public float getBase(){
10 return this.base;
11 }
12
13 public float getHeight(){
14 return this.height;
15 }
16
17 public double calculateArea(){
18 double area = this.getHeight()*this.getBase()*0.5;
19 return area;
20 }
21 }
Main.java
1 import java.util.*;
2
3 public class Main{
4 public static void main (String[] args) {
5 Scanner in = new Scanner(System.in);
6 System.out.println("Enter the shape :");
7 String shape = in.nextLine();
8 double area = 0;
9 //Shape obj;
10 if(shape.equals("Circle")){
11 System.out.println("Enter the radius :");
12 float rad = in.nextFloat();
13 Shape obj = new Circle(rad);
14 area = obj.calculateArea();
15 }
16 else if (shape.equals("Rectangle")){
17 System.out.println("Enter the length :");
18 float length = in.nextFloat();
19 System.out.println("Enter the breadth :");
20 float breadth = in.nextFloat();
21 Shape obj = new Rectangle(length,breadth);
22 area =obj.calculateArea();
23
24 }
25 else if(shape.equals("Triangle")){
26 System.out.println("Enter the base :");
27 float base= in.nextFloat();
28 System.out.println("Enter the height :");
29 float height = in.nextFloat();
30 Shape obj = new Triangle(base, height);
31 area =obj.calculateArea();
32 }
33 System.out.printf("The area of Circle is: %.2f",area );
34 }
35 }

Customer.java
1
2 public class Customer {
3
4
5 //Attributes
6 private int customerId;
7 private String customerName;
8 private String emailId;
9
10 //Constructor
11 public Customer(int customerId, String customerName, String emailId) {
12 super();
13 this.customerId = customerId;
14 this.customerName = customerName;
15 this.emailId = emailId;
16 }
17
18 //Getters and Setters
19 public int getCustomerId() {
20 return customerId;
21 }
22
23 public void setCustomerId(int customerId) {
24 this.customerId = customerId;
25 }
26
27 public String getCustomerName() {
28 return customerName;
29 }
30
31 public void setCustomerName(String customerName) {
32 this.customerName = customerName;
33 }
34
35 public String getEmailId() {
36 return emailId;
37 }
38
39 public void setEmailId(String emailId) {
40 this.emailId = emailId;
41 }
42
43 }
44
Account.java
1 abstract public class Account {
2
3
4 //Uncomment the getters and setters after writing the attributes
5 protected int accountNumber;
6 protected Customer customerObj;
7 protected double balance;
8
9 public Account(int accountNumber, Customer customerObj, double balance){
10 super();
11 this.accountNumber =accountNumber;
12 this.customerObj =customerObj;
13 this.balance = balance;
14 }
15
16 abstract public boolean withdraw(double amount);
17
18 public int getAccountNumber() {
19 return accountNumber;
20 }
21
22 public void setAccountNumber(int accountNumber) {
23 this.accountNumber = accountNumber;
24 }
25
26 public Customer getCustomerObj() {
27 return customerObj;
28 }
29
30 public void setCustomerObj(Customer customerObj) {
31 this.customerObj = customerObj;
32 }
33
34 public double getBalance() {
35 return balance;
36 }
37
38 public void setBalance(double balance) {
39 this.balance = balance;
40 }
41
42
43 }
SavingsAccount.java
1 public class SavingsAccount extends Account{
2
3
4
5 //Uncomment the getters and setters after writing the attributes
6 private double minimumBalance;
7
8 public SavingsAccount(int accountNumber, Customer customerObj, double
balance, double minimumBalance){
9 super(accountNumber,customerObj,balance);
10 this.minimumBalance = minimumBalance;
11 }
12
13 public boolean withdraw(double amount){
14 if((this.getBalance() - amount) > this.getMinimumBalance()){
15 this.setBalance((this.getBalance() - amount));
16 return true;
17 }
18 else{
19 return false;
20 }
21 }
22 public double getMinimumBalance() {
23 return minimumBalance;
24 }
25
26 public void setMinimumBalance(double minimumBalance) {
27 this.minimumBalance = minimumBalance;
28 }
29
30
31
32 }
33
34
Main.java
1 public class Main{
2
3 public static void main(String args[]){
4 Customer obj = new Customer(101,"Serah","[email protected]");
5 Account sobj = new SavingsAccount(1144,obj,10000,100);
6 System.out.println(obj.getCustomerId()+" "+ obj.getCustomerName()+" "+
obj.getEmailId());
7 System.out.println(sobj.withdraw(1000)+" "+sobj.getBalance()+"
"+sobj.getAccountNumber());
8 }
9 }

Vehicle.java
1
2 public class Vehicle implements Loan, Insurance{
3
4 private String vehicleNumber;
5 private String modelName;
6 private String vehicleType;
7 private double price;
8
9 public double issueLoan(){
10 String type = this.getVehicleType();
11 if(type.equals("4 wheeler")){
12 return (0.8 * this.getPrice());
13 }
14 else if(type.equals("3 wheeler")){
15 return (0.75*this.getPrice());
16
17 }
18
19 else if(type.equals("2 wheeler")){
20 return (0.5*this.getPrice());
21 }
22 return 0;
23
24 }
25
26 public double takeInsurance(){
27 double price = this.getPrice();
28 if(price <= 150000){
29 return 3500;
30 }
31 else if (price >150000 && price <=300000){
32 return 4000;
33 }
34 else{
35 return 5000;
36 }
37 }
38 public String getVehicleNumber() {
39 return vehicleNumber;
40 }
41 public void setVehicleNumber(String vehicleNumber) {
42 this.vehicleNumber = vehicleNumber;
43 }
44 public String getModelName() {
45 return modelName;
46 }
47 public void setModelName(String modelName) {
48 this.modelName = modelName;
49 }
50
51 public String getVehicleType() {
52 return vehicleType;
53 }
54 public void setVehicleType(String vehicleType) {
55 this.vehicleType = vehicleType;
56 }
57 public double getPrice() {
58 return price;
59 }
60 public void setPrice(double price) {
61 this.price = price;
62 }
63
64 public Vehicle(String vehicleNumber, String modelName, String
vehicleType,double price) {
65
66 this.vehicleNumber = vehicleNumber;
67 this.modelName = modelName;
68 this.vehicleType=vehicleType;
69 this.price = price;
70 }
71
72 }
73
Loan.java
1 public interface Loan{
2 abstract public double issueLoan();
3 }
Insurance.java
1 public interface Insurance{
2 public abstract double takeInsurance();
3 }
Main.java
1 import java.util.Scanner;
2 public class Main
3 {
4 public static void main(String[] args)
5 {
6 Scanner sc= new Scanner(System.in);
7 Vehicle obj;
8 String VehicleNumber = sc.nextLine();
9 String modelName = sc.nextLine();
10 String VehicleType = sc.nextLine();
11 double price = sc.nextDouble();
12 obj = new Vehicle(VehicleNumber,modelName,VehicleType,price);
13 System.out.println(obj.takeInsurance());
14 System.out.println(obj.issueLoan());
15
16
17 }
18 }

Employee.java
1 abstract public class Employee
2 {
3 protected int employeeId;
4 protected String employeeName;
5 protected double salary;
6
7 //Getters and Setters
8 public int getEmployeeId() {
9 return employeeId;
10 }
11 public void setEmployeeId(int employeeId) {
12 this.employeeId = employeeId;
13 }
14 public String getEmployeeName() {
15 return employeeName;
16 }
17 public void setEmployeeName(String employeeName) {
18 this.employeeName = employeeName;
19 }
20 public double getSalary() {
21 return salary;
22 }
23 public void setSalary(double salary) {
24 this.salary = salary;
25 }
26
27
28 //Write a public 2 argument constructor with arguments – employeeId,and
employeeName
29 public Employee(int employeeId, String employeeName){
30 super();
31 this.employeeId = employeeId;
32 this.employeeName =employeeName;
33 }
34
35
36
37
38 //Write a method - public void calculateSalary()
39 //Make this method as abstract
40 abstract public void calculateSalary();
41
42
43
44
45 }
PermanentEmployee.java
1 //Make this class inherit the Employee class
2
3 public class PermanentEmployee extends Employee
4 {
5 private double basicPay;
6
7 // Getters and Setters
8
9 public double getBasicPay() {
10 return basicPay;
11 }
12
13 public void setBasicPay(double basicPay) {
14 this.basicPay = basicPay;
15 }
16
17 //1. Write a public 3 argument constructor with arguments – employeeId,
employeeName and basicPay.
18 public PermanentEmployee(int employeeId,String employeeName,double
basicPay){
19 super(employeeId,employeeName);
20 this.basicPay = basicPay;
21 }
22
23
24
25 //2. Implement the - public void calculateSalary() - method
26 public void calculateSalary(){
27 double salary = this.getBasicPay() * (1-0.12);
28 this.setSalary(salary);
29 }
30
31
32
33 }
TemporaryEmployee.java
1 //Make this class inherit the Employee class
2
3 public class TemporaryEmployee extends Employee{
4
5 private int hoursWorked;
6 private int hourlyWages;
7
8 // Getters and Setters
9
10 public int getHoursWorked() {
11 return hoursWorked;
12 }
13 public void setHoursWorked(int hoursWorked) {
14 this.hoursWorked = hoursWorked;
15 }
16 public int getHourlyWages() {
17 return hourlyWages;
18 }
19 public void setHourlyWages(int hourlyWages) {
20 this.hourlyWages = hourlyWages;
21 }
22
23 //1. Write a public 4 argument constructor with arguments – employeeId,
employeeName, hoursWorked and hourlyWages.
24
25 public TemporaryEmployee(int employeeId,String employeeName, int
hoursWorked, int hourlyWages){
26 super(employeeId,employeeName);
27 this.hoursWorked =hoursWorked;
28 this.hourlyWages =hourlyWages;
29 }
30
31
32 //2. Implement the - public void calculateSalary() - method
33 public void calculateSalary(){
34 this.setSalary((this.getHourlyWages() * this.getHoursWorked()));
35 }
36
37
38
39 }
40
Loan.java
1
2 public class Loan {
3
4 //Implement the below method
5
6 public double calculateLoanAmount(Employee employeeObj) {
7 if(employeeObj instanceof PermanentEmployee){
8 return (0.15*employeeObj.getSalary());
9 }
10 else{
11 return (0.1*employeeObj.getSalary());
12 }
13 }
14
15 }
16
Main.java
1 import java.util.Scanner;
2 public class Main{
3
4 public static void main(String[] args){
5 Scanner sc=new Scanner(System.in);
6 Employee obj = new PermanentEmployee(101,"serah",10000);
7 obj.calculateSalary();
8
9 Employee objj = new TemporaryEmployee(101,"serah",150,100);
10 objj.calculateSalary();
11 Loan l =new Loan();
12 double a = l.calculateLoanAmount(obj);
13 double b = l.calculateLoanAmount(objj);
14 System.out.println(obj.getSalary()+" "+objj.getSalary()+" "+a+" "+b);
15 }
16
17 }

Main.java
1 public class Main
2 {
3 public static void main(String args[])
4 {
5
6 DisplayText obj = welcomeMessage();
7 String val = obj.getInput();
8 obj.displayText(val);
9
10 }
11 public static DisplayText welcomeMessage(){
12 DisplayText text = (String val) -> {System.out.println("Welcome
"+val);};
13 return text;
14 }
15 }
DisplayText.java
1 import java.util.Scanner;
2 @FunctionalInterface
3 public interface DisplayText
4 {
5 abstract public void displayText(String text);
6 public default String getInput(){
7 Scanner in = new Scanner(System.in);
8 String val = in.nextLine();
9 return val;
10 }
11 }

NumberType.java
1 @FunctionalInterface
2 public interface NumberType
3 {
4 public boolean checkNumberType(int number);
5 }
NumberTypeUtility.java
1 import java.util.*;
2 public class NumberTypeUtility
3 {
4 public static NumberType isOdd(){
5 NumberType obj = (int num) -> {return (num%2==0?false:true);};
6 return obj;
7 }
8 public static void main (String[] args) {
9 Scanner in = new Scanner(System.in);
10 int val = in.nextInt();
11 NumberType obj = isOdd();
12 boolean add = obj.checkNumberType(val);
13 if(add == false){
14 System.out.println(val+" is not odd");
15 }
16 else{System.out.println(val+" is odd");}
17 }
18 }

Validate.java
1 @FunctionalInterface
2 public interface Validate{
3 //write the abstract method
4 public boolean validateName(String name);
5 }
ValidateUtility.java
1 import java.util.*;
2 public class ValidateUtility
3 {
4 public static void main(String args[])
5 {
6 //fill code here
7 Scanner in = new Scanner(System.in);
8 String val = in.nextLine();
9 String value = in.nextLine();
10 Validate obj1 = validateEmployeeName();
11 boolean a1 = obj1.validateName(val);
12 if(a1 == true){
13 System.out.println("Employee name is valid");
14
15 }
16 else{
17 System.out.println("Employee name is invalid");
18 }
19
20 Validate obj2 = validateProductName();
21 boolean a2 = obj2.validateName(value);
22 if(a2 == true){
23 System.out.println("Product name is valid");
24 }
25 else{
26 System.out.println("Product name is invalid");
27 }
28 }
29
30 public static Validate validateEmployeeName()
31 {
32 //fill code here
33 Validate obj = (String val) -> {if(val.matches("[A-Za-z ]{5,20}"))
return true;
34 else return false;
35 };
36 return obj;
37 }
38
39 public static Validate validateProductName()
40 {
41 //fill code here
42 Validate obj = (String val) -> {if(val.matches("[A-Za-z]{1}[0-9]
{5}"))return true;
43 else return false;
44 };
45 return obj;
46 }
47 }

Calculate.java
1 @FunctionalInterface
2 public interface Calculate
3 {
4 public float performCalculation(int a, int b);
5 }
Calculator.java
1 import java.util.*;
2 public class Calculator
3 {
4 public static Calculate performAddition(){
5 Calculate obj = (int a,int b) -> {float c = (float)a + (float)b;
return c;};
6 return obj;
7 }
8
9 public static Calculate performSubtraction(){
10 Calculate obj = (int a, int b) -> {float c = (float)a - (float)b;
return c;};
11 return obj;
12 }
13
14 public static Calculate performProduct(){
15 Calculate obj = (int a, int b) -> {float c = (float)a * (float)b;
return c;};
16 return obj;
17
18 }
19
20 public static Calculate performDivision(){
21 Calculate obj = (int a, int b) -> {float c = (float)a / (float)b;
return c;};
22 return obj;
23 }
24
25 public static void main (String[] args) {
26 Scanner in = new Scanner(System.in);
27 int a = in.nextInt();
28 int b = in.nextInt();
29 Calculate obj = performAddition();
30 System.out.println("The sum is "+obj.performCalculation(a,b));
31 obj = performSubtraction();
32 System.out.println("The difference is "+obj.performCalculation(a,b));
33 obj = performProduct();
34 System.out.println("The product is "+obj.performCalculation(a,b));
35 obj = performDivision();
36 System.out.println("The division value is
"+obj.performCalculation(a,b));
37 }
38 }

You might also like