Name: Mohamad Fasil Ansaary M
Reg. No.: 19BCE1687
Course: CSE1007 Java Programming Lab
Faculty: Dr. Hema N
1.Define a class University that has 2 member variables name of the university and place.
Define a method display to print the university details. Construct an interface that method
called subject() which is implemented into a class called School. Given the name of the
university, display the details and the subjects offered by them.
Source Code:
import java.util.*;
interface subject
public void subjects();
class University
String name;
String loc;
University(String name,String loc)
this.name =name;
this.loc=loc;
void display()
{
System.out.println("\nUniversity Name: "+name);
System.out.println("Located at : "+loc);
public class schools extends University implements subject {
String [] sub;
schools(String name,String loc,String [] sub)
super(name,loc);
this.sub=new String[sub.length];
for(int i=0;i<sub.length;i++)
this.sub[i]=sub[i];
public void subjects()
System.out.print("\nSubjects offered at this University : ");
for(int i=0;i<sub.length;i++)
System.out.println(sub[i]);
public static void main(String[]args)
int n;
String name;
String loc;
Scanner s=new Scanner(System.in);
System.out.print("Enter the university Name : ");
name= s.nextLine();
System.out.print("Enter the location : ");
loc= s.nextLine();
System.out.print("Enter the no. of subjects offered by the University :
");
n=s.nextInt();
String sub[]=new String[n];
System.out.print("Enter the subjects offered by the University : ");
for(int i=0;i<n;i++)
sub[i]= s.nextLine();
schools ob=new schools(name,loc,sub);
ob.display();
ob.subjects();
Output:
2.Create 3 packages: student, academics, placement and non-academics (sub package of
academics) to read information and create a main package report to display required
information of the student.
Source Code:
package academics;
import java.util.Scanner;
public class academics {
Scanner s =new Scanner(System.in);
String[] sub=new String[5];
public void getinfo(){
for(int i=0;i<5;i++){
System.out.print("Enter marks for sub "+(i+1)+" :");
sub[i]=s.next();
}
}
public void readinfo(){
for(int i=0;i<5;i++){
System.out.print("\nMarks for sub "+(i+1)+" : "+sub[i]);
}
}
}
package academics.nonacademics;
import java.util.Scanner;
public class nonacademics {
Scanner s =new Scanner(System.in);
String[] ach=new String[3];
public void getach(){
System.out.print("Enter 5 non academic achievements :");
for(int i=0;i<3;i++){
ach[i]=s.next();
}
}
public void readach(){
System.out.print("\nNon academic achievements :");
for(int i=0;i<3;i++){
System.out.println("\n"+ach[i]);
}
}
}
package placements;
import java.util.Scanner;
public class placements {
Scanner s =new Scanner(System.in);
String plc;
public void getplc(){
System.out.println("Enter placed company:");
plc=s.next();
}
public void readplc(){
System.out.print("\nPlaced under: "+plc);
}
}
package student;
import academics.*;
import academics.nonacademics.*;
import placements.*;
import java.util.Scanner;
public class student {
Scanner s =new Scanner(System.in);
String name;
String reg;
academics ac=new academics();
nonacademics nac=new nonacademics();
placements pc=new placements();
public String getstu(){
System.out.print("Enter the name:");
name=s.next();
System.out.print("Enter the reg no:");
reg=s.next();
ac.getinfo();
nac.getach();
pc.getplc();
return reg;
}
public void readstu() {
System.out.print("\nName:" + name);
System.out.print("\nReg. no:" + reg);
ac.readinfo();
nac.readach();
pc.readplc();
}
}
package report;
import student.*;
import java.util.Scanner;
public class report {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int c;
int n;
System.out.print("Enter no of records to add:");
n = s.nextInt();
student[] st = new student[n];
String[] reg = new String[n];
while (true) {
System.out.println("Enter required choice:\n1.Add student info
\n2.Get student info");
c = s.nextInt();
if (c == 1) {
for (int i = 0; i < n; i++) {
st[i] = new student();
reg[i] = st[i].getstu();
System.out.print("Adding records...\n");
}
System.out.print("Records Added.\n");
continue;
} else {
String rec;
System.out.print("Enter reg no of student to search for:");
rec = s.next();
for (int i = 0; i < n; i++) {
if (rec.equals(reg[i])) {
st[i].readstu();
}
}
break;
}
}
}
}
Output: