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

CER3C2 Lab Assignment 05

The document contains multiple Java solutions demonstrating various programming concepts such as commission calculation, object-oriented principles with classes like Circle and Employee, and basic data handling with user input. Each solution includes a main method that interacts with the user, processes data, and outputs results. The document showcases a variety of functionalities including mathematical calculations, data encapsulation, and use of constructors.

Uploaded by

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

CER3C2 Lab Assignment 05

The document contains multiple Java solutions demonstrating various programming concepts such as commission calculation, object-oriented principles with classes like Circle and Employee, and basic data handling with user input. Each solution includes a main method that interacts with the user, processes data, and outputs results. The document showcases a variety of functionalities including mathematical calculations, data encapsulation, and use of constructors.

Uploaded by

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

SOLUTION 01

import java.util.Scanner;
class Commission{
private int sales;
Commission(int data){
sales = data;
}
public float commission(){
return .1f * sales;
}
}
class demo{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the sales: ");
int sales = sc.nextInt();
if(sales<0){
System.out.println("Invalid Input");
}
else{
Commission c = new Commission(sales);
float commission = c.commission();
System.out.println("Commission = "+commission);
}
}}

INPUT/OUTPUT
Enter the sales:
450000
Commission = 45000.0
SOLUTION 02
import java.util.Scanner;
class Point{
//Coordinates
int x;
int y;
Point(int a , int b){
x = a;
y = b;
}
}
class Circle{
int x;
int y;
Point p = new Point(4,5);
Circle(Point p){ //Copy Constructor
x = p.x;
y = p.y;
}

public void get Coordinates(){


System.out.println("The Coordinates of the circle are:\nx = "+x+"\ny = "+y);
}
public double areaOfCircle(int radius){
return Math.PI * Math.pow(radius , 2);
}
}
class demo{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the radius");
int radius = sc.nextInt();
Point p1 = new Point(2,4);
Circle c1 = new Circle(p1);
c1.getCoordinates();
double area = c1.areaOfCircle(radius);
System.out.println("Area = "+area);
}
}

INPUT/OUTPUT
Enter the radius
5
The Coordinates of the circle are:
x=2
y=4
Area = 78.53981633974483
SOLUTION 03
class Time{
private int sec;
private int min;
private int hour;
public Time(int sec1 , int min1 , int hour1){
sec = sec1;
min = min1;
hour = hour1;}
public void add(Time t1){
int seconds = sec + t1.sec;
int minutes = min + t1.min;
int hours = hour + t1.hour;
System.out.println("Seconds = "+seconds+"\nMinutes = "+ minutes+"\nHours =
"+hours);
}
}
public class demo {
public static void main(String[] args) {
Time t = new Time(2,4,6);
Time t1 = new Time(1,3,5);
t.add(t1);
}}

INPUT/OUTPUT
Seconds = 3
Mintes = 7
Hours = 11
SOLUTION 04
class Complex{
private int real;
private int imaginary;

Complex(int a , int b){


real = a;
imaginary = b;
}
public void add(Complex c1){
int r = real + c1.real;
int i = imaginary + c1.imaginary;
System.out.println(“Sum is :” + r + “+” + i + “i”);
}
}
class demo{
public static void main(String[] args) {
Complex c = new Complex(2, 3);
Complex c1 = new Complex(4, 5);
c.add(c1);
}
}

INPUT/OUTPUT
Sum is : 6 + 8i
SOLUTION 05

class Reverse {
int num;

Reverse(int a){
num = a;
}

public int reverse(){


int rev = 0;
int digit = 0;
while(num >0 ){
digit = num%10;
rev = rev*10+digit;
num/=10;
}
return rev;
}}

public class demo{


public static void main(String[] args) {

Reverse r = new Reverse(143);


int reverse = r.reverse();
System.out.println("Reverse is = "+reverse);
}
}

INPUT/OUTPUT
Reverse is = 341
SOLUTION 06
import java.util.Scanner;

public class Student {


String name;
int roll_no, sub1, sub2;
Scanner S = new Scanner(System.in);

void Input() {
System.out.println("Enter the name of the student");
name = S.nextLine();

System.out.println("Enter the roll number and marks of Sub1 and Sub2");


roll_no = S.nextInt();
sub1 = S.nextInt();
sub2 = S.nextInt();
}

void Display() {
System.out.println("Name : " + name);
System.out.println("Roll Number : " + roll_no);
System.out.println("Marks in Sub1 and Sub2 respectively : " + sub1 + " " + sub2);
System.out.println("Total marks are : " + (sub1 + sub2));
System.out.println("Percentage : " + (sub1 + sub2) / 2);
}
}

class Driver {
public static void main(String[] args) {
Student S1 = new Student();
S1.Input();
S1.Display();
}
}

INPUT/OUTPUT
Enter the name of the student
Divyansh
Enter the roll number and marks of Sub1 and Sub2
30 84 68
Name : Divyansh
Roll Number : 30
Marks in Sub1 and Sub2 respectively : 84 68
Total marks are : 152
Percentage : 76
SOLUTION 07
import java.util.Scanner;

public class Employee {


int emp_id;
double basic_salary, gross_salary;
String emp_name;

Scanner S = new Scanner(System.in);

void Input() {
System.out.println("Enter the Employee ID");
emp_id = S.nextInt();
System.out.println("Enter the Employee Name");
emp_name = S.next();
System.out.println("Enter the Basic Salary");
basic_salary = S.nextInt();
}

void Display() {
gross_salary = basic_salary + 0.05 * basic_salary;
System.out.println("The gross salary is : " + gross_salary);
}
}

class Driver {
public static void main(String[] args) {
Employee E1 = new Employee();
E1.Input();
E1.Display();
}
}

INPUT/OUTPUT
Enter the Employee ID
20
Enter the Employee Name
Anando
Enter the Basic Salary
50000
The gross salary is : 52500.0
SOLUTION 08
import java.util.Scanner;

class Item {
int code, price;

Item(int c, int p) {
code = c;
price = p;
}

public static void main(String[] args) {


Item[] I = new Item[5];
int total_price = 0;
int a,b;
Scanner S = new Scanner(System.in);
for (int i = 0; i < 5; i++) {
System.out.println("Enter the code for Item " + (i + 1));
a = S.nextInt();
System.out.println("Enter the price for Item " + (i + 1));
b = S.nextInt();
I[i]= new Item(a,b);
}

System.out.println("Item Code Item Price");


System.out.println("--------- ----------");

for (int i = 0; i < 5; i++) {


System.out.println(I[i].code + " " + I[i].price);
total_price = total_price + I[i].price;
}
System.out.println("The total price is : "+ total_price);
}
}

INPUT/OUTPUT
Enter the code for Item 1
101
Enter the price for Item 1
34
Enter the code for Item 2
102
Enter the price for Item 2
45
Enter the code for Item 3
103
Enter the price for Item 3
99
Enter the code for Item 4
104
Enter the price for Item 4
151
Enter the code for Item 5
105
Enter the price for Item 5
121
Item Code Item Price
--------- ----------
101 34
102 45
103 99
104 151
105 121
The total price is : 450
SOLUTION 09
import java.util.Scanner;

class Tender {
String company_name;
int cost;

Tender(String name, int c) {


company_name = name;
cost = c;
}

public static void main(String[] args) {


Tender[] T = new Tender[5];
Scanner S = new Scanner(System.in);
String a;
int b;
for (int i = 0; i < 5; i++) {
System.out.println("Enter the name of company " + (i + 1));
a = S.next();
System.out.println("Enter the cost for company " + (i + 1));
b = S.nextInt();
T[i] = new Tender(a, b);
}
int min_cost = T[0].cost;
int index = 0;
for (int i = 0; i < 5; i++) {
if (T[i].cost < min_cost) {
min_cost = T[i].cost;
index = i;
}
}
System.out.println("The minimum cost is for the company : " +
T[index].company_name);
}
}

INPUT/OUTPUT
Enter the name of company 1
Nightloft
Enter the cost for company 1
30000
Enter the name of company 2
SilverSure
Enter the cost for company 2
20000
Enter the name of company 3
HellBoy
Enter the cost for company 3
15000
Enter the name of company 4
Ryuga
Enter the cost for company 4
50000
Enter the name of company 5
AweMonk
Enter the cost for company 5
70000
The minimum cost is for the company : HellBoy
SOLUTION 10
import java.util.Scanner;

class Circle {
private double radius;
private String colour;

Circle() {
radius = 1.0;
colour = "red";
}

Circle(double r) {
radius = r;
colour = "red";
}

public double GetRadius() {


return radius;
}

public double GetArea() {


return 3.14 * radius * radius;
}

public static void main(String [] args)


{
Circle C1 = new Circle();
Circle C2 = new Circle(3);

System.out.println("C1 has radius : " + C1.GetRadius() );


System.out.println(" Area of C1 : " + C1.GetArea());
System.out.println("C2 has radius : " + C2.GetRadius() + " Area of C2 : " +
C2.GetArea());
System.out.println(" Area of C2 : " + C2.GetArea());
}
}

INPUT/OUTPUT
C1 has radius : 1.0
Area of C1 : 3.14
C2 has radius : 3.0 Area of C2 : 28.259999999999998
Area of C2 : 28.259999999999998
SOLUTION 11

import java.util.Date;

class Account {
private int ID;
private double Balance;
static private double annualInterestRate;
private Date dateCreated;
Account(){
ID=0;
Balance=0;
annualInterestRate=0;
dateCreated=new Date();

}
Account(int id,double bal){
ID=id;
Balance=bal;
annualInterestRate=0;
dateCreated=new Date();
}
public int getID() {
return ID;
}
public void setID(int iD) {
ID = iD;
}
public double getBalance() {
return Balance;
}
public void setBalance(double balance) {
Balance = balance;
}
public static double getAnnualInterestRate() {
return annualInterestRate;
}
public static void setAnnualInterestRate(double annualInterestRate) {
Account.annualInterestRate = annualInterestRate;
}
public Date getDateCreated() {
return dateCreated;
}
public static double getMonthlyInterestRate(){
return ((getAnnualInterestRate()/(100*12))*100);
}
public double getMonthlyInterest(){
return (Balance*(getMonthlyInterestRate()/100));
}
public void withdraw(int amount){
Balance-=amount;
System.out.println("withdrawed "+amount);
System.out.println("balance= " +getBalance());
}
public void deposit(int amount){
Balance+=amount;
System.out.println("deposited "+amount);
System.out.println("balance= " +getBalance());
}

}
public class demo{
public static void main(String[] args) {
Account firstaccount=new Account();
Account Secondaccount=new Account(101, 1000);
System.out.println("first account balance "+firstaccount.getBalance());
System.out.println("second account balance "+Secondaccount.getBalance());
firstaccount.deposit(100);
Secondaccount.withdraw(100);

}
}

INPUT/OUTPUT

First account balance 0.0


Second account balance 1000.0
Deposited 100
Balance= 100.0
Withdrew = 100
Balance= 900.0
SOLUTION 12
import java.util.Scanner;

public class test {

public static void main(String[] args) {


Scanner s = new Scanner(System.in);
System.out.println("Enter amount and interest rate");
double amount=s.nextDouble();
double interest=s.nextDouble();
System.out.println("Years Future Values" );
for(int i=1;i<=30;i++){

System.out.println(i+" "+(amount*Math.pow(1+(interest/100), i)));


}
}

INPUT/OUTPUT

Years Future values


1 1090.0
2 1188.1000000000001
3 1295.0290000000002
4 1411.5816100000004
5 1538.6239549000004
6 1677.1001108410007
7 1828.039120816691
8 1992.5626416901935
9 2171.893279442311
10 2367.363674592119
11 2580.42640530541
12 2812.664781782897
13 3065.8046121433576
14 3341.7270272362603
15 3642.482459687524
16 3970.3058810594016
17 4327.633410354748
18 4717.120417286676
19 5141.661254842477
20 5604.4107677783
21 6108.807736878347
22 6658.6004331974
23 7257.874472185165
24 7911.083174681831
25 8623.080660403197
26 9399.157919839485
27 10245.08213262504
28 11167.139524561295
29 12172.182081771813
30 13267.678469131277
SOLUTION 13

public double computeSalesCommission(double salesAmount, double


commissionRate);
public void printCalendar(int month, int year);
public double computeSquareRoot(double number);
public boolean isEven(int number);
public void printMessage(String message, int times);
public double computeMonthlyPayment(double loanAmount, int numberOfYears,
double annualInterestRate);
SOLUTION 14
class staticExample{
static int x=10;
public static void staticMethod(){
System.out.println("Static method was called");
}
public void print(){
System.out.println("non-static method was called");
}
}
public class static demo {
public static void main(String[] args) {
staticExample.staticMethod();
staticExample s=new staticExample();
s.print();
System.out.println("printing static variable : "+staticExample.x);

}
}

INPUT/OUTPUT

Static method was called


non-static method was called
printing static variable : 10
SOLUTION 15
abstract class Shape{
abstract public double calculateArea();
abstract public double calculatePerimeter();
}
class Rectangle extends Shape{

private double length;


private double width;
public Rectangle(double length, double width) {
this.length = length;
this.width = width;
}
public Rectangle(){
length=width=0;
}
@Override
public double calculateArea() {

return length*width;
}
@Override
public double calculatePerimeter() {
return 2*(length+width);
}

}
class Triangle extends Shape{
private double s1;
private double s2;
private double s3;
public Triangle(double s1, double s2, double s3) {
this.s1 = s1;
this.s2 = s2;
this.s3 = s3;
}
public Triangle(){
s1=s2=s3=0;
}
@Override
public double calculateArea() {
double s=calculatePerimeter()/2;
return Math.sqrt(s*(s-s1)*(s-s2)*(s-s3));
}
@Override
public double calculatePerimeter() {

return (s1+s2+s3);
}
}
public class abstract demo {
public static void main(String[] args) {
Rectangle rectangle=new Rectangle(5,10);
System.out.println("Area of Rectangle "+rectangle.calculateArea());
System.out.println("Perimeter of Rectangle "+rectangle.calculatePerimeter());
Triangle triangle=new Triangle(2,2,2);
System.out.println("Area of Triangle "+triangle.calculateArea());
System.out.println("Perimeter of Triangle "+triangle.calculatePerimeter());
}
}

INPUT/OUTPUT
Area of Rectangle 50.0
Perimeter of Rectangle 30.0
Area of Triangle 1.7320508075688772
Perimeter of Triangle 6.
SOLUTION 16
interface vehicle{
void start();
void stop();
}
class Car implements vehicle{

@Override
public void start() {
System.out.println("Car has started");

@Override
public void stop() {
System.out.println("Car has stopped");

}
class MotorCycle implements vehicle{

@Override
public void start() {
System.out.println("MotorCycle has started ");

@Override
public void stop() {
System.out.println("MotorCycle has stopped");

}
public class interface demo {
public static void main(String[] args) {
Car c=new Car();
c.start();
c.stop();
MotorCycle m=new MotorCycle();
m.start();
m.stop();

}
}

INPUT/OUTPUT

Car has started


Car has stopped
MotorCycle has started
MotorCycle has stopped
SOLUTION 17
import java.util.Scanner;

class ThreeDObject{
public double wholeSurfaceArea(){
return 0;
}
public double volume(){
return 0;
}

}
class Box extends ThreeDObject{
private double length;
private double width;
private double height;

public Box(double length, double width, double height) {


this.length = length;
this.width = width;
this.height = height;
}
@Override
public double volume() {
return length*width*height;
}
@Override
public double wholeSurfaceArea() {
return (2*(length*width+length*height+width*height));
}

}
class Cube extends ThreeDObject{
private double sideLength;
public Cube(double sideLength) {
this.sideLength = sideLength;
}

@Override
public double volume() {
return sideLength*sideLength*sideLength;
}

@Override
public double wholeSurfaceArea() {
return 6*sideLength*sideLength;
}

}
class Cylinder extends ThreeDObject{
private double radius;
private double height;
public Cylinder(double radius, double height) {
this.radius = radius;
this.height = height;
}
@Override
public double volume() {
return 3.14*radius*radius*height;
}
@Override
public double wholeSurfaceArea() {
return 2*3.14*radius*(height+radius);
}

}
class Cone extends ThreeDObject{
private double height;
private double radius;
public Cone(double height, double radius) {
this.height = height;
this.radius = radius;
}
@Override
public double volume() {
return (3.14*radius*radius*height)/3;
}
@Override
public double wholeSurfaceArea() {
double slant=Math.sqrt(radius*radius+height*height);
return 3.14*radius*(radius+slant);
}
}
public class threeDobjectdemo {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
System.out.println("Enter length, width and height of box");
double length=s.nextDouble();
double width=s.nextDouble();
double height=s.nextDouble();
Box b=new Box(length, width, height);
System.out.println("volume of box is "+b.volume());
System.out.println("whole surface area of box is "+b.wholeSurfaceArea());
System.out.println("Enter Side Length of Cube");
length=s.nextDouble();
Cube c=new Cube(length);
System.out.println("Volume of Cube is "+c.volume());
System.out.println("Whole surface area of cube is "+c.wholeSurfaceArea());
System.out.println("Enter height and radius of cylinder");
height=s.nextDouble();
double radius=s.nextDouble();
Cylinder cylinder=new Cylinder(radius,height );
System.out.println("Volume of Cylinder is "+cylinder.volume());
System.out.println("Whole Surface Area of Cylinder is "+
cylinder.wholeSurfaceArea());
System.out.println("Enter height and radius of cone ");
height=s.nextDouble();
radius=s.nextDouble();
Cone cone=new Cone(height, radius);
System.out.println("Volume of cone is "+cone.volume());
System.out.println("Whole Surface area of cone is "+cone.wholeSurfaceArea());

}
}

INPUT/OUTPUT

Enter length, width and height of box


222
volume of box is 8.0
whole surface area of box is 24.0
Enter Side Length of Cube
2
Volume of Cube is 8.0
Whole surface area of cube is 24.0
Enter height and radius of cylinder
25
Volume of Cylinder is 157.0
Whole Surface Area of Cylinder is 219.8
Enter height and radius of cone
25
Volume of cone is 52.333333333333336
Whole Surface area of cone is 163.04708747201173
SOLUTION 18
class Vehicle{
protected String regnNumber;
protected int speed;
protected String color;
protected String OwnerName;
public void showData(){
System.out.println("This is a Vehicle class");
}
public Vehicle(String regnNumber, int speed, String color, String ownerName) {
this.regnNumber = regnNumber;
this.speed = speed;
this.color = color;
OwnerName = ownerName;
}
}
class Bus extends Vehicle{
private int routeNumber;

public Bus(String regnNumber, int speed, String color, String ownerName, int
routeNumber) {
super(regnNumber, speed, color, ownerName);
this.routeNumber = routeNumber;
}

@Override
public void showData() {
System.out.println("Registration Number: "+ regnNumber);
System.out.println("Speed: "+speed);
System.out.println("Color: "+color);
System.out.println("Owner Name: "+OwnerName );
System.out.println("Route Number: "+ routeNumber);
super.showData();
}
}
class Car extends Vehicle{
private String manufacturerName;

public Car(String regnNumber, int speed, String color, String ownerName, String
manufacturerName) {
super(regnNumber, speed, color, ownerName);
this.manufacturerName = manufacturerName;
}

@Override
public void showData() {
System.out.println("Registration Number: "+ regnNumber);
System.out.println("Speed: "+speed);
System.out.println("Color: "+color);
System.out.println("Owner Name: "+OwnerName );
System.out.println("Manufacturer Name: "+ manufacturerName);
super.showData();
}
}
public class vehicledemo {
public static void main(String[] args) {
Car car=new Car("1120", 100, "Black","Atharva Aher", "Toyota");
car.showData();
Bus bus=new Bus("1130", 50, "Red", "Anando Sharma", 10);
bus.showData();

}
}

INPUT/OUTPUT

Registration Number: 1120


Speed: 100
Color: Black
Owner Name: Atharva Aher
Manufacturer Name: Toyota
This is a Vehicle class
Registration Number: 1130
Speed: 50
Color: Red
Owner Name: Anando Sharma
Route Number: 10
This is a Vehicle class
SOLUTION 19
abstract class Asset {

static int descriptor = 34;

static double date = 22.11;

static int current_value = 3400;

static void displayDetails(){

System.out.println(descriptor);

System.out.println(date);

System.out.println(current_value);

abstract class Stock extends Asset{

static int num_shares = 21;

static int share_price = 4500;

static int asset = 543;

static void displayDetails(){

System.out.println(num_shares);

System.out.println(share_price);

System.out.println(asset);

}
}
abstract class Bond extends Asset{

static int interest_rate = 3;

static int asset = 344;

static void displayDetails(){

System.out.println(interest_rate);

System.out.println(asset);

abstract class Savings extends Asset{

static int interest_rate = 5;

static int asset = 5678;

static void displayDetails(){

System.out.println(interest_rate);

System.out.println(asset);

class MIN{

public static void main(String arr[]){


Stock.displayDetails();

Savings.displayDetails();

Bond.displayDetails();

INPUT/OUTPUT

21
4500
543
5
5678
3
344
SOLUTION 20
import java.util.Scanner;

interface Department{
String DeptName="Computer Science";
String DeptHead="Atharva Aher";
void printAttributes();

}
class hostel {
protected String hostelName;
protected int hostelLocation;
private int numberOfRooms;

public hostel(String hostelName, int hostelLocation, int numberOfRooms) {


this.hostelName = hostelName;
this.hostelLocation = hostelLocation;
this.numberOfRooms = numberOfRooms;
}
public String getHostelName() {
return hostelName;
}
public void setHostelName(String hostelName) {
this.hostelName = hostelName;
}
public int getHostelLocation() {
return hostelLocation;
}
public void setHostelLocation(int hostelLocation) {
this.hostelLocation = hostelLocation;
}
public int getNumberOfRooms() {
return numberOfRooms;
}
public void setNumberOfRooms(int numberOfRooms) {
this.numberOfRooms = numberOfRooms;
}

}
class Student extends hostel implements Department{
private String studentName;
private int regdNo;
private String electiveSubject;
private int avgMarks;

public Student(String hostelName, int hostelLocation, int numberOfRooms, String


studentName, int regdNo,
String electiveSubject, int avgMarks) {
super(hostelName, hostelLocation, numberOfRooms);
this.studentName = studentName;
this.regdNo = regdNo;
this.electiveSubject = electiveSubject;
this.avgMarks = avgMarks;
}
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}
public int getRegdNo() {
return regdNo;
}
public void setRegdNo(int regdNo) {
this.regdNo = regdNo;
}
public String getElectiveSubject() {
return electiveSubject;
}
public void setElectiveSubject(String electiveSubject) {
this.electiveSubject = electiveSubject;
}
public int getAvgMarks() {
return avgMarks;
}
public void setAvgMarks(int avgMarks) {
this.avgMarks = avgMarks;
}
@Override
public void printAttributes() {
// TODO Auto-generated method stub
System.out.println("Department Name: "+DeptName);
System.out.println("Department Head: "+DeptHead);
}

}
public class Driver {
static Student[] arr=new Student[100];
static int ptr=0;
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int choice;
do{
System.out.println("1.Admit new student");
System.out.println("2.Migrate a student");
System.out.println("3.Display details of a student");
System.out.println("4.Exit");
choice=s.nextInt();
switch(choice){
case 1:
String name,elective;
int regdNo,marks;
System.out.println("Enter student name");
name=s.nextLine();
s.next();
System.out.println("Enter elective subject");
elective=s.nextLine();
s.next();
System.out.println("Enter registration number");
regdNo=s.nextInt();

System.out.println("Enter avg marks");


marks=s.nextInt();
Student student=new Student("DAVV hostel", ptr+1, 100, name, regdNo,
elective, marks);
Driver.arr[ptr++]=student;
break;
case 2:
System.out.println("Enter registration number student you want to
migrate");
int a1=s.nextInt();
System.out.println("Enter new location of student");
int b1=s.nextInt();
for (int i=0;i<ptr;i++) {
Student studentobj=Driver.arr[i];
if(studentobj.getRegdNo()==a1){
studentobj.setHostelLocation(b1);
}
}
System.out.println("operation successful");
break;
case 3:
System.out.println("Enter registration number of student");
int registrationNo=s.nextInt();
for(Student studentobj:Driver.arr){
if(registrationNo==studentobj.getRegdNo()){
studentobj.printAttributes();
System.out.println("Student Name: "+studentobj.getStudentName());
System.out.println("Student Elective Subject:
"+studentobj.getElectiveSubject());
System.out.println("Student avg marks: "+studentobj.getAvgMarks());
System.out.println("Student Hostel Nam:
"+studentobj.getHostelName());
System.out.println("student Hostel Location:
"+studentobj.hostelLocation);
break;
}

}
break;
case 4:
System.out.println("Exiting");
break;
default:
System.out.println("invalid");
break;

}while(choice!=4);

}
}

INPUT/OUTPUT

PS D:\code\java> cd "d:\code\java\" ; if ($?) { javac Driver.java } ; if ($?) { java Driver }


1.Admit new student
2.Migrate a student
3.Display details of a student
4.Exit
1
Enter student name
Atharva Aher
Enter elective subject
Maths
Enter registration number
101
Enter avg marks
100
1.Admit new student
2.Migrate a student
3.Display details of a student
4.Exit
2
Enter registration number student you want to migrate
101
Enter new location of student
2
operation successful
1.Admit new student
2.Migrate a student
3.Display details of a student
4.Exit
3
Enter registration number of student
101
Department Name: Computer Science
Department Head: Atharva Aher
Student Name:
Student Elective Subject: Aher
Student avg marks: 100
Student Hostel Nam: DAVV hostel
student Hostel Location: 2
1.Admit new student
2.Migrate a student
3.Display details of a student
4.Exit
4
Exiting

You might also like