I am learning java and I successfully wrote one small console application. I would love to get reviews and possible bug sources on my code. I'm particularly concerned with my object structure.
Question
A well renowned hotel has three branches in Miami. Namely x,y and z. Each has two types of customers: Regular and Rewardee. Also each branch has its own ratings x is given a 3 star rating while y has 5 star rating and z has 4 star rating.
Each hotel has specific rates for weekend and weekdays. x charges $100 for regular customers on weekdays and $120 on weekends While it is $90 for rewardee on weekdays and $60 on weekends. Similarly y charges $130 for regular customers on weekdays and $150 on weekends. While its $100 for rewardee on weekdays and $95 on weekends. While z charges $195 for regular customers on weekdays and $150 on weekends. While its $120 for rewardee on weekdays and $90 on weekends. Now when the customer requests for a particular detail you need to find which hotel would yield the customer profit. In case of tie between hotels compare the ratings and provide the result.
Input format:
regular: 16Mar2010(sun), 19Mar2010(wed), 21Mar2010(Fri)
Output format:
320 410 540 LakeWood
Solution:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
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;
}
}
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();
x = new HotelFactory("LakeWood");
x.setRegularWeekDay(100);
x.setRegularWeekEnd(120);
x.setRewardeeWeekDay(90);
x.setRewardeeWeekEnd(60);
y = new HotelFactory("RidgeWood");
y.setRegularWeekDay(130);
y.setRegularWeekEnd(150);
y.setRewardeeWeekDay(100);
y.setRewardeeWeekEnd(95);
z = new HotelFactory("BridgeWood");
z.setRegularWeekDay(195);
z.setRegularWeekEnd(150);
z.setRewardeeWeekDay(120);
z.setRewardeeWeekEnd(90);
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);
}
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();
}
}
}