Sunday 23 November 2014

Hostel Management System Project

Structure of the Problem Requirements 

In this project we will implement the complete source code of hostel management system in Java. The main purpose of this code to understand the basic concept of OOP . The project used the all functionality of OOP concept like constructor, classes , inheritance and calling of methods from one class to another class. Here is the four classes of  this project which help you in better understanding.

Source Code

mainmenu.java

package post;
 import java.util.Scanner;

public class mainmenu 
{
static int tp=0;
static int rm=0;
static int ga=0;
static int gl=0;
static int gr=0;
static int gs=0;
String gn="";
person[] human =new person[10];
public static int Menu() {
Scanner read=new Scanner(System.in);
System.out.print("\n========================");
System.out.print("\n== 1. Add New person  ==");
System.out.print("\n== 2. View person     ==");
   System.out.print("\n== 5. Quit            ==");
System.out.print("\n========================");
System.out.print("\nChoice: ");
return read.nextInt();
}
public static void showMessage(String msg) {
System.out.print("\n"+msg);
}
public static int Message()
{
Scanner read=new Scanner(System.in);
System.out.print("\nChoice :");
return read.nextInt();
}
public static void print(person h) {
System.out.print("\n------------------------");
System.out.print("\nname: "+h.getName());
System.out.print("\nage: "+h.getAge());
System.out.print("\n------------------------");
System.out.print("\nroomseat: "+h.getRoomSeat());
System.out.print("\nroomrent: "+h.getSeatRent());
System.out.print("\n room laundry: "+(h.getRoomSeat()*h.getRoomLaundry()));
System.out.print("\nRoom Mess: "+h.getRoomMess());
System.out.print("\n------------------------");
System.out.print("\ntotal Payment: "+h.totalPayment());
System.out.print("\n------------------------");
}
public static String getName()
{
Scanner read=new Scanner(System.in);
System.out.print("\nEnter Name: ");
String gn=read.nextLine();
return gn;
}
public static int getLoundry()
{
return gl;
}
public static int getLndry()
{
Scanner read=new Scanner(System.in);
System.out.print("\nDo you want loundry?  1: yess ====  0:No");
int s=read.nextInt();
if (s==1)
{
s=500;
}
else
{
s=0;
}
return s;
}
public static int  getAge()
{
Scanner read=new Scanner(System.in);
System.out.print("\nEnter Age: ");
int ga=read.nextInt();
return ga;
}
public static int  getRoomSeat()
{
Scanner read=new Scanner(System.in);
System.out.print("\nEnte roomSeat: ");
int gs=read.nextInt();
gr=gs*5000;
rm=gs*3000;
gl=getLndry();
tp=gr+rm+(gl*gs);
return gs;
}
public static int  getSeatRent()
{
Scanner read=new Scanner(System.in); 
return gr;
}
public static int totalPayment()
{
Scanner read=new Scanner(System.in);
return tp;
}
public static int  getRoomMess()
{
Scanner read=new Scanner(System.in); 
return rm;
}
}

hostelManegements.java

package post;
public class hostelManegements
{
public static void main(String[] args)
{
person[] human =new person[10];
mainmenu[] menu=new mainmenu[10];
int choice =0;
int check=0;
int E=0;
int d=0;
int y=0;
do{
choice=mainmenu.Menu();

if (choice ==1)
{
if (check<10)
{
human[check]=new person( mainmenu.getRoomSeat(), mainmenu.getName(),mainmenu.getAge());
if(d==1)
{
d=mainmenu.getLoundry();
}
else
{
mainmenu.showMessage("2;Do you want Mess press <2> for yes ");
y=mainmenu.Message();
if (y==3)
{
E=(human[check].totalPayment()+human[check].getSeatRent()-human[check].getRoomLaundry());
}
else
{
E=human[check].totalPayment()-(human[check].getRoomLaundry()+human[check].getRoomMess());
}
}
check+=1;
}
else 
{
mainmenu.showMessage("seats full");
}
else if (choice==2) {
if (check>0) {
for (int x=0;x<check;x++) {
mainmenu.print(human[x]); 
mainmenu.showMessage("person #: "+(x+1));
}
mainmenu.showMessage("------------------------");
}
else {
mainmenu.showMessage("No file Found!");
}
}
}while ((choice > 0) && (choice < 3));

}
}

hostel.java

package post;
 
public class hostel
{
  private int roomSeat;
  private int seatRent;
  private int roomLaundry;
  private int roomMess;
  private int totalPayment;
  
  public hostel()
  {
  
  roomSeat=1;
  seatRent=0;
  roomLaundry=0;
  roomMess=0;
  totalPayment=0;
  
  
  }
  public hostel(int rS,int rl,int tp,int sr,int rm)
  {
  roomSeat=rS;
  seatRent=sr;
  roomLaundry=rl;
  roomMess=rm;
  totalPayment=tp;
  
  }
  
  public int totalPayment()
  {
  return totalPayment;
  }
  public int getRoomSeat()
  {
  return roomSeat;
  }
  
  public int getRoomLaundry()
  {
  return roomLaundry;
  }
  public int getRoomMess()
  {
  return roomMess;
  }
  public int getSeatRent()
  {
  return seatRent;
  }
  }
  

person.java

package post;
public class person extends hostel
{
private String name;
private int age;

public person()
{
super();
name="a";
age=1;
}
public person(int x,String n,int a )
{

name =n;
age=a;
}
public String getName()
{
return name;
}
public int getAge()
{
return age;
}
}

Output of the Program

Hostel Management System Project in Java
Hostel Management System Project in Java

Share it Please
asad

About Author!

Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.

0 comments:

Post a Comment