Professional Documents
Culture Documents
CS13201
CS13201
Complete this page very clearly and follow all the Instructions:
Registration Number:……20194041………..
10
Marks Obtained
Maximum Marks
INVIGILATOR'S DECLARATION
I have carefully checked all the entries made by the student
and found them correct.
Motilal Nehru National Institute of Technology Allahabad,
Prayagraj – 211004, UP, INDIA
READ ME:
Introduction:
Problem statement : To construct the class hierarchy of a college system as specified in the question.
FEATURES : It gives a beautiful explaination of the main features of object oriented programming
like polymorphism and inheritance.
Tech stack used : java programming language . the compilation of the program is done by the
javac compiler which is a component of java development kit(jdk). And after the compilation the
javac generates the byte code of the output which is in turn executed by the java virtual machine
which generates the ouput
Output:
Motilal Nehru National Institute of Technology Allahabad,
Prayagraj – 211004, UP, INDIA
import java.util.ArrayList;
import java.util.Scanner;
class Myfile{
public static void main(String[] args) ///main function
{
dept.setdeptid(deptId);
clg.setcollegeid(collegeId);
course.setCourseid(courseId);
s.setstudentid(sId);
faculty.setfacultyid(facultyId);
subject.setsubjectId(subjectId);
System.out.println("Department Id is "+dept.getdeptid());
System.out.println("College Id is "+clg.getcollegeid());
System.out.println("Course Id is "+course.getcourseid());
System.out.println("Student Id is "+s.getstudentid());
System.out.println("Faculty Id is "+faculty.getfacultyid());
System.out.println("Subject Id is "+subject.getsubjectId());
}
}
}
class Course{
private int courseID;
private String courseName;
private int numStudent;
Student studd;
Course()
{
}
Course(int courseID,String courseName,int numStudent,Student studd)
{
this.courseID=courseID;
this.courseName=courseName;
this.numStudent=numStudent;
this.studd=studd;
}
protected void setCourseid(int courseID)
{
this.courseID=courseID;
}
protected int getcourseid()
{
return this.courseID;
}
protected void setcoursename(String name)
Motilal Nehru National Institute of Technology Allahabad,
Prayagraj – 211004, UP, INDIA
{
this.courseName=name;
}
protected String getcoursename()
{
return this.courseName;
}
protected void setno(int numStudent)
{
this.numStudent=numStudent;
}
protected int getno()
{
return this.numStudent;
}
public void enrollStudents()
{
System.out.println("this method is used for enrolling the students");
}
}
class College{
private int collegeID;
private String collegeName;
Department dept;
College()
{
}
College(int collegeID,String collegeName,Department dept)
{
this.collegeID=collegeID;
this.collegeName=collegeName;
this.dept=dept;
}
protected void setcollegeid(int collegeID)
{
this.collegeID=collegeID;
}
protected int getcollegeid()
{
return this.collegeID;
}
protected void setcollegename(String collegeName)
{
this.collegeName=collegeName;
}
protected String getcollegename()
{
return this.collegeName;
}
public void hireEmployee()
{
System.out.println("This method of the base class is used for hiring the employee");
}
Motilal Nehru National Institute of Technology Allahabad,
Prayagraj – 211004, UP, INDIA
}
class Department{
private int deptID;
private String deptName;
Course c;
Faculty fac;
Student students;
Department()
{
}
Department(int deptID,String deptName, Course c, Faculty fac,Student students)
{
this.deptID=deptID;
this.deptName=deptName;
this.c=c;
this.fac=fac;
this.students=students;
}
protected void setdeptid(int deptID)
{
this.deptID=deptID;
}
protected int getdeptid()
{
return this.deptID;
}
protected void setdeptname(String deptName)
{
this.deptName=deptName;
}
protected String getdeptname()
{
return this.deptName;
}
public void admitStudent()
{
System.out.println("this method is used for conducting the admission process of the student");
}
}
class Student{
}
Student(int sID,String sName)
{
this.sID=sID;
this.sName=sName;
}
protected void setstudentid(int sID)
{
Motilal Nehru National Institute of Technology Allahabad,
Prayagraj – 211004, UP, INDIA
this.sID=sID;
}
protected int getstudentid()
{
return this.sID;
}
protected void setstudentname(String sName)
{
this.sName=sName;
}
protected String getstudentname()
{
return this.sName;
}
public void studySubject()
{
System.out.println("this method is used to record the subject that particular student applied for");
}
class Faculty
{
private int facultyID;
private String facultyName;
private String facultyEmail;
Faculty()
{
}
Faculty(int facultyID,String facultyName,String facultyEmail)
{
this.facultyID=facultyID;
this.facultyName=facultyName;
this.facultyEmail=facultyEmail;
}
protected void setfacultyid(int facultyID)
{
this.facultyID=facultyID;
}
protected int getfacultyid()
{
return this.facultyID;
}
protected void setfacname(String name)
{
this.facultyName=name;
}
protected String getfacname()
{
return this.facultyName;
}
protected void setfacemail(String email)
{
this.facultyEmail=email;
Motilal Nehru National Institute of Technology Allahabad,
Prayagraj – 211004, UP, INDIA
}
protected String getfacemail()
{
return this.facultyEmail;
}
READ ME:
Mytictactoe game:
Tech stack:
Java , netbeans ide , jdk , and concept of multithreading ‘
/*
* To change this license header, choose License Headers in Project
Properties.
Motilal Nehru National Institute of Technology Allahabad,
Prayagraj – 211004, UP, INDIA
/**
*
* @author Khushi Agarwal
*/
public class PlayClient { // client side apllication
public static void main( String args[] )
{
TicTacToeClient application; // declare client application
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE
);
}
}
2. Client side:
/*
* 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 tictactoe;
Motilal Nehru National Institute of Technology Allahabad,
Prayagraj – 211004, UP, INDIA
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.net.Socket;
import java.net.InetAddress;
import java.io.IOException;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import java.util.Formatter;
import java.util.Scanner;
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
/**
*
* @author Khushi Agarwal
*/
idField.setEditable( false );
add( idField, BorderLayout.NORTH );
startClient();
} // end TicTacToeClient constructor
SwingUtilities.invokeLater(
new Runnable()
{
public void run()
{
// display player's mark
idField.setText( "You are player \"" + myMark + "\"" );
} // end method run
} // end anonymous inner class
); // end call to SwingUtilities.invokeLater
{
displayMessage( message + "\n" ); // display invalid move
myTurn = true; // still this client's turn
} // end else if
else if ( message.equals( "Opponent moved" ) )
{
int location = input.nextInt(); // get move location
input.nextLine(); // skip newline after int location
int row = location / 3; // calculate row
int column = location % 3; // calculate column
{
SwingUtilities.invokeLater(
new Runnable()
{
public void run()
{
squareToMark.setMark( mark ); // set mark in square
} // end method run
} // end anonymous inner class
); // end call to SwingUtilities.invokeLater
} // end method setMark
{
mark = squareMark; // set mark for this square
location = squareLocation; // set location of this square
addMouseListener(
new MouseAdapter()
{
public void mouseReleased( MouseEvent e )
{
setCurrentSquare( Square.this ); // set current square
// draw Square
public void paintComponent( Graphics g )
{
super .paintComponent( g );
/*
* 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 tictactoe;
import java.awt.BorderLayout;
import java.net.ServerSocket;
import java.net.Socket;
import java.io.IOException;
import java.util.Formatter;
import java.util.Scanner;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.Condition;
Motilal Nehru National Institute of Technology Allahabad,
Prayagraj – 211004, UP, INDIA
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
/**
*
* @author Khushi Agarwal
*/
public class Tictactoe extends JFrame {
try
{
server = new ServerSocket( 12345, 2 ); // set up ServerSocket
} // end try
catch ( IOException ioException )
{
ioException.printStackTrace();
System.exit( 1 );
} // end catch
try
{
players[ PLAYER_X ].setSuspended( false ); // resume player X
otherPlayerConnected.signal(); // wake up player X's thread
} // end try
finally
{
gameLock.unlock(); // unlock game after signalling player X
} // end finally
} // end method execute
{
// while not current player, must wait for turn
while ( player != currentPlayer )
{
gameLock.lock(); // lock game to wait for other player to go
try
{
otherPlayerTurn.await(); // wait for player's turn
} // end try
catch ( InterruptedException exception )
{
exception.printStackTrace();
} // end catch
finally
{
gameLock.unlock(); // unlock game after waiting
} // end finally
} // end while
try
{
otherPlayerTurn.signal(); // signal other player to continue
} // end try
finally
{
Motilal Nehru National Institute of Technology Allahabad,
Prayagraj – 211004, UP, INDIA
{
playerNumber = number; // store this player's number
mark = MARKS[ playerNumber ]; // specify player's mark
connection = socket; // store socket for client
{
output.format( "%s\n%s", "Player X connected",
"Waiting for another player\n" );
output.flush(); // flush output
try
{
while( suspended )
{
otherPlayerConnected.await(); // wait for player O
} // end while
} // end try
catch ( InterruptedException exception )
{
exception.printStackTrace();
} // end catch
finally
{
gameLock.unlock(); // unlock game after second player
} // end finally
if ( input.hasNext() )
location = input.nextInt(); // get move location
Main function:
/*
* 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 tictactoe;
import javax.swing.JFrame;
/**
*
* @author Khushi Agarwal
*/
public class Play {
public static void main( String args[] )
{
Tictactoe application = new Tictactoe();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE
);
application.execute();
} // end main
}
// end class TicTacToeServerTest
OUTPUT:
Motilal Nehru National Institute of Technology Allahabad,
Prayagraj – 211004, UP, INDIA
Rough output:
Motilal Nehru National Institute of Technology Allahabad,
Prayagraj – 211004, UP, INDIA