Beruflich Dokumente
Kultur Dokumente
import
import
import
java.util.*;
java.io.*;
javax.swing.JOptionPane;
java.text.DecimalFormat;
A = 0;
B = 0;
IDno = 0;
tDate = 0;
eDate = 0;
confirm = confirmation.charAt(0);
if (confirm == 'Y' || confirm == 'y')
if (apt.getTypeA() >= 3)
JOptionPane.showMessageDialog(null, "Type A apar
tment is already full. Please select another apartment");
else if (apt.getTypeA() < 3)
{
name = JOptionPane.showInputDialog("Please enter
the student's name.");
IDinput = JOptionPane.showInputDialog("Please en
ter the student's ID.");
ID = Integer.parseInt(IDinput);
studentInfo.storeName(name);
studentInfo.storeID(ID);
nameA[A] = studentInfo.getName();
ID_A[IDno] = studentInfo.getID();
apt.TypeAoccupied();
JOptionPane.showMessageDialog(null, "The amount
to be paid upon registration: n" +
"RM" + twoDecimals.format(apt.getMonthlycostA()) + " for rental this monthn" +
"RM100.00 for utility charges and rental deposit for a monthnn" +
"Total: RM" +twoDecimals.format(apt.getcostA()) + "nn" +
"Please pay RM" + twoDecimals.format(apt.getMonthlycostA()) +
" for the following months till the rental expires.");
todayDate[tDate] = ((gcalendar.get(Calendar.DATE
))+"-"+(months[gcalendar.get(Calendar.MONTH)])+"-"+(gcalendar.get(Calendar.YEAR)
) );
gcalendar.add(Calendar.DATE, + 140);
expiryDate[eDate] = ((gcalendar.get(Calendar.DAT
E))+"-"+(months[gcalendar.get(Calendar.MONTH)])+"-"+(gcalendar.get(Calendar.YEAR
)) );
JOptionPane.showMessageDialog(null, "Registratio
n details: nn" +
"Name: " + nameA[A] + "n" +
"Student ID: " + ID_A[IDno] + "n" +
"Date of registration: " + todayDate[tDate] + "n" +
"Rental expiry date: " + expiryDate[eDate]);
A++;
IDno++;
tDate++;
eDate++;
}
}
if(choice == 2)
{
confirmation = JOptionPane.showInputDialog("You have sel
ected apartment Type B.n" +
"Enter 'Y' to confirm.");
confirm = confirmation.charAt(0);
if (confirm == 'Y' || confirm == 'y')
if (apt.getTypeB() >= 2)
JOptionPane.showMessageDialog(null, "Type B apar
tment is already full. Please select another apartment");
else if (apt.getTypeB() < 2)
{
name = JOptionPane.showInputDialog("Please enter
the student's name.");
IDinput = JOptionPane.showInputDialog("Please en
ter the student's ID.");
ID = Integer.parseInt(IDinput);
studentInfo.storeName(name);
studentInfo.storeID(ID);
nameB[B] = studentInfo.getName();
ID_B[IDno] = studentInfo.getID();
apt.TypeBoccupied();
JOptionPane.showMessageDialog(null, "The amount
to be paid upon registration: n" +
"RM" + twoDecimals.format(apt.getMonthlycostB()) + " for rental this monthn" +
"RM100.00 for utility charges and rental deposit for a monthnn" +
"Total: RM" +twoDecimals.format(apt.getcostB()) + "nn" +
"Please pay RM" + twoDecimals.format(apt.getMonthlycostB()) +
" for the following months till the rental expires.");
todayDate[tDate] = ((gcalendar.get(Calendar.DATE
))+"-"+(months[gcalendar.get(Calendar.MONTH)])+"-"+(gcalendar.get(Calendar.YEAR)
) );
gcalendar.add(Calendar.DATE, + 140);
expiryDate[eDate] = ((gcalendar.get(Calendar.DAT
E))+"-"+(months[gcalendar.get(Calendar.MONTH)])+"-"+(gcalendar.get(Calendar.YEAR
)) );
JOptionPane.showMessageDialog(null, "Registratio
n details: nn" +
"Name: " + nameB[B] + "n" +
gcalendar.add(Calendar.DATE, + 140);
expiryDate[eDate] = ((gcalendar.get(Calendar.DAT
E))+"-"+(months[gcalendar.get(Calendar.MONTH)])+"-"+(gcalendar.get(Calendar.YEAR
)) );
JOptionPane.showMessageDialog(null, "Registratio
n details: nn" +
"Name: " + nameB_master[0] + "n" +
"Student ID: " + ID_B_master[IDno] + "n" +
"Date of registration: " + todayDate[tDate] + "n" +
"Rental expiry date: " + expiryDate[eDate]);
IDno++;
tDate++;
eDate++;
}
}
break;
//====================================================== Task 2 ================
===========================================================
case 2:
JOptionPane.showMessageDialog(null, "You selected task 2:n" +
"Updat
e the apartment status.n" +
"This
task is to remove a student from an apartment.n" +
"Click
OK to continue.");
if (apt.getTypeA() == 0 && apt.getTypeB() == 0 && apt.getTypeB_m
aster() == 0)
{
JOptionPane.showMessageDialog(null, "There are currently
no student registered in " +
"any of the apartment units.");
}
else
{
inputDel = JOptionPane.showInputDialog("Please enter the
ID of the student " +
"you wish to delete.");
searchDel = Integer.parseInt(inputDel);
for(int i = 0; i <= apt.getTypeA(); i++)
{
if(searchDel == ID_A[i])
{
confirmation = JOptionPane.showInputDialog("Th
e following student will be removed:n" +
{
JOptionPane.showMessageDialog(null, "These are t
he list of students staying " +
"in apartment Type B: n" +
"Name: " + nameB[i] + "n" +
"ID: " + ID_B[i] + "n" +
"Date of registration: " + todayDate[i] + "n" +
"Date of rental expiry: " + expiryDate[i] + "nn");
}
for(int i = 0; i <= apt.getTypeB_master(); i++)
{
JOptionPane.showMessageDialog(null, "These are t
he list of students staying " +
"in apartment Type B master bedroom: n" +
"Name: " + nameB_master[i] + "n" +
"ID: " + ID_B_master[i] + "n" +
"Date of registration: " + todayDate[i] + "n" +
"Date of rental expiry: " + expiryDate[i] + "nn");
}
JOptionPane.showMessageDialog(null, "The total number of
occupants in the following apartments are: n" +
"Type
A: " + apt.getTypeA() + "n" +
"Type
B: " + apt.getTypeB() + "n" +
"Type
B master bedroom: " + apt.getTypeB_master() + "nn");
JOptionPane.showMessageDialog(null, "The total number of
vacant rooms in the following apartments are: n" +
"Type
A: " + (3 - apt.getTypeA()) + "n" +
"Type
B: " + (2 - apt.getTypeB()) + "n" +
"Type
B master bedroom: " + (1 - apt.getTypeB_master()) + "nn");
}
break;
}
inputreturn = JOptionPane.showInputDialog("Do you want to return to the
main menu?n" +
"Enter 'Y' for yes.");
returnToMenu = inputreturn.charAt(0);