Please help me make this code more object oriented. I also want to use a few more classes and separate the input processing code to another class.
Question:
A hotel chain operating in Goa wishes to offer room reservation services. They have three hotels in Goa: GreenValley, RedRiver and BlueHills. Each hotel has separate weekday and weekend (Saturday and Sunday) rates. There are special rates for rewards customer as a part of loyalty program.Each hotel has a rating assigned to it.
- GreenValley with a rating of 3 has weekday rates as Rs1100 for regular customer and Rs800 for rewards customer. The weekend rates are 900 for regular customer and 800 for a rewards customer.
- RedRiver with a rating of 4 has weekday rates as Rs1600 for regular customer and Rs1100 for rewards customer. The weekend rates are 600 for regular customer and 500 for a rewards customer.
- BlueHills with a rating of 5 has weekday rates as Rs2200 for regular customer and Rs1000 for rewards customer. The weekend rates are 1500 for regular customer and 400 for a rewards customer.
The input to the program will be a range of dates for a regular or rewards customer. The output should be the cheapest available hotel. In case of a tie, the hotel with highest rating should be returned.
Example to the input format:
Regular:
16Mar2009(mon), 17Mar2009(tues), 18Mar2009(wed)
Output:
GreenValley
HotelFactory.java:
package org.dipankar.java;
public class HotelFactory {
String hotelName;
private int regularWeekDay;
private int regularWeekEnd;
private int rewardeeWeekDay;
private int rewardeeWeekEnd;
HotelFactory(String name) {
this.hotelName = name;
}
public int getRegularWeekDay() {
return regularWeekDay;
}
public void setRegularWeekDay(int regularWeekDay) {
this.regularWeekDay = regularWeekDay;
}
public int getRegularWeekEnd() {
return regularWeekEnd;
}
public void setRegularWeekEnd(int regularWeekEnd) {
this.regularWeekEnd = regularWeekEnd;
}
public int getRewardeeWeekDay() {
return rewardeeWeekDay;
}
public void setRewardeeWeekDay(int rewardeeWeekDay) {
this.rewardeeWeekDay = rewardeeWeekDay;
}
public int getRewardeeWeekEnd() {
return rewardeeWeekEnd;
}
public void setRewardeeWeekEnd(int rewardeeWeekEnd) {
this.rewardeeWeekEnd = rewardeeWeekEnd;
}
public String getHotelName() {
return hotelName;
}
}
TestHotel.java:
package org.dipankar.java;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class TestHotel {
private static HotelFactory x, y, z;
public static void main(String[] args) throws IOException {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String s = bf.readLine();
//setting values for green valley
x = new HotelFactory("Green Valley");
x.setRegularWeekDay(1100);
x.setRegularWeekEnd(900);
x.setRewardeeWeekDay(800);
x.setRewardeeWeekEnd(800);
//setting values for blue hills
y = new HotelFactory("Blue Hills");
y.setRegularWeekDay(2200);
y.setRegularWeekEnd(1500);
y.setRewardeeWeekDay(1000);
y.setRewardeeWeekEnd(400);
//setting values for red river
z = new HotelFactory("Red River");
z.setRegularWeekDay(1600);
z.setRegularWeekEnd(600);
z.setRewardeeWeekDay(1100);
z.setRewardeeWeekEnd(500);
int index = s.indexOf(":");
String type = s.substring(0, index);
int cost_x = 0, cost_y = 0, cost_z = 0;
int day_index_start = 0, day_index_end = 0;
while (day_index_start != -1) {
day_index_start = s.indexOf("(", day_index_start + 1);
day_index_end = s.indexOf(")", day_index_end + 1);
if (day_index_start != -1) {
String day = s.substring(day_index_start + 1, day_index_end);
if (day.equalsIgnoreCase("sun") || day.equalsIgnoreCase("sat")) {
if (type.equalsIgnoreCase("regular")) {
cost_x += x.getRegularWeekEnd();
cost_y += y.getRegularWeekEnd();
cost_z += z.getRegularWeekEnd();
} else {
cost_x += x.getRewardeeWeekEnd();
cost_y += y.getRewardeeWeekEnd();
cost_z += z.getRewardeeWeekEnd();
}
} else {
if (type.equalsIgnoreCase("regular")) {
cost_x += x.getRegularWeekDay();
cost_y += y.getRegularWeekDay();
cost_z += z.getRegularWeekDay();
} else {
cost_x += x.getRewardeeWeekDay();
cost_y += y.getRewardeeWeekDay();
cost_z += z.getRewardeeWeekDay();
}
}
}
}
System.out.println(cost_x);
System.out.println(cost_y);
System.out.println(cost_z);
String result = min(cost_x, cost_y, cost_z);
System.out.println(result);
}
//implementing the min method
private static String min(int a, int b, int c) {
if (a < b && a < c) {
return x.getHotelName();
} else if (b < a && b < c) {
return y.getHotelName();
} else if (c < a && c < b) {
return z.getHotelName();
} else if (a == b || b == c) {
return y.getHotelName();
} else if (c == a) {
return z.getHotelName();
} else {
return x.getHotelName();
}
}
}