I am trying to rewrite my code without a conditional statement and loop. My code is written based on the instruction like this, but additionally without loop and conditional statement
A program that take input as start month and day to end month and day and
calculate total price.
Supposed inputs are always correct.
Input range is same year January 1 to Dec 31
January 1/1 is Monday.
Input start day is always Monday
Even month consists of 31 days , Odd month consists of 30 days
For price Weekday -> $2
Sat -> $3
Sun -> $5
If customer book over 50 days, price is going to get flat to $1
public class test {
int startMonth;
int startDay;
int endMonth;
int endDay;
int totalDate;
public test (int startMonth, int startDay, int endMonth, int endDay) {
this.endMonth = endMonth;
this.endDay = endDay;
this.startMonth = startMonth;
this.startDay = startDay;
}
public int getPrice() {
getTotalDate();
int price = 0;
int discount = totalDate > 50 ? totalDate - 50 : 0;
System.out.println("discount " + discount);
totalDate = totalDate > 50 ? 50 : totalDate % 50;
System.out.println("totalData : " + totalDate);
int sunDay = totalDate/7;
int satDay = totalDate/7 + (totalDate%7)/6;
int weekDay = totalDate - sunDay - satDay;
price+= sunDay*5 + satDay*3 + weekDay*2;
return price + discount;
}
public int getTotalDate() {
int gapOfMonth = endMonth - startMonth;
totalDate = gapOfMonth*30 + (gapOfMonth +1)/2 + (endDay - startDay);
return totalDate;
}
public static void main (String[] args) {
test t = new test(1,1,2,30);
System.out.println("test");
System.out.println(t.getPrice());
}
}