Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package exams.june2016;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.math.BigDecimal;
- import java.util.Arrays;
- import java.util.Calendar;
- import java.util.GregorianCalendar;
- public class P02_SoftUniCoffeeOrders {
- public static void main(String[] args) throws IOException {
- BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
- int n = Integer.parseInt(reader.readLine());
- //double allPrices = 0;
- BigDecimal allPrices = new BigDecimal("0.0");
- for (int i = 0; i < n; i++) {
- BigDecimal priceCoffee = new BigDecimal(reader.readLine());
- int[] date = Arrays.stream(reader.readLine().split("/"))
- .mapToInt(Integer::parseInt)
- .toArray();
- long countCoffee = Long.parseLong(reader.readLine());
- int day = date[0];
- // int month = date[1] - 1;
- int month = date[1];
- int year = date[2];
- // Calendar myCal = new GregorianCalendar(year, month, day);
- // int daysInMonth = myCal.getActualMaximum(Calendar.DAY_OF_MONTH);
- int daysInMonth = getDays(month, year);
- //double priceMonthCoffee = (daysInMonth * countCoffee) * priceCoffee;
- long coffeeForMonth = daysInMonth * countCoffee;
- BigDecimal coffeeForMonthBig = new BigDecimal(coffeeForMonth);
- BigDecimal priceMonthCoffee = coffeeForMonthBig.multiply(priceCoffee);
- System.out.printf("The price for the coffee is: $%.2f%n", priceMonthCoffee);
- //allPrices = allPrices + priceMonthCoffee;
- allPrices = allPrices.add(priceMonthCoffee);
- }
- System.out.printf("Total: $%.2f", allPrices);
- }
- public static int getDays (int month, int year) {
- int numberOfDays = 0;
- switch (month) {
- case 1:
- numberOfDays = 31;
- break;
- case 2:
- if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0))) {
- numberOfDays = 29;
- } else {
- numberOfDays = 28;
- }
- break;
- case 3:
- numberOfDays = 31;
- break;
- case 4:
- numberOfDays = 30;
- break;
- case 5:
- numberOfDays = 31;
- break;
- case 6:
- numberOfDays = 30;
- break;
- case 7:
- numberOfDays = 31;
- break;
- case 8:
- numberOfDays = 31;
- break;
- case 9:
- numberOfDays = 30;
- break;
- case 10:
- numberOfDays = 31;
- break;
- case 11:
- numberOfDays = 30;
- break;
- case 12:
- numberOfDays = 31;
- break;
- }
- return numberOfDays;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment