EmiliaKitkarska

HOMEWORK3

Dec 5th, 2019
130
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. class Main {
  4. public static void main(String[] args) {
  5. Scanner scan = new Scanner(System.in);
  6.  
  7.  
  8. double age = Integer.parseInt(scan.nextLine());
  9. String gander = scan.nextLine();
  10.  
  11. if (age<16) {
  12. if (gander.equals("m")){
  13. System.out.println("Master");
  14. } else if (gander.equals("f")){
  15. System.out.println("Miss");
  16. }
  17. } else if(age>=16) {
  18. if (gander.equals("m")){
  19. System.out.println("Mr.");
  20. } else if (gander.equals("f")){
  21. System.out.println("Ms.");
  22. }
  23. }
  24.  
  25.  
  26. }
  27. }
  28. 2. квартално магазинче
  29. package upr;
  30. import java.util.Scanner;
  31.  
  32. public class homework {
  33. public static void main (String[] args){
  34. Scanner scan = new Scanner(System.in);
  35. String product = scan.nextLine();
  36. String town = scan.nextLine();
  37. double quantity = Double.parseDouble(scan.nextLine());
  38. double price = 0;
  39.  
  40.  
  41. if(town.equals("sofia")) {
  42. if(product.equals("coffe")) {
  43. price = quantity * 0.5;
  44. }else if(product.equals("water")) {
  45. price = quantity * 0.8;
  46. }else if(product.equals("beer")) {
  47. price = quantity * 1.2;
  48. }else if(product.equals("sweets")) {
  49. price = quantity * 1.45;
  50. }else if(product.equals("peanuts")) {
  51. price = quantity * 1.6;
  52. }
  53. }else if(town.equals("plovdiv")) {
  54. if (product.equals("coffe")) {
  55. price = quantity * 0.4;
  56. }else if(product.equals("water")) {
  57. price = quantity * 0.7;
  58. }else if(product.equals("beer")) {
  59. price = quantity * 1.15;
  60. }else if(product.equals("sweets")) {
  61. price = quantity * 1.3;
  62. }else if(product.equals("peanuts")) {
  63. price = quantity * 1.5;
  64. }
  65. }else if(town.equals("varna")) {
  66. if (product.equals("coffe")) {
  67. price = quantity * 0.45;
  68. }else if(product.equals("water")) {
  69. price = quantity * 0.7;
  70. }else if(product.equals("beer")) {
  71. price = quantity * 1.1;
  72. }else if(product.equals("sweets")) {
  73. price = quantity * 1.35;
  74. }else if(product.equals("peanuts")) {
  75. price = quantity * 1.55;
  76. }
  77. }
  78. System.out.println(price);
  79. }
  80.  
  81. }
  82. 3. плод или зеленчук
  83. package upr;
  84. import java.util.Scanner;
  85.  
  86. public class home1 {
  87. public static void main(String[] args) {
  88. Scanner scan = new Scanner(System.in);
  89. String product = scan.nextLine();
  90.  
  91. boolean isFruit = product.equals("banana") || product.equals("apple") || product.equals("kiwi") ||
  92. product.equals("cherry") || product.equals("lemon") || product.equals("grapes");
  93.  
  94. boolean isVegetable = product.endsWith("tomato") || product.equals("cucumber") || product.equals("pepper") ||
  95. product.equals("carrot");
  96.  
  97. if(isFruit) {
  98. System.out.println("fruit");
  99. }else if(isVegetable) {
  100. System.out.println("vegetable");
  101. }else {
  102. System.out.println("unknown");
  103. }
  104. }
  105. }
  106.  
  107.  
  108. 4. Невалидно число
  109. package upr;
  110. import java.util.Scanner;
  111.  
  112. public class hm {
  113. public static void main(String[] args) {
  114. Scanner scan = new Scanner(System.in);
  115. double number = scan.nextInt();
  116. boolean isInRange = (number >= 100 && number <= 200) || number == 0;
  117.  
  118. if (!isInRange) {
  119. System.out.println("invalid");
  120. }
  121.  
  122.  
  123.  
  124. }
  125.  
  126.  
  127. }
  128.  
  129. 5.Магазин за плодове
  130. package upr;
  131. import java.util.Scanner;
  132.  
  133. public class hm {
  134. public static void main(String[] args) {
  135. Scanner scan = new Scanner(System.in);
  136. String fruit = scan.nextLine();
  137. String day = scan.nextLine();
  138. double quantity = Double.parseDouble(scan.nextLine());
  139. double price = 0;
  140.  
  141. if(day.equals("monday") || day.equals("tyesday") || day.equals("wednesday")
  142. || day.equals("thursday") || day.equals("friday")) {
  143.  
  144. if (fruit.equals("banana")) {
  145. price = quantity * 2.5;
  146. }else if(fruit.equals("apple")) {
  147. price = quantity * 1.2;
  148. }else if(fruit.equals("orange")) {
  149. price = quantity * 0.85;
  150. }else if(fruit.equals("grapefruit")) {
  151. price = quantity * 1.45;
  152. }else if(fruit.equals("kiwi")) {
  153. price = quantity * 2.7;
  154. }else if(fruit.equals("pineapple")) {
  155. price = quantity * 5.5;
  156. }else if(fruit.equals("grapes")) {
  157. price = quantity * 3.85;
  158. }
  159. }else if(day.equals("saturday") || day.equals("sunday")) {
  160.  
  161. if (fruit.equals("banana")) {
  162. price = quantity * 2.7;
  163. }else if(fruit.equals("apple")) {
  164. price = quantity * 1.25;
  165. }else if(fruit.equals("orange")) {
  166. price = quantity * 0.9;
  167. }else if(fruit.equals("grapefruit")) {
  168. price = quantity * 1.6;
  169. }else if(fruit.equals("kiwi")) {
  170. price = quantity * 3;
  171. }else if(fruit.equals("pineapple")) {
  172. price = quantity * 5.6;
  173. }else if(fruit.equals("grapes")) {
  174. price = quantity * 4.2;
  175. }
  176.  
  177.  
  178. }
  179.  
  180. System.out.println(price);
  181. }
  182.  
  183.  
  184. }
  185.  
  186. 6.Ден от седмицата
  187. package upr;
  188. import java.util.Scanner;
  189.  
  190. public class hm {
  191. public static void main(String[] args) {
  192. Scanner scan = new Scanner(System.in);
  193. int day = Integer.parseInt(scan.nextLine());
  194.  
  195. switch (day) {
  196. case 1:
  197. System.out.println("Monday");
  198. break;
  199. case 2:
  200. System.out.println("Tuesday");
  201. break;
  202. case 3:
  203. System.out.println("Wednesday");
  204. break;
  205. case 4:
  206. System.out.println("Thursday");
  207. break;
  208. case 5:
  209. System.out.println("Friday");
  210. break;
  211. case 6:
  212. System.out.println("Saturday");
  213. break;
  214. case 7:
  215. System.out.println("Sunday");
  216. break;
  217. default:
  218. System.out.println("error");
  219. break;
  220. }
  221. }
  222. }
RAW Paste Data