package schoolapartments;
import java.util.Calendar;
import java.util.Scanner;
public class Main {
public Main(){
}
private ApartmentA[] typeA;
private ApartmentB[] typeB;
private Student[] student;
private Scanner input=new Scanner(System.in);
private Scanner input2=new Scanner(System.in);
private Calendar calendar;
public static void schoolapartment (String[] args) {
Main ma=new Main();
ma.initialiseArrays();
ma.Menu();
}
private void Menu()
{
char selection;
String choice;
System.out.println("WELCOME TO UCTI APARTMENT SYSTEM");
System.out.println("");
System.out.println("[----------------------------]");
System.out.println("[ MAIN MENU ]");
System.out.println("[----------------------------]");
System.out.println("[ Press N - New Registration ]");
System.out.println("[ Press U - Update Status ]");
System.out.println("[ Press R - Report ]");
System.out.println("[ Press S - Search ]");
System.out.println("[ Press Q - Quit System ]");
System.out.println("[----------------------------]");
System.out.println("");
choice=input.next();
selection=choice.charAt(0);
switch(selection)
{
case 'N':
case 'n':
registerStudentModule();
break;
case 'U':
case 'u':
updateModule();
break;
case 'R':
case 'r':
generateReportModule();
break;
case 'S':
case 's':
searchModule();
break;
case 'Q':
case 'q':
System.out.println("Thank you for using our system");
System.out.println("Have a nice day");
System.exit(0);
break;
default:
System.out.println("Incorrect Selection");
System.out.println("Please revise your selection");
System.out.println("");
Menu();
break;
}
}
public void registerStudentModule()
{
char choice;
String str,studentID,studentName,master,deposite;
boolean isMaster;
System.out.println("");
System.out.println("[-----------------------------------------------------------------]");
System.out.println("[ REGISTRATION MENU ]");
System.out.println("[--------------------------------|--------------------------------]");
System.out.println("[ Type A | Type B ]");
System.out.println("[--------------------------------|--------------------------------]");
System.out.println("[ 2 Single bedroom | 1 Master bedroom ]");
System.out.println("[ | 2 Single bedroom ]");
System.out.println("[ Facilities: Laudry & Kitchen | Facilities: No Laudry/Kitchen ]");
System.out.println("[ Monthly rental: RM300 | Month rental: RM280 (Master) ]");
System.out.println("[ | RM200 (Single) ]");
System.out.println("[-----------------------------------------------------------------]");
System.out.println("");
System.out.println("-----------New Student---------");
System.out.println(" Press A - Apartment Type A ");
System.out.println(" Press B - Apartment Type B ");
System.out.println("-------------------------------");
str=input.next();
choice=str.charAt(0);
switch(choice)
{
case 'A':
case 'a':
System.out.println("Enter Student ID (TP No.)");
System.out.print("TP");
studentID=input.next();
System.out.println("Enter Student Name");
studentName=input2.nextLine();
System.out.println("Enter Security Deposite");
deposite=input.next();
for(int i=0;i<20;i++)
{
if(typeA[i].isVaccant()==true)
{
typeA[i].setRooms();
for(int j=0;j<20;j++)
{
if(student[j].getID().equalsIgnoreCase("")==true)
{
student[j].setType(typeA[i].getApartmentID());
student[j].setRent(typeA[i].getRentAmount());
student[j].setID(studentID);
student[j].setName(studentName);
calendar=Calendar.getInstance();
calendar.add(Calendar.DATE, 30);
student[j].setExpiry(calendar.getTime().toString());
System.out.println("New Student booking has been made");
break;
}
}
break;
}
}
break;
case 'B':
case 'b':
System.out.println("Enter Student ID");
studentID=input.next();
System.out.println("Enter Student Name");
studentName=input2.nextLine();
System.out.println("Enter Security Deposite");
deposite=input.next();
System.out.println("Master Roam(Y/N)");
master=input.next();
if(master.equalsIgnoreCase("Y"))
isMaster=true;
else
isMaster=false;
for(int i=0;i<10;i++)
{
if(typeB[i].isVaccant()==true)
{
typeB[i].setRooms();
typeB[i].setMasterRoom(isMaster);
for(int j=0;j<20;j++)
{
if(student[j].getID().equalsIgnoreCase("")==true)
{
student[j].setType(typeA[i].getApartmentID());
student[j].setRent(typeA[i].getRentAmount());
student[j].setID(studentID);
student[j].setName(studentName);
calendar=Calendar.getInstance();
calendar.add(Calendar.DATE, 30);
student[j].setExpiry(calendar.getTime().toString());
System.out.println("New Student booking has been made");
break;
}
}
break;
}
}
break;
default:
System.out.println("Incorrect Selection");
break;
}
System.out.println("Enter Y to add another student or M for Main Menu");
str=input.next();
if(str.equalsIgnoreCase("Y"))
registerStudentModule();
else
Menu();
}
private void updateModule()
{
String apartmentID,choice;
System.out.println("*******Update Module*******");
System.out.println("*Please enter Apartment ID*");
System.out.println("***************************");
apartmentID=input.next();
System.out.println("Enter A for Type A and B for Type B");
choice=input.next();
if(choice.equalsIgnoreCase("A"))
{
for(int i=0;i<20;i++)
{
if(typeA[i].getApartmentID().equalsIgnoreCase(apartmentID))
{
if(typeA[i].isVaccant()==true)
System.out.println("The apartment is currently vaccant");
else
System.out.println("The apartment is currently Full");
System.out.println("Do you want to change the current Status of the appartment?(Y/N)");
choice=input.next();
if(choice.equalsIgnoreCase("Y"))
{
if(typeA[i].isVaccant()==true)
typeA[i].setVaccant(false);
else
typeA[i].setVaccant(true);
System.out.println("Apartment Status has been updated");
System.out.println();
break;
}
else
break;
}
}
Menu();
}
else
{
for(int i=0;i<20;i++)
{
if(typeB[i].getApartmentID().equalsIgnoreCase(apartmentID))
{
if(typeB[i].isVaccant()==true)
System.out.println("The apartment is currently vaccant");
else
System.out.println("The apartment is currently Full");
System.out.println("Do you want to change the current Status of the appartment?(Y/N)");
choice=input.next();
if(choice.equalsIgnoreCase("Y"))
{
if(typeB[i].isVaccant()==true)
typeB[i].setVaccant(false);
else
typeB[i].setVaccant(true);
System.out.println("Apartment Status has been updated");
System.out.println();
break;
}
else
break;
}
}
Menu();
}
}
private void generateReportModule()
{
int atype=0,btype=0;
String str;
for(int i=0;i<20;i++)
{
if(typeA[i].isVaccant()==true)
atype=atype+1;
if(typeB[i].isVaccant()==true)
btype=btype+1;
}
System.out.println("********Report Mordule**********");
System.out.println("*Apartment Type : Type A *");
System.out.printf("*Occupied : %d Apartments*\n",atype);
System.out.printf("*Vacant : %d Apartments*\n",20-atype);
System.out.println("********************************");
System.out.println("*Apartment Type : Type B *");
System.out.printf("*Occupied : %d Apartments*\n",btype);
System.out.printf("*Vacant : %d Apartments*\n",20-btype);
System.out.println("*********************************");
System.out.println("Enter any Key to continue");
str=input.next();
Menu();
}
private void searchModule()
{
String studentID,ans;
boolean found=false;
System.out.println("*****Search Module*******");
System.out.println("*Please Enter Student ID*");
System.out.println("*************************");
studentID=input.next();
for(int i=0;i<20;i++)
{
if(student[i].getID().equalsIgnoreCase(studentID))
{
found=true;
System.out.printf("Student ID : %s\n",student[i].getID());
System.out.printf("Student Name : %s\n",student[i].getName());
System.out.printf("Apartment ID : %s\n",student[i].getType());
System.out.printf("Rent Amount : %f\n",student[i].getRent());
System.out.printf("Expiry Date : %s\n",student[i].getExpiry());
System.out.println("Enter any key to continue");
ans=input.next();
break;
}
}
if(found==false)
{
System.out.println("You entered a wrong student ID, please enter correct student ID");
searchModule();
}
Menu();
}
private void initialiseArrays()
{
typeA=new ApartmentA[20];
typeB=new ApartmentB[20];
student=new Student[20];
for(int i=0;i<20;i++)
{
typeA[i]=new ApartmentA(String.valueOf((i+1)*100));
typeB[i]=new ApartmentB(String.valueOf((i+1)*100));
student[i]=new Student();
}
}
}
This is the "main" code which related to another 3 classes.i'm trying to convert to an applet. I am very new to Java and from what i got from Google is applet was based on .awt and swing. For my case, i don't know where to put those init(), start(), stop() etc.
It's very simple application that simulates a house/apartment service system . The application will do
Registration of student
Update (check out)
Report
Search
Basically i have made everything working its just the matter of running in in applet form which my teacher didn't taught me yet so my knowledge just based on books and webs.
So, where should should i begin with ?
(i noticed some website said that the application must be changed into swig, where should i put the command )
that i want to run it in an applet.

New Topic/Question
Reply




MultiQuote




|