Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class MasterHerbalist {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- Double expenses = Double.parseDouble(scan.nextLine());
- int days = 0;
- double income = 0.0;
- while (true){
- int herbs = 0;
- String input = scan.nextLine();
- if (input.equals("Season Over")) break;
- String[] arr = input.split("\\s+");
- int hours = Integer.parseInt(arr[0]);
- String path = arr[1];
- Double price = Double.parseDouble(arr[2]);
- for (int i = 0; i < hours; i++) {
- char location = path.charAt(i % path.length());
- if (location == 'H'){
- herbs++;
- }
- }
- days++;
- income += price * herbs;
- }
- double averageIncome = income / days;
- if (averageIncome >= expenses){
- System.out.printf("Times are good. Extra money per day: %.2f.",
- averageIncome - expenses);
- }
- else{
- double moneyNeeded = days * expenses - income;
- System.out.printf("We are in the red. Money needed: %.2f.", moneyNeeded);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement