Pages

සීමාවන් නොමැති අදහස් වලට පණ දෙන්න.....

Monday, October 19, 2009

hiring System program in java ( Command Line Interface )

Equiphire pvt. Ltd supplies 3 major equipments for hire.

Program which created for this company which runs on Command Line Interface. It
could handle using the main menu.

No ---|--- Item ---|--- Daily Rental ---|--- Deposit Value
1 ---|--- Electric Drill - --|--- 800 ---|--- 15000
2 ---|--- Water Pump ---|--- 500 ---|--- 7500
3 ---|--- Electric Jigsaw ---|--- 400 ---|--- 8000


main CLI interface of the program



______________________________________
How it works.
  • This program is a platform independent program. So, it could run on any operating system which has Java installed.
  • It runs on command line interface.
  • It saves data in files and retrieves data from them.
  • Program asks a choice as a numerical input from the keyboard. As mentioned
  • here, we can choose the appropriate value as our need.
_________________________________________________________________________

How could we use the program

Choice 1 brings the user to the Hiring System.
◦ We can add hire details via the program.
◦ Program will calculate the deposit value needed and the default deposit as well as the return value from the deposit.
◦ Transactions will be saved in a file for future use.

• Choice 2 brings the user to the Daily report.
◦ User could view the daily transactions of the company.
◦ User need to enter appropriate date on the YYYYMMDD format.
◦ System will automatically show every transaction which done in particular day.

• Choice 3 brings the user to the History of the hires of individual customer.
◦ User could easily find the hiring history of a customer using the customer ID.
◦ User need to enter appropriate customer ID in to the system.
◦ System will automatically show every transaction which done by particular customer.

• Choice 4 brings the user to the History of the hires of individual equipment.
◦ User could easily find the hiring history of an equipment using the equipment ID.
◦ User need to enter appropriate Equipment ID in to the system.
◦ System will automatically show a history of the hirings which done on the particular equipment.

• Choice 5 brings the user to the History of the hires of the Company
◦ User could easily find the full hiring history of the Company.

• Choice 6 brings the user to the Customer database.
◦ User could easily find the full list of the Customer database.

• Choice 7 provides the facility to add Customers to the system.
◦ User could easily add Customers to the system.
◦ User need to add the customers name and the email address. Customer ID and registered date will be added automatically to the system.
◦ It will saved in a file for future use.

• Choice 8 provides the facility to add Equipments to the system.
◦ User could easily add a Equipments to the system.
◦ User need to add Equipment ID, Name, daily rental and the Deposit value.
◦ It will saved in a file for future use.


//////////////////////////////////////////////////////////////////////////////////////////////////
// //
// //
// hiringSystem //
// //
// K.W.Roshan Herath //
// //
// //
// //
// //
// //
//______________________________________________________________________________________________//
// created on opnSUSE 11.0 with //
// java version "1.6.0_06" //
// Java(TM) SE Runtime Environment (build 1.6.0_06-b02) //
// Java HotSpot(TM) Client VM (build 10.0-b22, mixed mode) //
// //
//////////////////////////////////////////////////////////////////////////////////////////////////


import java.util.*;

import java.io.*;

import java.lang.*;
import java.lang.String.*;



class hiringSystem
{

private InputStreamReader ir=new InputStreamReader(System.in);


private BufferedReader br;

private FileOutputStream fos;

private PrintStream ps;

private FileReader frs;


//function to check the existence for a file

private boolean checkFile(String filename)

{

File myFile=new File(filename);

boolean b=myFile.exists();



return b;

}
//////////////////////////////////////////////////////////////////////////////////////////////////
// function to get date //
//////////////////////////////////////////////////////////////////////////////////////////////////

private String fdate()

{
String date;
int month,day,year;
GregorianCalendar calendr;

calendr=new GregorianCalendar();
day=calendr.get(calendr.DATE);
month=calendr.get(calendr.MONTH);
month+=1;//to add january as 1 instead of 0
year=calendr.get(calendr.YEAR);

date = year +""+ month +""+ day;

return date;

}


//////////////////////////////////////////////////////////////////////////////////////////////////
// function to make a hire //
//////////////////////////////////////////////////////////////////////////////////////////////////

private void hire()throws IOException

{
//////////////////////////////////////////////////////////////////
/* String chkcustID,chkcustName,chkemail,chks,chkdateRegd;
long datenow,duration,chkdateReg;

String cline[]=new String[5];


frs=new FileReader("ITE1101As2OctE091041007Customers.txt");

br=new BufferedReader(frs);


while((chks=br.readLine()) != null)

{

cline=chks.split(",");

chkcustID=cline[0];

chkcustName=cline[1];

chkemail=cline[2];

chkdateRegd=cline[3];

}
datenow=(long)fdate();
chkdateReg=(long)chkdateRegd;

duration=datenow-chkdateReg;
*/
//////////////////////////////////////////////////
String custID,datehired,msg,s="y";
String equipID,cuID;
int days,type;
double deposit=0,deposit1=0,rental,returnval;


while(s.equals("y")) {
try{
br=new BufferedReader(ir);

System.out.println("\nEnter Equipment Type");
System.out.println("\n1 FOR ELECTRIC DRILL");
System.out.println("2 FOR WATER PUMP");
System.out.println("3 FOR ELECTRIC JIGSAW ");
System.out.print("\nEnter Equipment Type 1,2,3: ");
type=Integer.parseInt(br.readLine());
System.out.print("\nEnter Equipment ID: ");
equipID=br.readLine();

System.out.print("\nEnter Customer ID: ");
cuID=custID=br.readLine();

System.out.print("\nEnter no of days hired for: ");
days=Integer.parseInt(br.readLine());
datehired=fdate();

System.out.print("\n registered date :"+datehired+"\n\n");

br=new BufferedReader(ir);

if(type==1)
{ deposit=800*days;if(deposit<=15000) deposit1=15000; else deposit1=deposit;} else if(type==2) { deposit=500*days;if(deposit<=15000) deposit1=7500; else deposit1=deposit;} else if(type==3) { deposit=400*days; if(deposit<=15000) deposit1=8000; else deposit1=deposit;} System.out.println("\ndeposit must : "+deposit1); System.out.println("\ndeposit need : "+deposit); returnval=deposit1-deposit; System.out.println("\nretrun value must : "+returnval); fos=new FileOutputStream("ITE1101As2OctE091041007Transaction.txt",true); ps=new PrintStream(fos); ps.println(equipID+","+custID+","+datehired+","+days+","+deposit1+","+deposit+","+returnval); fos.close(); System.out.println("Hire successfull"); } catch(Exception ex) { System.out.println("Error in accepting specifications..."); } } } ////////////////////////////////////////////////////////////////////////////////////////////////// // to view daily report // ////////////////////////////////////////////////////////////////////////////////////////////////// private void dailyReport()throws IOException { String equipID,custID,datehired,days,deposit1,deposit,returnval,s,searchDate; String cline[]=new String[7]; InputStreamReader Ir=new InputStreamReader(System.in); BufferedReader Br=new BufferedReader(Ir); System.out.print("\nEnter date YYYYMMDD: "); searchDate=Br.readLine(); try { frs=new FileReader("ITE1101As2OctE091041007Transaction.txt"); br=new BufferedReader(frs); System.out.println("daily report for : "+searchDate); System.out.println("Equip \tby \thired \t\tforDays \tdeposit\tpayable\treturn"); System.out.println("----------------------------------------------"); while((s=br.readLine()) != null) { cline=s.split(","); equipID=cline[0]; custID=cline[1]; datehired=cline[2]; days=cline[3]; deposit1=cline[4]; deposit=cline[5]; returnval=cline[6]; if(datehired.equals(searchDate)){ System.out.println(datehired+"\t"+equipID+"\t"+custID+"\t"+days+"\t\t"+deposit1+"\t"+deposit+"\t"+returnval); } }} catch(Exception ex) { System.out.println("Some exceptions occured..."); System.out.println("Could not generate the Customer report...!"); } } ////////////////////////////////////////////////////////////////////////////////////////////////// // to view hire history for individual customer // ////////////////////////////////////////////////////////////////////////////////////////////////// private void indCust()throws IOException { String equipID,custID,datehired,days,deposit1,deposit,returnval,s,customerID; String cline[]=new String[7]; InputStreamReader Ir=new InputStreamReader(System.in); BufferedReader Br=new BufferedReader(Ir); System.out.print("\nEnter Customer ID: "); customerID=Br.readLine(); try { frs=new FileReader("ITE1101As2OctE091041007Transaction.txt"); br=new BufferedReader(frs); System.out.println("Hire history for : "+customerID); System.out.println("Equip \tby \thired \t\tforDays \tdeposit\tpayable\treturn"); System.out.println("----------------------------------------------"); while((s=br.readLine()) != null) { cline=s.split(","); equipID=cline[0]; custID=cline[1]; datehired=cline[2]; days=cline[3]; deposit1=cline[4]; deposit=cline[5]; returnval=cline[6]; if(custID.equals(customerID)){ System.out.println(custID+"\t"+equipID+"\t"+datehired+"\t"+days+"\t\t"+deposit1+"\t"+deposit+"\t"+returnval); } }} catch(Exception ex) { System.out.println("Some exceptions occured..."); System.out.println("Could not generate the Customer report...!"); } } ////////////////////////////////////////////////////////////////////////////////////////////////// // to view hire history for equipments // ////////////////////////////////////////////////////////////////////////////////////////////////// private void indEquip()throws IOException { String equipID,custID,datehired,days,deposit1,deposit,returnval,s,equipmentID; String cline[]=new String[7]; InputStreamReader Ir=new InputStreamReader(System.in); BufferedReader Br=new BufferedReader(Ir); System.out.print("\nEnter Equipment ID: "); equipmentID=Br.readLine(); try { frs=new FileReader("ITE1101As2OctE091041007Transaction.txt"); br=new BufferedReader(frs); System.out.println("Hire history for : "+equipmentID); System.out.println("Equip \tby \thired \t\tforDays \tdeposit\tpayable\treturn"); System.out.println("----------------------------------------------"); while((s=br.readLine()) != null) { cline=s.split(","); equipID=cline[0]; custID=cline[1]; datehired=cline[2]; days=cline[3]; deposit1=cline[4]; deposit=cline[5]; returnval=cline[6]; if(equipID.equals(equipmentID)){ System.out.println(equipID+"\t"+custID+"\t"+datehired+"\t"+days+"\t\t"+deposit1+"\t"+deposit+"\t"+returnval); } }} catch(Exception ex) { System.out.println("Some exceptions occured..."); System.out.println("Could not generate the Customer report...!"); } } ////////////////////////////////////////////////////////////////////////////////////////////////// // displayReport() // ////////////////////////////////////////////////////////////////////////////////////////////////// private void displayReport() { String equipID,custID,datehired,days,deposit1,deposit,returnval,s; String cline[]=new String[7]; try { frs=new FileReader("ITE1101As2OctE091041007Transaction.txt"); br=new BufferedReader(frs); System.out.println("Equip \tby \thired \t\tforDays \tdeposit\tpayable\treturn"); System.out.println("----------------------------------------------"); while((s=br.readLine()) != null) { cline=s.split(","); equipID=cline[0]; custID=cline[1]; datehired=cline[2]; days=cline[3]; deposit1=cline[4]; deposit=cline[5]; returnval=cline[6]; System.out.println(equipID+"\t"+custID+"\t"+datehired+"\t"+days+"\t\t"+deposit1+"\t"+deposit+"\t"+returnval); } } catch(Exception ex) { System.out.println("Some exceptions occured..."); System.out.println("Could not generate the daily transaction report...!"); } } ////////////////////////////////////////////////////////////////////////////////////////////////// // to view customer details // ////////////////////////////////////////////////////////////////////////////////////////////////// private void viewCust() { String custID,custName,email,dateRegd,s; String cline[]=new String[4]; try { frs=new FileReader("ITE1101As2OctE091041007Customers.txt"); br=new BufferedReader(frs); System.out.println("Customer ID \tCustomer Name \temail \t\tDate registered "); System.out.println("----------------------------------------------"); while((s=br.readLine()) != null) { cline=s.split(","); custID=cline[0]; custName=cline[1]; email=cline[2]; dateRegd=cline[3]; System.out.println(custID+"\t\t"+custName+"\t\t\t"+email+"\t"+dateRegd); } } catch(Exception ex) { System.out.println("Some exceptions occured..."); System.out.println("Could not generate the Customer report...!"); } } ////////////////////////////////////////////////////////////////////////////////////////////////// // function to add a customer // ////////////////////////////////////////////////////////////////////////////////////////////////// //function for auto-generating the customer id private String generate_id() { String id=" "; String thisLine; String[] fullText = new String[200]; String[] lastLine=new String[5]; int counter=0,nid=0,l=0,z=0; boolean b=checkFile("ITE1101As2OctE091041007Customers.txt"); if(b==false) { id="00001"; } else { try { frs=new FileReader("ITE1101As2OctE091041007Customers.txt"); br=new BufferedReader(frs); while((thisLine=br.readLine()) != null) { counter=counter+1; fullText[counter] = thisLine; } frs.close(); lastLine=fullText[counter].split(","); nid=Integer.parseInt(lastLine[0]); nid=nid+1; l=(String.valueOf(nid)).length(); z=5-l; for(int i=1;i<=z;i++) { id=id+"0"; } id=id+String.valueOf(nid); id=id.substring(1); } catch(Exception ex) { System.out.println("Could not generate the Customer ID...!"); } } return id; } //function to add new Customer private void addCustomer() { String desc; String cust,email,regd; String id; try { id=generate_id(); System.out.print("\n Customer ID :"+id+"\n"); br=new BufferedReader(ir); System.out.print("\n Customer Name : "); cust=br.readLine(); System.out.print("\n Email : "); email=br.readLine(); regd=fdate(); System.out.print("\n registered date :"+regd+"\n\n"); br=new BufferedReader(ir); fos=new FileOutputStream("ITE1101As2OctE091041007Customers.txt",true); ps=new PrintStream(fos); ps.println(id+","+cust+","+email+","+regd); fos.close(); System.out.println("Successfully added one Customer..."); } catch(Exception ex) { System.out.println("Error in accepting Customer specifications..."); } } ////////////////////////////////////////////////////////////////////////////////////////////////// // function to add an Equipment // ////////////////////////////////////////////////////////////////////////////////////////////////// private boolean checkFile1(String filename) { File myFile1=new File(filename); boolean b1=myFile1.exists(); return b1; } boolean b1=checkFile1("ITE1101As2OctE091041007Equipments.txt"); //function to add new equipment private void addEquipment() { String equip; double drent=0; double deposit=0; String id; int availability=1; try { br=new BufferedReader(ir); System.out.print("\n Equipment ID :"); id=br.readLine(); System.out.print("\n Equipment Name : "); equip=br.readLine(); System.out.print("\n Daily rental :"); drent=Double.parseDouble(br.readLine()); System.out.print("\n Deposit :"); deposit=Double.parseDouble(br.readLine()); fos=new FileOutputStream("ITE1101As2OctE091041007Equipments.txt",true); ps=new PrintStream(fos); ps.println(id+","+equip+","+drent+","+availability+","+deposit); fos.close(); System.out.println("Successfully added one Equipment"); } catch(Exception ex) { System.out.println("Error in accepting specifications..."); } } ////////////////////////////////////////////////////////////////////////////////////////////////// // HELP // ////////////////////////////////////////////////////////////////////////////////////////////////// /*private void help() { System.out.println(" HIRING SYSTEM HELP "); }*/ ////////////////////////////////////////////////////////////////////////////////////////////////// // MAIN Method // ////////////////////////////////////////////////////////////////////////////////////////////////// public static void main(String args[]) throws IOException { hiringSystem inv=new hiringSystem(); int ch=0; String s; InputStreamReader ir=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(ir); System.out.println("\n\n\n"); System.out.println("--------------------------------------------------"); System.out.println(" EquipHire Pvt. Ltd "); System.out.println(" උපකරණ කුලියට දීම "); System.out.println("--------------------------------------------------\n"); System.out.println("1. HIRE AN EQUIPMENT"); System.out.println("2. TO VIEW THE DAILY REPORT"); System.out.println("3. TO VIEW HIRE HISTORY OF A CUSTOMER"); System.out.println("4. TO VIEW HIRE HISTORY OF AN EQUIPMENT"); System.out.println("5. VIEW FULL HIRING REPORT"); System.out.println("6. VIEW ALL CUSTOMERS"); System.out.println("7. ADD NEW CUSTOMER"); System.out.println("8. ADD AN EQUIPMENT"); System.out.println("---------------------------------"); System.out.println("9. Exit"); begin: while(ch!=9) { System.out.print("\n"); System.out.print("\n Enter a choice and Press ENTER to continue[1-9]:"); ch=Integer.parseInt(br.readLine()); if(ch>9||ch<1)

{

System.out.println("This doesn't appear to be a valid option...!");

continue begin;

}



////////////////////////////////////////////////////////////////////////////////////////////

if(ch==1)

{

s="y";

while(s.equals("y")||s.equals("Y"))

{

inv.hire();

System.out.print("\n Hire another[y/n]:");

s=br.readLine();

}

}

////////////////////////////////////////////////////////////////////////////////////////////
else

if(ch==2)

{

s="y";

while(s.equals("y")||s.equals("Y"))

{

inv.dailyReport();
System.out.print("\n View again ?[y/n]:");

s=br.readLine();




}

}
////////////////////////////////////////////////////////////////////////////////////////////
else

if(ch==3)

{

s="y";

while(s.equals("y")||s.equals("Y"))

{

inv.indCust();
System.out.print("\n View again ?[y/n]:");

s=br.readLine();


}

}
///////////////////////////////////////////////////////////////////////////////////////////
else

if(ch==4)

{

s="y";

while(s.equals("y")||s.equals("Y"))

{

inv.indEquip();
System.out.print("\n View again ?[y/n]:");

s=br.readLine();



}

}
////////////////////////////////////////////////////////////////////////////////////
else

if(ch==5)

{

inv.displayReport();

}
/////////////////////////////////////////////////////////////////////////////////////
else

if(ch==6)

{

s="y";

while(s.equals("y")||s.equals("Y"))

{

inv.viewCust();
System.out.print("\n View again ?[y/n]:");

s=br.readLine();



}

}
////////////////////////////////////////////////////////////////////////////////////////
else
if(ch==7)

{

s="y";

while(s.equals("y")||s.equals("Y"))

{

inv.addCustomer();

System.out.print("\n Add another[y/n]:");

s=br.readLine();

}

continue begin;

}
////////////////////////////////////////////////////////////////////////////////////////

else
if(ch==8)

{

s="y";

while(s.equals("y")||s.equals("Y"))

{

inv.addEquipment();

System.out.print("\n Add another[y/n]:");

s=br.readLine();

}

}
////////////////////////////////////////////////////////////////////////////////////////


}

System.out.println("Thanks for using this program...!");

}

}


__________________________________________________________________________________

  1. there are some errors in my program.
  2. it needs 3 text files to store data.
  3. before add a customer, it should have atlest 00000 as the1st data in the customer file.
  4. can hire w/o registering as a customer.
  5. can hire equipment which isn't in the equipment file.
  6. cant find the equipment is available to hire or not.
  7. .cant calculate delays.
i'l try to solve these problems as i get free time from my studies. please help me if you can.

No comments:

Post a Comment

හිත කියන්නෙ පුදුම දෙයක්. ඒක තියෙන්නෙ කොතැනද කියලා කවුද දන්නෙ?
හිත නිතරම වෙනස් වෙනවා. හිතට නිතරම සිතුවිලි එනවා.
හිතට වරක් ආපු සිතුවිල්ලක් නැවත ඇති වෙන්නෙ කලාතුරකින්.

ඔබ කැමති නම් හිතට එන සිතුවිලි/අදහස් අකුරු කරන්න.


ඇනෝලා සමා වෙත්වා. මගේ බ්ලොග් එකට ස්පෑම්බොට් එකකින් ස්පෑම් කමෙන්ට් එනනිසා ඇනෝලාගේ කමෙන්ට් කිරීමේ අයිතිය නැති කරන්න සිදු වුනා.

Related Posts with Thumbnails