Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Main.java
- package hotel;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- //"{pricePerDay} {numberOfDays} {season} {discountType}"
- String input = scanner.nextLine();
- String [] splittedInput = input.split("\\s+");
- //["{pricePerDay}", "{numberOfDays}", "{season}", "{discountType}"]
- double pricePerDay = Double.parseDouble(splittedInput[0]);
- int numberOfDays = Integer.parseInt(splittedInput[1]);
- Season season = Season.valueOf(splittedInput[2].toUpperCase()); //"Summer" -> "SUMMER"
- DiscountType discountType = DiscountType.valueOf(splittedInput[3].toUpperCase()); //"SecondVisit" -> "SECONDVISIT"
- double holidayPrice = PriceCalculator.calculateHolidayPrice(pricePerDay, numberOfDays, season, discountType);
- System.out.printf("%.2f", holidayPrice);
- }
- }
- PriceCalculator.java
- package hotel;
- public class PriceCalculator {
- public static double calculateHolidayPrice (double pricePerDay, int days, Season season, DiscountType discountType) {
- //сума за всички дни
- double priceForAllDays = pricePerDay * days;
- //умножение спрямо сезона
- priceForAllDays *= season.getMultiplyCoefficient();
- //отстъпка
- priceForAllDays = priceForAllDays - priceForAllDays * (discountType.getPercent() / 100);
- return priceForAllDays;
- }
- }
- Season.java
- package hotel;
- public enum Season {
- //4 сезона -> 4 константни обекта
- SUMMER(4),
- AUTUMN(1),
- WINTER(3),
- SPRING(2);
- private int multiplyCoefficient;
- Season(int multiplyCoefficient) {
- this.multiplyCoefficient = multiplyCoefficient;
- }
- public int getMultiplyCoefficient() {
- return multiplyCoefficient;
- }
- public void setMultiplyCoefficient(int multiplyCoefficient) {
- this.multiplyCoefficient = multiplyCoefficient;
- }
- }
- DiscountType.java
- package hotel;
- public enum DiscountType {
- NONE(0),
- SECONDVISIT(10),
- VIP(20);
- private double percent;
- DiscountType(double percent) {
- this.percent = percent;
- }
- public double getPercent() {
- return percent;
- }
- public void setPercent(double percent) {
- this.percent = percent;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement