⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simpleserversocket.java

📁 一个基于Java servelet的hotel broker 程序 实现access数据库访问
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
            	                    
            	                    while(itssss.hasNext())
            	                    {
            	                    	ps.println(new StringBuffer("OPTION:" + itssss.next()));
            	                    }
            	                    
            	                    ps.flush();
            	                    
            	                    String userSelectedRoom = br.readLine();
            	                    
            	                    if(userSelectedRoom != null)
            	                    {
            	                    	ps.println(new StringBuffer("OPTION:" + "Please wait for processing your booking request..."));
                      	                ps.println(new StringBuffer("OPTION:" + "-----------------------"));
                      	                ps.println(new StringBuffer("OPTION:" + "confirm to book this room?"));
                      	                ps.println(new StringBuffer("OPTION:" + "Please answer with YES or NO"));
                      	                ps.println(new StringBuffer("OPTION:" + "-----------------------"));
                      	                ps.flush();
                      	                
                      	                String userConfirmation = br.readLine();
                      	                
                      	                if(userConfirmation.equals("YES"))
                      	                {
                      	                	ps.println(new StringBuffer("OPTION:" + "please input your name:"));
                      	                    ps.println(new StringBuffer("OPTION:" + "-----------------------"));
                      	                    ps.flush();
                      	                    String userName = br.readLine();
                      	                    
                      	                    if(userName != null)
                      	                    {
                      		                   ps.println(new StringBuffer("OPTION:" + "please input your Phone Number:"));
                      	                       ps.println(new StringBuffer("OPTION:" + "-----------------------"));
                      	                       ps.flush();
                      	                       
                      	                       String userPhoneNumber = br.readLine();
                      	                       if(userPhoneNumber != null)
                      	                       {
                      	    	                  ps.println(new StringBuffer("OPTION:" + "please input your Credit Card Number:"));
                      	                          ps.println(new StringBuffer("OPTION:" + "-----------------------"));
                      	                          ps.flush();
                      	                          
                      	                          String userCreditCardNumber = br.readLine();
                      	                          if(userCreditCardNumber != null)
                      	                          {
                      	        	                 ps.println(new StringBuffer("OPTION:" + "please input your Check in date:"));
                      	        	                 ps.println(new StringBuffer("OPTION:" + "Format as 2008-08-08"));
                      	                             ps.println(new StringBuffer("OPTION:" + "-----------------------"));
                      	                             ps.flush();
                      	                             
                      	                             String userCheckinDate = br.readLine();
                      	                             if(userCheckinDate != null)
                      	                             {
                      	               	                 ps.println(new StringBuffer("OPTION:" + "please input your Check out date:"));
                      	                                 ps.println(new StringBuffer("OPTION:" + "Format as 2008-08-08"));
                      	                                 ps.println(new StringBuffer("OPTION:" + "-----------------------"));
                      	                                 ps.flush();
                      	                                 
                      	                                 String userCheckoutDate = br.readLine();
                      	                                 if(userCheckoutDate != null)
                      	                                 {
                      	                	                 ps.println(new StringBuffer("OPTION:" + "We are just processing your booking request..."));
                      	                                     ps.println(new StringBuffer("OPTION:" + "Please wait..."));
                      	                                     ps.println(new StringBuffer("OPTION:" + "-----------------------"));
                      	                                     ps.flush();
                      	                                  
                      	                                     //call functions to do the booking
                      	                                     String success = "SUCCESS";
                      	                                     if(success.equals(BookHotel(port,userName,userPhoneNumber,userCreditCardNumber,userSelectedRoom,userCheckinDate,userCheckoutDate)))
                      	                                     {
                      	                                     	ps.println(new StringBuffer("OPTION:" + "Booking success"));
                      	                                        ps.println(new StringBuffer("OPTION:" + "Thanks for choosing" + userSelectedHotel +"^^"));
                      	                                        ps.println(new StringBuffer("OPTION:" + "Input QUIT to quit the system!"));
                      	                                        ps.println(new StringBuffer("OPTION:" + "-----------------------"));
                      	                                        ps.flush();
                      	                                     }
                      	                                 }
                      	                             }  
                      	                          }
                      	                       } //if(userPhoneNumber != null)
                      	                    } //if(userName != null)
                      	                }  //if(userConfirmation.equals("YES"))
            	                    } //if(empty_room.contains(userSelectedRoom))
            	                 } //if(room_type.contains(userSelectedRoomType))
            	               } //if(hotelList.contains(userSelectedHotel))
            	            } //if(city.contains(userSelectedCity))	
            	            else
                            {
                    	       ps.println(new StringBuffer("OPTION:" + "Input error"));
            	               ps.println(new StringBuffer("OPTION:" + "Please try again"));
            	               ps.println(new StringBuffer("OPTION:" + "-------------------"));
            	               ps.flush();
                            }
            	            continue;
                    	} //if(userOption.equals ("2"))
                    	
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                    	if(keyword.equals ("3"))
                    	{
                    		ps.println(new StringBuffer("OPTION:" + "Welcome to Hotel Booking Broker!"));
                    		ps.println(new StringBuffer("OPTION:" + "-----------------------"));
                    		
                    		ps.println(new StringBuffer("OPTION:" + "Input 0 to go back the main menu..."));
                    		ps.println(new StringBuffer("OPTION:" + "-----------------------"));
            	            ps.flush();
                    		
            	            String userInput = br.readLine();
            	            if(userInput != null)
            	            {
            	               ps.println(new StringBuffer("MENU:"+"1.Cities available"));//Send client the menu message.
                               ps.println(new StringBuffer("MENU:"+"2.Book a room"));//Send client the menu message.	
            	               ps.println(new StringBuffer("MENU:"+"3.About us"));
            	               ps.println(new StringBuffer("MENU:"+"4.Hotel Vacancy Request"));
            	               ps.println(new StringBuffer("MENU:"+"5.Hotels available"));
            	               ps.println(new StringBuffer("MENU:"+"----------------------------"));//Send client the menu message.
            	               ps.flush();		
            	            }	
            	            
            	            continue;
                    	}
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////                  
                        if(keyword.equals("4"))
                        {
                        	ps.println(new StringBuffer("OPTION:" +"Please choose a city:"));
                    		
                    		ArrayList<String>city = getCity();
                            Iterator its = city.iterator();
                    		while(its.hasNext())
                    		{
                    		  ps.println(new StringBuffer("OPTION:" + its.next()));
                    		}
                    		ps.println(new StringBuffer("OPTION:" + "-----------------------"));
            	            ps.flush();
            	            
            	            String userSelectedCity = br.readLine();
            	            
            	            ta.append("User input:" + userSelectedCity + "\n");
            	            if(userSelectedCity != null)
            	            {
            	               ps.println(new StringBuffer("OPTION:" +"Please choose a hotel:"));
            	            	
            	               ArrayList<String> hotelList = getHotel(userSelectedCity);
                    		   Iterator itss = hotelList.iterator();
                    		   
                    		   while(itss.hasNext())
                               {
                    		     ps.println(new StringBuffer("OPTION:" + itss.next()));
                    		     ps.flush();
                    		   }
                    		   ps.println(new StringBuffer("OPTION:" + "-----------------------"));
            	               ps.flush();
            	               
            	               String userSelectedHotel = br.readLine();
            	               if(userSelectedHotel != null)
            	               {
            	               	 ps.println(new StringBuffer("OPTION:" + "Connecting to "+ userSelectedHotel + " hotel database..."));
            	                 ps.flush();
                    		     int port = getPortNumber(userSelectedCity,userSelectedHotel);
                    	         ArrayList<String> room_type = HotelConnector(port,"TYPE");
                    	         //Socket hotel_socket = HotelConnector(port);
                    	         //BufferedReader br_hotel = new BufferedReader(new InputStreamReader(hotel_socket.getInputStream()));
                                 //PrintStream ps_hotel = new PrintStream(hotel_socket.getOutputStream());
                    	         ps.println(new StringBuffer("OPTION:" + "Connection established successfully!"));
                    	         ps.println(new StringBuffer("OPTION:" + "Welcome to " + userSelectedHotel + " hotel..."));
            	                 ps.println(new StringBuffer("OPTION:" + "-----------------------"));
            	                 
            	                 ps.println(new StringBuffer("OPTION:" + "Please select room type:"));
            	                 
            	                 Iterator itsss = room_type.iterator();
            	                 while(itsss.hasNext())
                                 {
                    		       ps.println(new StringBuffer("OPTION:" + itsss.next()));
                    		       ps.println(new StringBuffer("OPTION:" + "-----------------------"));
                    		     }
                    		     //ps.println(new StringBuffer("OPTION:" + "-----------------------"));
            	                 ps.flush();
            	                 
            	                 String userSelectedRoomType = br.readLine();
            	                 
            	                 if(userSelectedRoomType != null)
            	                 {
            	                 	ps.println(new StringBuffer("OPTION:" + "Please wait for processing your request..."));
                      	            ps.println(new StringBuffer("OPTION:" + "-----------------------"));
            	                    ps.flush();
            	                    
            	                    ps.println(new StringBuffer("OPTION:" + "Please input expected check in date..."));
            	                    ps.println(new StringBuffer("OPTION:" + "Format as 2008-08-08"));
            	                    ps.println(new StringBuffer("OPTION:" + "-----------------------"));
            	                    ps.flush();
            	                    
            	                    String userSelectedCheckinDate = br.readLine();
            	                    
            	                    ps.println(new StringBuffer("OPTION:" + "Please input expected check out date..."));
            	                    ps.println(new StringBuffer("OPTION:" + "Format as 2008-08-08"));
            	                    ps.println(new StringBuffer("OPTION:" + "-----------------------"));
            	                    ps.flush();
            	                    
            	                    String userSelectedCheckoutDate = br.readLine();
            	                    
            	                    String availabilityResult = checkAvailability(port,userSelectedRoomType,userSelectedCheckinDate,userSelectedCheckoutDate);
            	                    if(availabilityResult.equals("SUCCESS"))
            	                    {
            	                    	ps.println(new StringBuffer("OPTION:" + "congratulation.Query succeed."));
            	                        ps.println(new StringBuffer("OPTION:" + "-----------------------"));
            	                        ps.println(new StringBuffer("OPTION:" + "Input 0 to go back to the menu"));
            	                        ps.println(new StringBuffer("OPTION:" + "-----------------------"));
            	                        ps.flush();
            	                        
            	                        String userInput = br.readLine();
            	                        
            	                        if(userInput != null)
            	                        {
            	                        	ps.println(new StringBuffer("MENU:"+"1.Cities available"));//Send client the menu message.
                                            ps.println(new StringBuffer("MENU:"+"2.Book a room"));//Send client the menu message.	
            	                            ps.println(new StringBuffer("MENU:"+"3.About us"));
            	                            ps.println(new StringBuffer("MENU:"+"4.Hotel Vacancy Request"));
            	                            ps.println(new StringBuffer("MENU:"+"5.Hotels available"));
            	                            ps.println(new StringBuffer("MENU:"+"----------------------------"));//Send client the menu message.
            	                            ps.flush();
            	                        }
            	                    }
            	                    else if(availabilityResult.equals("FAILURE"))
            	                         {
            	                         	ps.println(new StringBuffer("OPTION:" + "Sorry,no room is available based on information you provided.."));
            	                            ps.println(new StringBuffer("OPTION:" + "-----------------------"));
            	                            ps.println(new StringBuffer("OPTION:" + "Input 0 to go back to the menu"));
            	                            ps.println(new StringBuffer("OPTION:" + "-----------------------"));
            	                            ps.flush();
            	                            
            	                            String userInput1 = br.readLine();
            	                            String userInput = br.readLine();
            	                        
            	                            if(userInput1 != null)
            	                            {
            	                        	   ps.println(new StringBuffer("MENU:"+"1.Cities available"));//Send client the menu message.
                                               ps.println(new StringBuffer("MENU:"+"2.Book a room"));//Send client the menu message.	
            	                               ps.println(new StringBuffer("MENU:"+"3.About us"));
            	                               ps.println(new StringBuffer("MENU:"+"4.Hotel Vacancy Request"));
            	                               ps.println(new StringBuffer("MENU:"+"5.Hotels available"));
            	                               ps.println(new StringBuffer("MENU:"+"----------------------------"));//Send client the menu message.
            	                               ps.flush();
            	                            }
            	                         }
            	                 } //if(userSelectedRoomType != null)
            	               } // if(userSelectedHotel != null)
            	            } //if(userSelectedCity != null)
                          continue;
                        } //if(keyword.equals("4"))
                        
                        if(keyword.equals("5"))
                        {
                        	ps.println(new StringBuffer("OPTION:" +"Please choose a city:"));
                    		
                    		ArrayList<String>city = getCity();
                            Iterator its = city.iterator();
                    		while(its.hasNext())
                    		{
                    		  ps.println(new StringBuffer("OPTION:" + its.next()));
                    		}
                    		ps.println(new StringBuffer("OPTION:" + "-----------------------"));
            	            ps.flush();
            	            
            	            String userSelectedCity = br.readLine();
            	            
            	            ta.append("User input:" + userSelectedCity + "\n");
            	            if(userSelectedCity != null)
            	            {
            	               ps.println(new StringBuffer("OPTION:" +"Please choose a hotel:"));
            	            	
            	               ArrayList<String> hotelList = getHotel(userSelectedCity);
                    		   Iterator itss = hotelList.iterator();
                    		   
                    		   while(itss.hasNext())
                               {
                    		     ps.println(new StringBuffer("OPTION:" + itss.next()));
                    		     ps.flush();
                    		   }
                    		   ps.println(new StringBuffer("OPTION:" + "-----------------------"));
                    		   ps.println(new StringBuffer("OPTION:" +"Input 0 to go back to maim menu.."));
            	               ps.flush();
            	               
            	               String userDecision = br.readLine();
            	               
            	               if(userDecision != null)
            	               {
            	               	 ps.println(new StringBuffer("MENU:"+"1.Cities available"));//Send client the menu message.
                                 ps.println(new StringBuffer("MENU:"+"2.Book a room"));//Send client the menu message.	
            	                 ps.println(new StringBuffer("MENU:"+"3.About us"));
            	                 ps.println(new StringBuffer("MENU:"+"4.Hotel Vacancy Request"));
            	                 ps.println(new StringBuffer("MENU:"+"5.Hotels available"));
            	                 ps.println(new StringBuffer("MENU:"+"----------------------------"));//Send client the menu message.
            	                 ps.flush();
            	               } //if(userDecision != null)
            	            } //if(userSelectedCity != null)
                          continue;
                        } //if(keyword.equals("5"))
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////                               

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -