Maxim_Leo

Untitled

Apr 4th, 2022
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.37 KB | None | 0 0
  1. package com.company;
  2.  
  3. //enum v {car,truck,bus}
  4.  
  5.  
  6. class Car {
  7.  
  8. private String reg_number="Отсутствует";
  9. private final String brand;
  10. // private final v view;
  11. private String color;
  12. //private int power;
  13. private Engine engine;
  14. private final int num_of_wheels;
  15. public Car(String brand,String color, Engine engine, int num_of_wheels){ //(v view)
  16. this.brand=brand;
  17. // this.view=view;
  18. this.color=color;
  19. //this.power=power;
  20. this.engine=engine;
  21. this.num_of_wheels=num_of_wheels;
  22.  
  23. }
  24. public Car(String number,String brand, String color, Engine engine, int num_of_wheels){// v view
  25. this.brand=brand;
  26. // this.view=view;
  27. this.color=color;
  28. //this.power=power;
  29. this.engine=engine;
  30. this.num_of_wheels=num_of_wheels;
  31. this.reg_number=number;
  32. }
  33.  
  34. void setReg_number(String reg_number){
  35. this.reg_number = reg_number;
  36. }
  37. void setColor(String color){
  38. this.color = color;
  39. }
  40. void setEngine(Engine engine){
  41. this.engine = engine;
  42. }
  43.  
  44. String getBrand(){
  45. return brand;
  46. }
  47. String getReg_number(){
  48. return reg_number;
  49. }
  50. String getColor(){
  51. return color;
  52. }
  53. Engine getEngine(){
  54. return engine;
  55. }
  56. int getNum_of_wheels(){
  57. return num_of_wheels;
  58. }
  59. void ChangeColor(String color){
  60. this.color=color;
  61. }
  62. //void ChangePower(int power){
  63. // this.power=power;
  64. // }
  65. void ChangeEngine(Engine engine){
  66. this.engine=engine;
  67. }
  68. void ChangeNumber(String number){
  69. if (number.matches("^([АБЕКМНОРСТУХABEKMHOPCTYX][\\s]?)[0-9]{3}[\\s]?[АБЕКМНОРСТУХABEKMHOPCTYX]{2}[\\s]?([0-9]{2,3})[\\s]?[A-Z]{3}$"))
  70. this.reg_number=number;
  71. else System.out.println("Номер задан неправильно");
  72. }
  73. void Info(){
  74. System.out.println("Информация о машине: ");
  75. // System.out.println("Вид: "+view);
  76. System.out.println("Регистрационный номер: "+reg_number);
  77. System.out.println("Марка: "+brand);
  78. //System.out.println("Мощность двигателя: "+power+" л.с.");
  79. System.out.println("Количество колёс: "+num_of_wheels);
  80. System.out.println("Цвет: "+color);
  81. engine.printInfo();
  82. System.out.println();
  83. }
  84. }
  85. class Engine{
  86. private String serial_number="";
  87. private double fuel_rate;
  88. private String fuel_type;
  89. private int power;
  90. private double capacity;
  91. private int cylinders_num;
  92. private double torque;
  93. private int max_speed;
  94. public Engine(double fuel_rate, String fuel_type,int power,double capacity,int cylinders_num,double torque,int max_speed){
  95. this.fuel_rate=fuel_rate;
  96. this.fuel_type=fuel_type;
  97. this.power=power;
  98. this.capacity=capacity;
  99. this.cylinders_num=cylinders_num;
  100. this.torque=torque;
  101. this.max_speed=max_speed;
  102. }
  103. public Engine(String serial_number, double fuel_rate, String fuel_type,int power,double capacity,int cylinders_num,double torque,int max_speed){
  104. this.serial_number=serial_number;
  105. this.fuel_rate=fuel_rate;
  106. this.fuel_type=fuel_type;
  107. this.power=power;
  108. this.capacity=capacity;
  109. this.cylinders_num=cylinders_num;
  110. this.torque=torque;
  111. this.max_speed=max_speed;
  112. }
  113. void ChangeSNum(String serial_number){
  114. this.serial_number=serial_number;
  115. }
  116. void ChangeFuelRate(double fuel_rate){
  117. this.fuel_rate=fuel_rate;
  118. }
  119. void ChangeFuelType(String fuel_type){
  120. this.fuel_type=fuel_type;
  121. }
  122. void ChangePower(int power){
  123. this.power=power;
  124. }
  125. void ChangeCapacity(double capacity){
  126. this.capacity=capacity;
  127. }
  128. void ChangeCylNum(int cylinders_num){
  129. this.cylinders_num=cylinders_num;
  130. }
  131. void ChangeTorque(double torque){
  132. this.torque=torque;
  133. }
  134. void ChangeMaxSpeed(int max_speed){
  135. this.max_speed=max_speed;
  136. }
  137.  
  138.  
  139. class Pass_Car extends Car{
  140. String type;
  141. String transmission;
  142. int max_speed;
  143. public Pass_Car(String brand, String color, Engine engine, int num_of_wheels,String type,String transmission,int max_speed){
  144. super(brand, color, engine, num_of_wheels);
  145. //this.view=view;
  146. //this.power=power;
  147. this.type=type;
  148. this.transmission=transmission;
  149. this.max_speed=max_speed;
  150. setColor(color);
  151. }
  152. }
  153. class Truck extends Car{
  154. private int weight;
  155. private int lifting_capacity;
  156. private int cabin;
  157. String dimensions;
  158. public Truck(String brand, String color, Engine engine, int num_of_wheels,int weight,int lifting_capacity,int cabin,String dimensions){
  159. super(brand, color, engine, num_of_wheels);
  160. //this.view=view;
  161. //this.power=power;
  162. setColor("Black");
  163. this.lifting_capacity=lifting_capacity;
  164. this.weight=weight;
  165. this.cabin=cabin;
  166. this.dimensions=dimensions;
  167. }
  168. class Bus extends Car{
  169. int space;
  170. String dimensions;
  171. public Bus(String brand, String color, Engine engine, int num_of_wheels,int space,String dimensions){
  172. super(brand, color, engine, num_of_wheels);
  173. //this.view=view;
  174. //this.power=power;
  175. this.space=space;
  176. this.dimensions=dimensions;
  177.  
  178. }
  179. }
  180. class FireTruck extends Car{
  181. private int weight;
  182. int space;
  183. String passability;
  184. public FireTruck(String brand, String color, Engine engine, int num_of_wheels,int weight,int space,String Passability){
  185. super(brand, color, engine, num_of_wheels);
  186. //this.view=view;
  187. //this.power=power;
  188. this.weight=weight;
  189. this.space=space;
  190. this.passability=passability;
  191. setColor("Red");
  192. }
  193. @Override void ChangeNumber(String number){
  194. if (number.matches("^([АБЕКМНОРСТУХABEKMHOPCTYX]{2}[\\s]?)[0-9]{4}[\\s]?[5]{2}[A-Z]{3}$"))
  195. this.setReg_number(number);
  196. else System.out.println("Номер задан неправильно");
  197. }
  198.  
  199. }
  200. }
  201.  
  202.  
  203. void printInfo(){
  204. System.out.println("Характеристики двигателя: ");
  205. System.out.println("Серийный номер: № "+serial_number);
  206. System.out.println("Расход топлива: "+fuel_rate+" л/100 км");
  207. System.out.println("Тип топлива: "+fuel_type);
  208. System.out.println("Мощность: "+power+" л.с.");
  209. System.out.println("Обьем: "+capacity+" л");
  210. System.out.println("Количество цилиндров: "+cylinders_num);
  211. System.out.println("Крутящий момент: "+torque+" Нм");
  212. System.out.println("Максимальное число оборотов: "+max_speed+" об/мин");
  213. System.out.println();
  214. }
  215. }
  216. class Complex{
  217. private final double x;
  218. private double y=0;
  219.  
  220. Complex(double x, double y){
  221. this.x=x;
  222. this.y=y;
  223. }
  224. Complex(double x){this.x=x;}
  225. void Real(){
  226. System.out.println(x);
  227. }
  228. void Imaginary(){
  229. System.out.println("i*"+y);
  230. }
  231. void AlgForm() {
  232. System.out.println("Алгебраическая форма: ");
  233. System.out.println(x+"+i*"+y);
  234. }
  235. void TrigForm() {
  236. System.out.println("Тригонометрическая форма: ");
  237. double r=Math.sqrt(x*x+y*y);
  238. double FI = Math.atan(y/x);
  239. System.out.printf("%.2f *(cos(%.2f)+ isin(%.2f))",r,FI,FI);
  240. System.out.println();
  241. }
  242. static boolean Compare(Complex z1, Complex z2){
  243. return z1.x == z2.x && z1.y == z2.y;
  244. }
  245. static void Sum(Complex z1, Complex z2){
  246. System.out.println(z1.x+z2.x+" i*"+(z1.y+z2.y));
  247. }
  248. static void Diff(Complex z1, Complex z2){
  249. System.out.println(z1.x-z2.x+" i*"+(z1.y-z2.y));
  250. }
  251. static void Mult(Complex z1, Complex z2){
  252. System.out.printf("%.2f + i * %.2f",(z1.x*z2.x-z1.y*z2.y),(z1.y*z2.x+z1.x*z2.y));
  253. System.out.println();
  254. }
  255. static void Div(Complex z1, Complex z2){
  256. System.out.printf("%.2f + i * %.2f",(z1.x*z2.x+z1.y*z2.y)/(z2.x*z2.x+z2.y*z2.y),(z1.y*z2.x+z1.x*z2.y)/(z2.x*z2.x-z2.y*z2.y));
  257. System.out.println();
  258. }
  259. }
  260. public class Lab4 {
  261. public static void main(String[] args){
  262.  
  263. // Car Land_Cruiser = new Car ("Toyota",v.car,"White",300,4);
  264. Engine engine=new Engine(10.1,"Бензин",415,3.3,6,650,5200);
  265. engine.ChangeCapacity(3.5);
  266. engine.printInfo();
  267. Car Land_Cruiser = new Car ("Toyota","White",engine,4);
  268. Land_Cruiser.Info();
  269. Land_Cruiser.ChangeNumber("X156YH76RUS");
  270. Land_Cruiser.ChangeColor("Green");
  271. // Land_Cruiser.ChangePower(350);
  272. Land_Cruiser.Info();
  273.  
  274. Complex z1 = new Complex(10,3);
  275. Complex z2 = new Complex(7,2);
  276. z1.Real();
  277. z1.Imaginary();
  278. z2.Real();
  279. z2.Imaginary();
  280. z1.AlgForm();
  281. z1.TrigForm();
  282. System.out.println(Complex.Compare(z1,z2));
  283. Complex.Sum(z1,z2);
  284. Complex.Diff(z1,z2);
  285. Complex.Mult(z1,z2);
  286. Complex.Div(z1,z2);
  287.  
  288. }
  289. }
  290.  
Advertisement
Add Comment
Please, Sign In to add comment