You are on page 1of 9

Assignnment

OOP

Areej Bashir (sp18-bse-060)


Raffy (Fa20-bse-109)
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package library;

import java.util.Scanner;

/**
*
* @author Raffay
*/
public class Library {
public String Name;
public int id;
public int shelfno;

Scanner sc = new Scanner(System.in);


public void Enter(){
System.out.println("Enter the name");
Name=sc.next();
System.out.println("Enter the id ");
id=sc.nextInt();
System.out.println("Enter the shelf number");
shelfno=sc.nextInt();
}
public void Display(){
System.out.println(Name);
System.out.println(id);
System.out.println(shelfno);
}
public void Search(){}
} // end of Library
class journal extends Library {

public String date_of_publication ;


public journal(String name,int id, int shelfno,String date_of_publication){

super.Name= name;
super.id= id;
super.shelfno= shelfno;
this.date_of_publication= date_of_publication;

} // end of journal
class book extends Library{
public int no_of_pages;

public book(String name,int id, int shelfno,int no_of_pages){

super.Name= name;
super.id= id;
super.shelfno= shelfno;
this.no_of_pages= no_of_pages;

} // end of book

MAIN CLASS
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package library;

import java.util.Scanner;

/**
*
* @author Raffay
*/

public class maintest {


public static void main(String [] arg){
int y=0;
book [] b = new book[5];
journal[] jobj= new journal[5];
String name;
int id;
int shelfno;

journal [] j = new journal[5];


String p= "librarian123";
String p1;
Scanner sc = new Scanner(System.in);
int x=0;
int bookentered=0;
while(x!=3){
System.out.println("1. librarain \n 2. User 3 for exit");
x=sc.nextInt();
if(x==1){
bookentered++;
System.out.println("Enter the pasword");
p1=sc.next();
if(p.equals(p1)){
System.out.println("Welcome");
System.out.println("what do you want to do ? \n 1. Enter books \n 2. enter journls \n 3. Display
book \n 4. Display journals");
y = sc.nextInt();
if(y==1){
for (int i =0;i<b.length;i++) {
System.out.println("Enter the name");
name=sc.next();
System.out.println("Enter the id ");
id=sc.nextInt();
System.out.println("Enter the shelf number");
shelfno=sc.nextInt();

b[i] = new book(name,id,shelfno,200);


System.out.println("\n");
}
}
if(y==2){

for (int i =0;i<b.length;i++) {


System.out.println("Enter the name");
name=sc.next();
System.out.println("Enter the id ");
id=sc.nextInt();
System.out.println("Enter the shelf number");
shelfno=sc.nextInt();

jobj[i] = new journal(name,id,shelfno,"25th 2005");


System.out.println("\n");
}
}
if(y==3){
System.out.println("BOOKS");
for(int i=0;i<b.length;i++){
System.out.println(b[i].Name+b[i].id+b[i].no_of_pages+b[i].shelfno);
}
System.out.println("Journals");
for(int i=0;i<jobj.length;i++){
System.out.println(jobj[i].Name+jobj[i].id+jobj[i].date_of_publication+jobj[i].shelfno);

}
}

}
else{ System.out.println("pasword Incorrect");
}

}
else if(x==2){
if(bookentered>0){
System.out.println("USER MODE\n 1 to search by id 2 to search by name");
int check = sc.nextInt();
if(check==1){
System.out.println("enter id to search for book");
int idsearch= sc.nextInt();
for(int i=0;i<b.length;i++){
if(idsearch==b[i].id){
System.out.println("Book found");
System.out.println(b[i].Name+b[i].id+b[i].no_of_pages+b[i].shelfno);
}
}
}
else if(check==2){
System.out.println("enter name to search for book");
String search= sc.next();
for(int i=0;i<b.length;i++){
if(search.equals(b[i].Name)){
System.out.println("Book found");
System.out.println(b[i].Name+b[i].id+b[i].no_of_pages+b[i].shelfno);
}
}
}}
else
System.out.println("book not entered");
}
}
}
}

Question 2
Main class
package com.company;

import com.fac.define.faculity;
import com.name.std.std;

public class Main {

public static void main(String[] args) {


std[] arr;
arr = new std[2];
arr[0] = new std("Sp18-bse-060", "Areej Bashir", 3.0F);
arr[1] = new std("Sp18-bse-023", "Ahmed", 4.0F);

faculity[] arr2;
arr2 = new faculity[3];
arr2[0] = new faculity("emp001", "Areej Bashir", 250000);
arr2[1] = new faculity("emp23", "Perviz", 2500000);
arr2[1] = new faculity("emp23", "Ali khan", 25000);
}

}
package faculity

package com.fac.define;

public class faculity {


private final String emp_id;
private final String emp_name;
public float salary;

// Student class constructor


public faculity(String id, String name, float gpa)
{
this.emp_id = id;
this.emp_name = name;
this.salary=gpa;
}

// display() method to display


// the student data
public void display()
{
System.out.println("Employer id is: " + emp_id + " "
+ "and Employee name is: "
+ emp_name +" " + "and Employee Salary is:" + salary);
System.out.println();
}
}

package Student
package com.name.std;

public class std {


public float gpa;
public String id,name;

// Student class constructor


public std(String id, String name, float gpa)
{
this.id = id;
this.name = name;
this.gpa=gpa;
}

// display() method to display


// the student data
public void display()
{
System.out.println("Student id is: " + id + " "
+ "and Student name is: "
+ name +" " +"and Student gpa is:" + gpa);
System.out.println();
}
}

You might also like