Roshan Ass 6
Roshan Ass 6
Roshan Ass 6
Name:Ankita Tiwari
Regs.no:2021ugcs062
1.
interface Department {
void getDeptName();
void getDeptHead();
}
class Hostel {
protected String hname, hlocaƟon;
int noofroom;
void getHostelName() {
System.out.println("Name Of the Hostel: " + hname);
}
void getHostelLocaƟon() {
System.out.println("Hostel LocaƟon: " + hlocaƟon);
}
void getNoOfRoom() {
System.out.println("Total Room: " + noofroom);
}
}
class Student extends Hostel implements Department {
private String sname, regno, elesub, deptName, deptHead;
private int avgMarks;
void getStudentName() {
System.out.println("Student: " + sname);
}
String getStudentRegNo() {
return regno;
}
void getElecƟveSubject() {
System.out.println("ElecƟve Subject: " + elesub);
}
void getAvgMarks() {
System.out.println("Average Marks: " + avgMarks);
}
public void getDeptName() {
System.out.println("Department Name: " + deptName);
}
public void getDeptHead() {
System.out.println("Department Head: " + deptHead);
}
void addStudent() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter Student name: ");
sname = sc.nextLine();
System.out.print("Enter RegistraƟon Number: ");
regno = sc.nextLine();
System.out.print("Enter ElecƟve Subject: ");
elesub = sc.nextLine();
System.out.print("Enter Hostel Name: ");
hname = sc.nextLine();
System.out.print("Enter Hostel LocaƟon: ");
hlocaƟon = sc.nextLine();
System.out.print("Enter Department Name: ");
deptName = sc.nextLine();
System.out.print("Enter Department Head: ");
deptHead = sc.nextLine();
System.out.print("Enter No of Room: ");
noofroom = sc.nextInt();
System.out.print("Enter Average Marks: ");
avgMarks = sc.nextInt();
}
void migrate() {
Scanner sc = new Scanner(System.in);
System.out.print("Enter new Department Name: ");
deptName = sc.nextLine();
System.out.print("Enter new Department Head: ");
deptHead = sc.nextLine();
}
void display() {
getStudentName();
System.out.println("Student RegistraƟon No is: " +
getStudentRegNo());
getElecƟveSubject();
getAvgMarks();
getDeptName();
getDeptHead();
}
}
public class Main {
public sta c void main(String[] args) {
Scanner sc = new Scanner(System.in);
Student[] students = new Student[100];
int studentCount = 0;
while (true) {
System.out.println("\n1. Admit a student");
System.out.println("2. Migrate a student");
System.out.println("3. Display student informaƟon");
System.out.println("4. Exit");
System.out.print("Enter Your Choice: ");
int choice = sc.nextInt();
switch (choice) {
case 1:
students[studentCount] = new Student();
students[studentCount].addStudent();
studentCount++;
break;
case 2:
System.out.print("Enter RegistraƟon no: ");
String regNo = sc.next();
boolean found = false;
for (int i = 0; i < studentCount; i++) {
if (students[i].getStudentRegNo().equals(regNo)) {
students[i].migrate();
found = true;
break;
}
}
if (!found) {
System.out.println("Student Not Found");
}
break;
case 3:
System.out.print("Enter RegistraƟon no: ");
regNo = sc.next();
found = false;
for (int i = 0; i < studentCount; i++) {
if (students[i].getStudentRegNo().equals(regNo)) {
students[i].display();
found = true;
break;
}
}
if (!found) {
System.out.println("Student Not Found");
}
break;
case 4:
System.out.println("ExiƟng program...");
sc.close();
System.out.println("\nFor VerificaƟon\nName: Roshan
Kumar\nRegno 2021UGCS075\n");
System.exit(0);
break;
default:
System.out.println("Invalid Choice");
}
}
}
}
}
}
3.
interface Exam {
void Percent_call();
}
class Student {
String name;
int roll_no;
int marks1,marks2;
Student(String name,int roll_no,int marks1,int marks2 ) {
this.name=name;
this.roll_no=roll_no;
this.marks1=marks1;
this.marks2=marks2;
}
void show() {
System.out.println("Student Name: "+ name);
System.out.println("Student roll: "+ roll_no);
System.out.println("Marks1: "+ marks1);
System.out.println("Marks2: "+ marks2);
}
}
class Result extends Student implements Exam {
Double per;
}
}
4.
import java.u l.ArrayList;
interface Stack {
void push(int item);
int pop();
boolean isEmpty();
boolean isFull();
}
public DynamicArrayStack() {
stackList = new ArrayList<>();
}
fixedStack.push(1);
fixedStack.push(2);
fixedStack.push(3);
dynamicStack.push(10);
dynamicStack.push(20);
dynamicStack.push(30);
5.
package MCA;
import MCA.Student;
6.a
// In Server.java
package mygame.server;
public class Server {
// class implementa on
}
// In U li es.java
package mygame.shared;
public class U li es {
// class implementa on
}
// In Client.java
package mygame.client;
7.
package pk1;
package pk1;
class Prot {
protected void display() {
System.out.println("Protected Access Class from pk1");
}
}
package pk1;
class Def {
void display() {
System.out.println("Default (Package-Private) Access Class from
pk1");
}
}
package pk2;
import pk1.Prot;
package pk2;
import pk1.Def;
import pk1.Pub;
import pk1.Prot;
import pk1.Def;
import pk2.ProtInh;
import pk2.DefInh;