Advertisement
ralitsa_d

PassionDays

Feb 23rd, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class PassionDays {
  4.  
  5. public static void main(String[] args) {
  6. Scanner scan = new Scanner(System.in);
  7.  
  8. Double money = Double.parseDouble(scan.nextLine());
  9.  
  10. while (true){
  11. String data = scan.nextLine();
  12. if (data.equals("mall.Enter")) break;
  13. }
  14.  
  15. String input = scan.nextLine();
  16.  
  17. int purchases = 0;
  18.  
  19. while (!input.equals("mall.Exit")){
  20.  
  21. for (int i = 0; i < input.length(); i++) {
  22. char action = input.charAt(i);
  23.  
  24. double price;
  25. if (Character.isUpperCase(action)){
  26. price = action / 2.0;
  27. }
  28. else if (Character.isLowerCase(action)){
  29. price = action * 0.3;
  30. }
  31. else if (action == '%'){
  32. price = money / 2.0;
  33. }
  34. else if (action == '*'){
  35. price = -10;
  36. }
  37. else{ // everything else
  38. price = action;
  39. }
  40.  
  41. if (price <= money){
  42. money -= price;
  43. if (action != '*'){
  44. purchases++;
  45. }
  46. System.out.println(price);
  47. System.out.println("Money " + money);
  48. System.out.println("Purchases: " + purchases);
  49. }
  50. else {
  51. System.out.println("no purchase");
  52. }
  53.  
  54. // if (price <= money && action != '*'){
  55. // money -= price;
  56. // purchases++;
  57. // }
  58. // else if (action == '*'){
  59. // money += 10;
  60. // }
  61. }
  62. input = scan.nextLine();
  63. }
  64.  
  65. System.out.printf("%s purchases. Money left: %.2f lv.",
  66. purchases, money);
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement