Sunday, June 16, 2013

Hotel Management in java

-Use one dimensional Array:

package homework;
import java.io.*;
public class Topic8 {
    public static void main(String[] args) throws IOException{
        if(args.length !=1)
            System.exit(0);
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int num = Integer.parseInt(args[0]);
        //int num=Integer.parseInt(in.readLine());
        String[] name = new String[num];
        String temp ="";
        while(true){
            System.out.print("1. Check In, 2. Check Out, 3. Show All, 4. Exit = ");
            int condition= Integer.parseInt(in.readLine());
            if(condition == 1){
                System.out.print("Check In : Room Number ? ");
                int cr = Integer.parseInt(in.readLine());
                if(cr>=0 && cr < name.length){
                    System.out.print("name = ");
                    temp=in.readLine();
                    if(name[cr] != null){
                        System.out.println("This room is busy!");
                    }else{
                        name[cr]=temp;
                    }
                }else{
                    System.out.println("This room "+cr+" is not have.");
                }
            }else if(condition == 2){
                System.out.print("Check Out : Room Number ? ");
                int co = Integer.parseInt(in.readLine());
                if(co>=0 && co < name.length){
                    if(name[co] !=null)
                        name[co]=null;
                    else
                        System.out.println("This room is already check out!");
                }else{
                    System.out.println("Room "+co+" is not have.");
                }
            }else if(condition == 3){
                for(int i=0;i<name.length;i++)
                    System.out.print("Room No."+i+" = "+name[i]+"\t");
                System.out.println();
            }else if(condition == 4){
                System.out.print("End...");
                System.exit(0);
            }else{
                System.out.println("Please choose that has available in option!");
            }
           
        }
       
    }
}

-Use tow dimensional Array:


package homework;

import java.io.*;

public class Topic10 {
    public static void main(String[] args) throws IOException{
        if(args.length !=2)
            System.exit(0);
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int num = Integer.parseInt(args[0]);//floor
        int num1 = Integer.parseInt(args[1]);//room
        String[][] name = new String[num][num1];
        String temp="";
        while(true){
            System.out.print("1. Check In, 2. Check Out, 3. Show All, 4. Exit = ");
            int condition = Integer.parseInt(in.readLine());
            if(condition == 1){
                System.out.print("Floor number = ");
                int fn = Integer.parseInt(in.readLine());
                if(fn>=0 && fn < num){
                    System.out.print("Room number = ");
                    int rn = Integer.parseInt(in.readLine());
                    if(rn>=0 && rn < num){
                        System.out.print("Customer name = ");
                        temp = in.readLine();
                        if(name[fn][rn] != null){
                            System.out.println("This room is busy!");
                        }else{
                            name[fn][rn]=temp;
                        }
                    }else{
                        System.out.println("This room "+rn+" is not have.");
                    }
                }else{
                    System.out.println("This floor "+fn+" is not have.");
                }
            }else if(condition == 2){
                System.out.print("Floor number = ");
                int fn = Integer.parseInt(in.readLine());
                if(fn>=0 && fn < num){
                    System.out.print("Room number = ");
                    int rn = Integer.parseInt(in.readLine());
                    if(rn>=0 && rn < num){
                        System.out.print("Customer name = ");
                        temp = in.readLine();
                        if(name[fn][rn] !=null)
                            name[fn][rn]=null;
                        else
                            System.out.println("This room is already check out!");
                    }else{
                        System.out.println("This room "+rn+" is not have.");
                    }
                }else{
                    System.out.println("This floor "+fn+" is not have.");
                }
            }else if(condition == 3){
                for(int i=0;i<num;i++){
                    System.out.println(i+" floor!");
                    for(int j=0;j<num1;j++){
                        System.out.print("Room No."+j+" : "+name[i][j]+"\t");
                    }
                    System.out.println();
                }
            }else if(condition == 4){
                System.out.print("End...");
                System.exit(0);
            }else{
                System.out.println("Please choose that has available in option!");
            }   
        }
    }
}

No comments:

Post a Comment