找個簡單的:
網(wǎng)站建設(shè)哪家好,找成都創(chuàng)新互聯(lián)!專注于網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、微信小程序、集團企業(yè)網(wǎng)站建設(shè)等服務(wù)項目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了保山免費建站歡迎大家使用!
import?java.util.Scanner;
public?class?a1{
public?static?void?main(String[]?args){
Scanner?s?=?new?Scanner(System.in);//接受客戶鍵盤輸入,在命令行中,回車結(jié)束
System.out.println(?"酒店管理系統(tǒng)"?);
Hotel?h?=?new?Hotel();
System.out.println(?h?);
h.print();
while?(true){
System.out.println(?"請輸入房間編號"?);
//聲明變量,用于接受控制臺輸入數(shù)據(jù)
String?no?=?s.next();
//預(yù)訂房間
h.order(no);
h.print();
}
}
}
class?Room{
//房間號
private?String?no;
//房間類型
private?String?type;
//是否被占用
private?boolean?isUse;
public?Room(){//默認調(diào)用
super();
}
public?Room(String?no,String?type,boolean?isUse){
super();
this.no?=?no;
this.type?=?type;
this.isUse?=?isUse;
}
public?String?getNo(){
return?no;
}
public?void?setNo(String?no){
this.no?=?no;
}
public?String?getType(){
return?type;
}
public?void?setType(String?type){
this.type?=?type;
}
public?boolean?isUse(){
return?isUse;
}
public?void?setUse(boolean?isUse){
this.isUse?=?isUse;
}
public?String?toString(){??//聲明輸出結(jié)果格式
return?"["?+?no?+?","?+?type?+?","?+?(isUse?"占用":"空閑")?+?"]";
}
}
class?Hotel{
Room?rooms[][];
public?Hotel(){
rooms?=?new?Room[5][4];//旅館有五層,每層四個房間
for(int?i=0;?i??rooms.length;?++i){//外層for循環(huán)是循環(huán)層,內(nèi)存循環(huán)是循環(huán)的每層的房間
for(int?j=0;?j??rooms[i].length;?++j){
if?(i?==?0?||?i?==?1)?{
//后面加個空字符串,是自動數(shù)據(jù)類型轉(zhuǎn)換,這樣前面的數(shù)字會自動變成數(shù)字型字符串;
rooms[i][j]?=?new?Room((i+1)*100+j+1?+""?,?"標(biāo)準間",false);
}
if?(i?==?2?||?i?==?3)?{
rooms[i][j]?=?new?Room((i+1)*100+j+1?+""?,?"雙人間",false);?
}
if?(i?==?4)?{
rooms[i][j]?=?new?Room((i+1)*100+j+1?+""?,?"豪華間",false);?
}
}
}
}
//對外提供房間列表的打印方式
public?void?print(){
for(int?i=0;?i??rooms.length;?++i){
for(int?j=0;?j??rooms[i].length;?++j){
System.out.print(?rooms[i][j]?+?"?"?);
}
//換行
System.out.println(??);
}
}
//提供旅館對外預(yù)定方式
public?void?order(String?no){
for(int?i=0;?i??rooms.length;?++i){
for(int?j=0;?j??rooms[i].length;?++j){
if?(rooms[i][j].getNo().equals(no))?{
//把對象的成員數(shù)據(jù)封裝,通過成員方法訪問
//1?成員變量的訪問方式rooms[i][j].no;
//2?成員方法的訪問方式
rooms[i][j].setUse(true);
return;
}
}
}
}
}
帶數(shù)據(jù)庫的就算了
//1.定義抽象類Room
public abstract class Room {
//定義抽象方法
public void roomCost(int days){ };
}
//2.定義子類Single
public class Single extends Room {
private String bedNo;//定義屬性床號
private Boolean isAirConditioning=true;//定義是否為空調(diào)房
private double roomPrice = 100.00;//定義非空調(diào)房基準價位屬性
//計算房價方法
public void roomCost(int days){
//當(dāng)是空調(diào)房進入if語句體,非空調(diào)房進入else語句體。
if(isAirConditioning){
roomPrice += days*10.00;
System.out.println("您的房間號為:"+getBedNo()+"號為空調(diào)房您的住宿費用如下:");
System.out.print(roomPrice);
System.out.print("人民幣");
}else{
System.out.println("您的房間號為:"+getBedNo()+"號住宿費用如下:");
System.out.print(roomPrice);
System.out.print("人民幣");
}
}
public String getBedNo() {
return bedNo;
}
public void setBedNo(String bedNo) {
this.bedNo = bedNo;
}
public double getRoomPrice() {
return roomPrice;
}
public void setRoomPrice(double roomPrice) {
this.roomPrice = roomPrice;
}
public static void main(String[] args) {
Single sg = new Single();
//給的房間為空調(diào)房
sg.isAirConditioning=true;
//給房間號值
sg.bedNo = "3102";
//執(zhí)行房間計費方法
sg.roomCost(3);
}
}
酒店類
package fdsa;
public class Hotel {
private String hotelID;
private String hotelName;
private String hoteladdess;
public String getHotelID() {
return hotelID;
}
public void setHotelID(String hotelID) {
this.hotelID = hotelID;
}
public String getHotelName() {
return hotelName;
}
public void setHotelName(String hotelName) {
this.hotelName = hotelName;
}
public String getHoteladdess() {
return hoteladdess;
}
public void setHoteladdess(String hoteladdess) {
this.hoteladdess = hoteladdess;
}
public String getHotelPhone() {
return hotelPhone;
}
public void setHotelPhone(String hotelPhone) {
this.hotelPhone = hotelPhone;
}
private String hotelPhone;
}
客戶類
public class Client{
private String clientName;
private String clientID;
public String getClientName() {
return clientName;
}
public void setClientName(String clientName) {
this.clientName = clientName;
}
public String getClientID() {
return clientID;
}
public void setClientID(String clientID) {
this.clientID = clientID;
}
}
房間類
public class Room{
private String roomID;
private Hotel hotelID;
public String getRoomID() {
return roomID;
}
public void setRoomID(String roomID) {
this.roomID = roomID;
}
public Hotel getHotelID() {
return hotelID;
}
public void setHotelID(Hotel hotelID) {
this.hotelID = hotelID;
}
public String getRoomAmount() {
return roomAmount;
}
public void setRoomAmount(String roomAmount) {
this.roomAmount = roomAmount;
}
private String roomAmount;
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("是否是會員?y/n");
String H = input.next();
System.out.println("請輸入入住日期:");
System.out.println("例如2009-03-16");
String in = input.next();
System.out.println("請輸離開日期:");
System.out.println("例如2009-03-16");
String out = input.next();
//String in = s.substring(5,15);
//String out = s.substring(15,26);
//System.out.println(in+" "+out);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c1 = Calendar.getInstance();
Calendar c2 = Calendar.getInstance();
try {
c1.setTime(sdf.parse(in));
c2.setTime(sdf.parse(out));
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
long time1 = c1.getTimeInMillis();
long time2 = c2.getTimeInMillis();
long tian = (time2-time1)/(1000*24*3600);
long tian1 = tian;
System.out.println("tian "+tian);
int week1 = c1.get(Calendar.DAY_OF_WEEK)-1;
//System.out.println(week1);
//int week2 = c2.get(Calendar.DAY_OF_WEEK)-1;
//System.out.println(week2);
int count = 0;
while(tian10){
if(week1 == 6 || week1==0){
count++;
}
if(week1==6){
week1 = 0;
week1--;
}
tian1--;
week1++;
}
System.out.println("count "+count);
long rujia;
long qitian;
long hanting;
if(H.equals("y")){
rujia = (tian-count)*80+count*80;
System.out.println("tian "+tian);
qitian = (tian-count)*110+count*50;
hanting = (tian-count)*100+count*40;
}else{
rujia = (tian-count)*110+count*90;
qitian = (tian-count)*160+count*60;
hanting = (tian-count)*220+count*150;
}
System.out.println("tian " + tian);
System.out.println("rujia "+rujia);
System.out.println("hanting "+hanting);
System.out.println("qitian "+qitian);
if(rujiaqitian rujiahanting){
System.out.println("如家");
}else if(qitianrujia qitianhanting){
System.out.println("七天");
}else if(hantingrujia hantingqitian){
System.out.println("漢庭");
}else if(hanting==rujia || hanting==qitian){
System.out.println("漢庭");
}else if(qitian==rujia qitianhanting){
System.out.println("七天");
}
}
我沒怎么測試 自己測測吧 還有一些約束用戶輸入啥的 嚴謹性什么的
本文題目:酒店房間預(yù)定Java代碼 酒店房間預(yù)定java代碼是多少
鏈接分享:http://jinyejixie.com/article16/dosgjgg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、移動網(wǎng)站建設(shè)、網(wǎng)站策劃、電子商務(wù)、面包屑導(dǎo)航、手機網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)