Advertisement
lashrone1

kiosk

May 21st, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.20 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Main {
  3.  
  4. static Scanner sc = new Scanner(System.in);
  5.  
  6. static int size = 0;
  7.  
  8. static void increase(Alochol arr[]) { //приватный вспомогательный метод для увеличения массива
  9. Alochol[] tmp = new Alochol[arr.length + 10];
  10. for (int i = 0; i < arr.length; i++)
  11. tmp[i] = arr[i];
  12. arr = tmp;
  13. }
  14.  
  15. static Alochol get(int pos,Alochol arr[]) { //получить значение из ячейки
  16. if ((pos < size) && (pos >= 0))
  17. return arr[pos];
  18. else
  19. System.out.println("Введенный введенная позиция больше размера массива, или меньше нуля!\nВведите позицию еще раз!\n");
  20. int an =sc.nextInt();
  21. return get(an,arr);
  22. }
  23.  
  24. static void set(int pos,Alochol arr[]) { //замещение элемента
  25. Alochol test = new Alochol();
  26. test.setVolume(213);
  27. test.setName("Вода");
  28. test.getDegrees();
  29. test.setTemperature(false);
  30. if ((pos < size) && (pos >= 0)) { //позиция должна быть строго меньше размера но не меньше нуля
  31. arr[pos] = test;
  32. } else System.out.println("Ошибка ввода! Неверные данные или элементы отсутствуют!");
  33. }
  34.  
  35. static void insert(int pos,Alochol arr[],Alochol p) { //добавление элемента
  36. if ((pos <= size) && (pos >= 0)) { //позиция должна быть не больше размера и не меньше нуля
  37. for (int i = arr.length - 1; i > pos; i--) //сдвиг элементов
  38. arr[i] = arr[i - 1];
  39. arr[pos] = p;
  40. size++;
  41. //System.out.println("Значение добавлено!");
  42. if (size == arr.length) //увеличение размера по надобности
  43. increase(arr);
  44. } else System.out.println("Ошибка ввода! Неверные данные!");
  45.  
  46. }
  47.  
  48. static void erase(int pos,Alochol arr[]) { //удаление элемента со сдвигом
  49. if ((pos < size) && (pos >= 0)) {
  50. for (int i = pos; i < size - 1; i++) //перезапись элементов
  51. arr[i] = arr[i + 1];
  52. size--;
  53. } else System.out.println("Ошибка ввода! Неверные данные!");
  54. }
  55.  
  56.  
  57. static void print(Alochol arr[]) { //метод печати
  58. if (size == 0)
  59. System.out.println("Массив пуст!");
  60. else {
  61. for (int i = 0; i < size/*arr.length*/; i++)
  62. System.out.print(arr[i] + " ");
  63. System.out.println();
  64. }
  65. }
  66.  
  67.  
  68. public static void main(String[] args) {
  69.  
  70. Alochol[] arr = new Alochol[10];
  71.  
  72. Alochol Pivo = new Alochol();
  73. Pivo.setVolume(12);
  74. Pivo.setName("Пиво");
  75. Pivo.getDegrees();
  76. Pivo.setTemperature(true);
  77.  
  78. insert(0,arr,Pivo);
  79. print(arr);
  80. get(0,arr);
  81.  
  82.  
  83.  
  84. }
  85. }
  86.  
  87.  
  88. import java.util.Scanner;
  89. abstract class Baza{
  90. private double volume;
  91. private int degrees;
  92. private String name;
  93. private boolean temperature;
  94.  
  95. Scanner sc=new Scanner(System.in);
  96.  
  97. public Baza(){}
  98.  
  99. public void setName(String name) {
  100. this.name = name;
  101. }
  102.  
  103. public void setDegrees() {
  104. switch (name){
  105. case "Квас":
  106. this.degrees=2;
  107. break;
  108. case "Водка":
  109. this.degrees=40;
  110. break;
  111. case "Вино":
  112. this.degrees=15;
  113. break;
  114. case "Шампанское":
  115. this.degrees=12;
  116. break;
  117. case "Коньяк":
  118. this.degrees=42;
  119. break;
  120. case "Виски":
  121. this.degrees=50;
  122. break;
  123. case "Пиво":
  124. this.degrees=8;
  125. break;
  126. default:
  127. this.degrees=95;
  128. break;
  129. }
  130. }
  131.  
  132. public void setTemperature(boolean temperature) {
  133. if(temperature==true)
  134. this.temperature = true;
  135. else
  136. this.temperature = false;
  137. }
  138.  
  139. public void setVolume(double volume) {
  140. if(volume<0) {
  141. System.out.println("Введенный обьем меньше нуля!\nВведите обьем еще раз!\n");
  142. double vol=sc.nextDouble();
  143. setVolume(vol);
  144. }
  145. else
  146. this.volume = volume;
  147. }
  148.  
  149. public double getVolume() {
  150. return volume;
  151. }
  152.  
  153. public int getDegrees() {
  154. return degrees;
  155. }
  156.  
  157. public String getTemperature(){
  158. if(this.temperature==true)
  159. return "Холодный";
  160. else
  161. return "Теплый";
  162. }
  163.  
  164. }
  165.  
  166. public class Alochol extends Baza{
  167.  
  168. public void setDegrees() {
  169. super.setDegrees();
  170. }
  171.  
  172. public void setName(String name){
  173. super.setName(name);
  174. }
  175.  
  176. public void setTemperature(boolean temperature) {
  177. super.setTemperature(temperature);
  178. }
  179.  
  180. public void setVolume(double volume) {
  181. super.setVolume(volume);
  182. }
  183.  
  184. public double getVolume() {
  185. return super.getVolume();
  186. }
  187.  
  188. public int getDegrees() {
  189. return super.getDegrees();
  190. }
  191.  
  192. public String getTemperature(){
  193. return super.getTemperature();
  194. }
  195. }
  196.  
  197. public class NeAlcohol extends Baza {
  198. public void setDegrees() {}
  199.  
  200. public void setName(String name){}
  201.  
  202. public void setTemperature(boolean temperature) {}
  203.  
  204. public void setVolume(double volume) {}
  205.  
  206. public double getVolume() {
  207. return super.getVolume();
  208. }
  209.  
  210. public int getDegrees() {
  211. return super.getDegrees();
  212. }
  213.  
  214. public String getTemperature(){
  215. return super.getTemperature();
  216. }
  217. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement