teddy-popova

Домашно 4.1

Nov 26th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.40 KB | None | 0 0
  1. 1зад. "Обръщение според възраст и пол":
  2.  
  3. import java.util.Scanner;
  4.  
  5. class Main {
  6. public static void main(String[] args) {
  7. Scanner scan = new Scanner(System.in);
  8.  
  9. String gander = scan.nextLine();
  10. int age = scan.nextInt();
  11.  
  12.  
  13. if (age<16) {
  14. if (gander.equals("male")){
  15. System.out.println("Master");
  16. } else if (gander.equals("female")){
  17. System.out.println("Miss");
  18. }
  19. } else if(age>=16) {
  20. if (gander.equals("male")){
  21. System.out.println("Ms.");
  22. } else if (gander.equals("female")){
  23. System.out.println("Mr.");
  24. }
  25. }
  26.  
  27.  
  28. }
  29. }
  30.  
  31.  
  32. 2зад. "Квартално магазинче":
  33.  
  34. import java.util.Scanner;
  35.  
  36.  
  37. class Main {
  38. public static void main(String[] args) {
  39.  
  40. String product = scan.nextLine() .toLowerCase();
  41. String town = scan.nextLine() .toLowerCase();
  42. double quantity = Double.parseDouble(scan.nextLine());
  43. double price = 0;
  44.  
  45. if (town.equals("sofia")){
  46. if(product.equals("coffee")){
  47. price = quantity * 0.5;
  48. } else if(product.equals("water")){
  49. price = quantity * 0.8;
  50. } else if(product.equals("beer")){
  51. price = quantity * 1.2;
  52. } else if(product.equals("sweets")){
  53. price = quantity * 1.45;
  54. } else if(product.equals("peanuts")){
  55. price = quantity * 1.6;
  56. }
  57. }
  58.  
  59. if (town.equals("plovdiv")){
  60. if(product.equals("coffee")){
  61. price = quantity * 0.4;
  62. } else if(product.equals("water")){
  63. price = quantity * 0.7;
  64. } else if(product.equals("beer")){
  65. price = quantity * 1.15;
  66. } else if(product.equals("sweets")){
  67. price = quantity * 1.3;
  68. } else if(product.equals("peanuts")){
  69. price = quantity * 1.5;
  70. }
  71. }
  72.  
  73. if (town.equals("varna")){
  74. if(product.equals("coffee")){
  75. price = quantity * 0.45;
  76. } else if(product.equals("water")){
  77. price = quantity * 0.7;
  78. } else if(product.equals("beer")){
  79. price = quantity * 1.1;
  80. } else if(product.equals("sweets")){
  81. price = quantity * 1.35;
  82. } else if(product.equals("peanuts")){
  83. price = quantity * 1.55;
  84. }
  85. }
  86.  
  87. System.out.println(price);
  88.  
  89. }
  90. }
  91.  
  92.  
  93. 3зад. "Точка в правоъгълник":
  94.  
  95. import java.util.Scanner;
  96.  
  97. class Main {
  98. public static void main(String[] args) {
  99. Scanner scan = new Scanner(System.in);
  100.  
  101. double x1 = Double.parseDouble(scan.nextLine());
  102. double y1 = Double.parseDouble(scan.nextLine());
  103. double x2 = Double.parseDouble(scan.nextLine());
  104. double y2 = Double.parseDouble(scan.nextLine());
  105. double x = Double.parseDouble(scan.nextLine());
  106. double y = Double.parseDouble(scan.nextLine());
  107.  
  108. if ((x >= x1 && x <= x2) && (y >= y1 && y <= y2)){
  109. System.out.println("Inside");
  110. } else {
  111. System.out.println("Outside");
  112. }
  113.  
  114. }
  115. }
  116.  
  117.  
  118.  
  119. 4зад. "Плод или зеленчук":
  120.  
  121. import java.util.Scanner;
  122.  
  123. class Main {
  124. public static void main(String[] args) {
  125. Scanner scan = new Scanner(System.in);
  126. String product = scan.nextLine();
  127.  
  128. boolean isFruit = product.equals("banana") || product.equals("apple") || product.equals("kiwi") || product.equals("cherry") || product.equals("lemon") || product.equals("grapes");
  129.  
  130. boolean isVegetable = product.equals("tomato") || product.equals("cucumber") || product.equals("pepper") || product.equals("carrot");
  131.  
  132. if (isFruit) {
  133. System.out.println("fruit");
  134. } else if (isVegetable) {
  135. System.out.println("vegetable");
  136. } else {
  137. System.out.println("unknown");
  138. }
  139.  
  140. }
  141. }
  142.  
  143.  
  144. 5зад. "Невалидно число":
  145.  
  146. import java.util.Scanner;
  147.  
  148. class Main {
  149. public static void main(String[] args) {
  150. Scanner scan = new Scanner(System.in);
  151. double number = Double.parseDouble(scan.nextLine());
  152.  
  153. boolean diapazon = (number >= 100 && number <= 200) || number == 0;
  154.  
  155. if (!diapazon) {
  156. System.out.println("invalid");
  157. }
  158.  
  159. }
  160. }
  161.  
  162. 6зад. "Точка върху страна на триъгълник":
  163.  
  164. import java.util.Scanner;
  165.  
  166. class Main {
  167. public static void main(String[] args) {
  168. Scanner scan = new Scanner(System.in);
  169.  
  170. double x1 = Double.parseDouble(scan.nextLine());
  171. double y1 = Double.parseDouble(scan.nextLine());
  172. double x2 = Double.parseDouble(scan.nextLine());
  173. double y2 = Double.parseDouble(scan.nextLine());
  174. double x = Double.parseDouble(scan.nextLine());
  175. double y = Double.parseDouble(scan.nextLine());
  176.  
  177. if (((x==x1) || (x==x2)) && (y>=y1) && (y<=y2)){
  178. System.out.println("Border");
  179. } else if (((y==y1) || (y==y2)) && (x>=x1) && (x<=x2)){
  180. System.out.println("Border");
  181. } else {
  182. System.out.println("Inside/outside");
  183. }
  184.  
  185. }
  186. }
  187.  
  188.  
  189. 7зад. "Магазин за плодове":
  190.  
  191. import java.util.Scanner;
  192.  
  193. class Main {
  194. public static void main(String[] args) {
  195. Scanner scan = new Scanner(System.in);
  196. String plod = scan.nextLine();
  197. String day = scan.nextLine();
  198. String quantity = scan.nextLine();
  199. String price = scan.nextLine();
  200.  
  201.  
  202. if (day.equals("monday")) || (day.equals("tuesday")) || (day.equals("wednes")) || (day.equals("thurday")) || (day.equals("friday")){
  203. if (fruit.equals("banana")){
  204. price = quantity * 2.50;
  205. } if (fruit.equals("apple")){
  206. price = quantity * 1.20;
  207. } if (fruit.equals("orange")){
  208. price = quantity * 0.80;
  209. }
  210. } else if (day.equals("saturday")) || (day.equals("sunday")){
  211. if (fruit.equals("banana")){
  212. price = quantity * 2.70;
  213. } if (fruit.equals("apple")){
  214. price = quantity * 1.25;
  215. } if (fruit.equals("orange")){
  216. price = quantity * 0.90;
  217. }
  218. }
  219.  
  220. System.out.println(price);
  221. }
  222. }
  223.  
  224. 11зад. "Кено":
  225.  
  226. import java.util.Scanner;
  227.  
  228. class Main {
  229. public static void main(String[] args) {
  230. Scanner scan = new Scanner(System.in);
  231. String type = scan.nextLine();
  232. int redove = Integer.parseInt(scan.nextLine());
  233. int coloni = Integer.parseInt(scan.nextLine());
  234. int mesta = redove * coloni;
  235. double dohodi = 0;
  236.  
  237. switch (type){
  238. case "premiere": dohodi = mesta * 12; break;
  239. case "normal": dohodi = mesta * 7.50; break;
  240. case "discount": dohodi = mesta * 5; break;
  241. }
  242. System.out.println(dohodi);
  243.  
  244. }
  245. }
Add Comment
Please, Sign In to add comment