Advertisement
ralitsa_d

MasterHerbalist

Feb 23rd, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class MasterHerbalist {
  4. public static void main(String[] args) {
  5. Scanner scan = new Scanner(System.in);
  6.  
  7. Double expenses = Double.parseDouble(scan.nextLine());
  8.  
  9. int days = 0;
  10. double income = 0.0;
  11.  
  12. while (true){
  13. int herbs = 0;
  14.  
  15. String input = scan.nextLine();
  16. if (input.equals("Season Over")) break;
  17.  
  18. String[] arr = input.split("\\s+");
  19.  
  20. int hours = Integer.parseInt(arr[0]);
  21. String path = arr[1];
  22. Double price = Double.parseDouble(arr[2]);
  23.  
  24. for (int i = 0; i < hours; i++) {
  25. char location = path.charAt(i % path.length());
  26. if (location == 'H'){
  27. herbs++;
  28. }
  29. }
  30.  
  31. days++;
  32. income += price * herbs;
  33. }
  34.  
  35. double averageIncome = income / days;
  36.  
  37. if (averageIncome >= expenses){
  38. System.out.printf("Times are good. Extra money per day: %.2f.",
  39. averageIncome - expenses);
  40. }
  41. else{
  42. double moneyNeeded = days * expenses - income;
  43. System.out.printf("We are in the red. Money needed: %.2f.", moneyNeeded);
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement