-3

酒店管理

一家著名的酒店在迈阿密拥有三个分店。即x,y和z(实际上他们给了名字)。每个人都有两种类型的客户。定期和受奖者。此外,每个分支都有自己的评级,x 获得 3 星评级,y 获得 5 星评级,z 获得 4 星评级。

每家酒店都有周末和工作日的具体价格。x 平日对普通客户收取 100 美元,周末收取 120 美元,而平日对受奖者收取 90 美元,周末收取 60 美元。同样,y 平日向常客收取 130 美元,周末收取 150 美元。平日为 100 美元,周末为 95 美元。而 z 在工作日对普通客户收取 195 美元,在周末收取 150 美元。平日为 120 美元,周末为 90 美元。现在,当客户要求特定细节时,您需要找到哪家酒店会为客户带来利润。如果酒店之间出现平局,请比较评级并提供结果。

输入格式:

常规:2010 年 3 月 16 日(周日)、2010 年 3 月 19 日(周三)、2010 年 3 月 21 日(周五)

我已经制作了这段代码......请告诉我我是否朝着正确的方向前进。还有我怎样才能使酒店价格动态

getTheday = function(aText,typeofcustomer)
    {

        this.typeofcustomer = typeofcustomer;
        myDays = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
        if(new Date(aText).getDay() == 0 || new Date(aText).getDay() == 5 || new Date(aText).getDay() == 6)
        {
            console.log("its weekend!!!");
            this.weekend(this.typeofcustomer);
        }

        console.log("it is ", myDays[new Date(aText).getDay()]);

    }

    getTheday.prototype.weekend = function(typeofcustomer)
    {
        console.log(typeofcustomer);
        this.hoteloptionsforweekend();
    }

    getTheday.prototype.hoteloptionsforweekend = function()
    {

        if(this.typeofcustomer == "rewardee")
        {
            this.hotelpricex_ = 60;
            this.hotelpricey_ = 95;
            this.hotelpricez_ = 90;
            this.minhotelprice = Math.min(this.hotelpricex_, this.hotelpricey_, this.hotelpricez_)

            console.log("min price is of hotel", this.minhotelprice);

        }

        if(this.typeofcustomer == "regular")
        {
            this.hotelpricex_ = 120;
            this.hotelpricey_ = 150;
            this.hotelpricez_ = 150;

        }

    }
4

1 回答 1

1
// Put your price listings outside of the constructor
// so that you could fetch them from somewhere else
// later
var hotelPrices = [
        {
            name:    'Hotel X',
            daily:   { regular: 120, rewardee: 60 },
            weekend: { regular: 140, rewardee: 70 }
        },
        {
            name:    'Hotel Y',
            daily:   { regular: 150, rewardee: 95 },
            weekend: { regular: 180, rewardee: 110 }
        },
        {
            name:    'Hotel Z',
            daily:   { regular: 150, rewardee: 90 },
            weekend: { regular: 180, rewardee: 110 }
        }
    ];

// Be consistent and use correct camelCase for naming.
// And, btw, `getTheDay` name is misleading and confusing.
getTheDay = function( aText, typeOfCustomer, prices ) {
    var day = ( new Date( aText ) ).getDay();

    this.typeOfCustomer = typeOfCustomer;
    this.prices = prices;

    // isWeekend is a Boolean, indicating whether the date passed
    // is a weekend. 
    this.isWeekend = day == 0 || day == 5 || day == 6;
};

getTheDay.prototype.getMinimumPrice = function() {
    var prices = [],
        i, len;

    for( i = 0, len = this.prices.length; i < len; i += 1 ) {
        // Taking the appropriate price from the price list
        // and moving it to the new list
        prices.push( this.prices[i][ this.isWeekend ? 'weekend' : 'daily' ][ this.typeOfCustomer ] )
    }

    // A small trick to feed Math.min an array
    // instead of a list of arguments
    return Math.min.apply( Math, prices );
};

// Example usage:
var hotelRates = new getTheDay( aText, typeOfCustomer, hotelPrices );
console.log( hotelRates.getMinimumPrice() );

现在您的主要任务是创建一个返回最便宜酒店名称的方法。DailyJS 上正在发布一系列适合 JavaScript 初学者的好文章:JS 101

于 2012-06-28T19:46:13.313 回答