Maxim_Leo

Untitled

Apr 3rd, 2022
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.97 KB | None | 0 0
  1. package com.company;
  2.  
  3. enum v {car,truck,bus}
  4. class Car {
  5.  
  6. private String reg_number="Отсутствует";
  7. private final String brand;
  8. private final v view;
  9. private String color;
  10. //private int power;
  11. private Engine engine;
  12. private final int num_of_wheels;
  13. public Car(String brand,v view, String color, Engine engine, int num_of_wheels){
  14. this.brand=brand;
  15. this.view=view;
  16. this.color=color;
  17. //this.power=power;
  18. this.engine=engine;
  19. this.num_of_wheels=num_of_wheels;
  20.  
  21. }
  22. public Car(String number,String brand,v view, String color, Engine engine, int num_of_wheels){
  23. this.brand=brand;
  24. this.view=view;
  25. this.color=color;
  26. //this.power=power;
  27. this.engine=engine;
  28. this.num_of_wheels=num_of_wheels;
  29. this.reg_number=number;
  30.  
  31. }
  32. void ChangeColor(String color){
  33. this.color=color;
  34. }
  35. //void ChangePower(int power){
  36. // this.power=power;
  37. // }
  38. void ChangeEngine(Engine engine){
  39. this.engine=engine;
  40. }
  41. void ChangeNumber(String number){
  42. if (number.matches("^([АБЕКМНОРСТУХABEKMHOPCTYX][\\s]?)[0-9]{3}[\\s]?[АБЕКМНОРСТУХABEKMHOPCTYX]{2}[\\s]?([0-9]{2,3})[\\s]?[A-Z]{3}$"))
  43. this.reg_number=number;
  44. else System.out.println("Номер задан неправильно");
  45. }
  46. void Info(){
  47. System.out.println("Информация о машине: ");
  48. System.out.println("Вид: "+view);
  49. System.out.println("Регистрационный номер: "+reg_number);
  50. System.out.println("Марка: "+brand);
  51. //System.out.println("Мощность двигателя: "+power+" л.с.");
  52. System.out.println("Количество колёс: "+num_of_wheels);
  53. System.out.println("Цвет: "+color);
  54. engine.printInfo();
  55. System.out.println();
  56. }
  57. }
  58. class Complex{
  59. private final double x;
  60. private double y=0;
  61.  
  62. Complex(double x, double y){
  63. this.x=x;
  64. this.y=y;
  65. }
  66. Complex(double x){this.x=x;}
  67. void Real(){
  68. System.out.println(x);
  69. }
  70. void Imaginary(){
  71. System.out.println("i*"+y);
  72. }
  73. void AlgForm() {
  74. System.out.println("Алгебраическая форма: ");
  75. System.out.println(x+"+i*"+y);
  76. }
  77. void TrigForm() {
  78. System.out.println("Тригонометрическая форма: ");
  79. double r=Math.sqrt(x*x+y*y);
  80. double FI = Math.atan(y/x);
  81. System.out.printf("%.2f *(cos(%.2f)+ isin(%.2f))",r,FI,FI);
  82. System.out.println();
  83. }
  84. static boolean Compare(Complex z1, Complex z2){
  85. return z1.x == z2.x && z1.y == z2.y;
  86. }
  87. static void Sum(Complex z1, Complex z2){
  88. System.out.println(z1.x+z2.x+" i*"+(z1.y+z2.y));
  89. }
  90. static void Diff(Complex z1, Complex z2){
  91. System.out.println(z1.x-z2.x+" i*"+(z1.y-z2.y));
  92. }
  93. static void Mult(Complex z1, Complex z2){
  94. System.out.printf("%.2f + i * %.2f",(z1.x*z2.x-z1.y*z2.y),(z1.y*z2.x+z1.x*z2.y));
  95. System.out.println();
  96. }
  97. static void Div(Complex z1, Complex z2){
  98. 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));
  99. System.out.println();
  100. }
  101. }
  102. /*
  103. class Pass_Car extends Car{
  104. Pass_Car(){
  105.  
  106. }
  107. }
  108. class Truck extends Car{
  109.  
  110. }
  111. class Bus extends Car{
  112. Bus(){
  113.  
  114. }
  115. }
  116. class Spec extends Car{
  117.  
  118. }
  119.  
  120. */
  121. class Engine{
  122. private String serial_number="";
  123. private double fuel_rate;
  124. private String fuel_type;
  125. private int power;
  126. private double capacity;
  127. private int cylinders_num;
  128. private double torque;
  129. private int max_speed;
  130. public Engine(double fuel_rate, String fuel_type,int power,double capacity,int cylinders_num,double torque,int max_speed){
  131. this.fuel_rate=fuel_rate;
  132. this.fuel_type=fuel_type;
  133. this.power=power;
  134. this.capacity=capacity;
  135. this.cylinders_num=cylinders_num;
  136. this.torque=torque;
  137. this.max_speed=max_speed;
  138. }
  139. public Engine(String serial_number, double fuel_rate, String fuel_type,int power,double capacity,int cylinders_num,double torque,int max_speed){
  140. this.serial_number=serial_number;
  141. this.fuel_rate=fuel_rate;
  142. this.fuel_type=fuel_type;
  143. this.power=power;
  144. this.capacity=capacity;
  145. this.cylinders_num=cylinders_num;
  146. this.torque=torque;
  147. this.max_speed=max_speed;
  148. }
  149. void ChangeSNum(String serial_number){
  150. this.serial_number=serial_number;
  151. }
  152. void ChangeFuelRate(double fuel_rate){
  153. this.fuel_rate=fuel_rate;
  154. }
  155. void ChangeFuelType(String fuel_type){
  156. this.fuel_type=fuel_type;
  157. }
  158. void ChangePower(int power){
  159. this.power=power;
  160. }
  161. void ChangeCapacity(double capacity){
  162. this.capacity=capacity;
  163. }
  164. void ChangeCylNum(int cylinders_num){
  165. this.serial_number=serial_number;
  166. }
  167. void ChangeTorque(double torque){
  168. this.serial_number=serial_number;
  169. }
  170. void ChangeMaxSpeed(int max_speed){
  171. this.max_speed=max_speed;
  172. }
  173. void printInfo(){
  174. System.out.println("Характеристики двигателя: ");
  175. System.out.println("Серийный номер: № "+serial_number);
  176. System.out.println("Расход топлива: "+fuel_rate+" л/100 км");
  177. System.out.println("Тип топлива: "+fuel_type);
  178. System.out.println("Мощность: "+power+" л.с.");
  179. System.out.println("Обьем: "+capacity+" л");
  180. System.out.println("Количество цилиндров: "+cylinders_num);
  181. System.out.println("Крутящий момент: "+torque+" Нм");
  182. System.out.println("Максимальное число оборотов: "+max_speed+" об/мин");
  183. System.out.println();
  184. }
  185. }
  186. public class Lab4 {
  187. public static void main(String[] args){
  188.  
  189. // Car Land_Cruiser = new Car ("Toyota",v.car,"White",300,4);
  190. Engine engine=new Engine(10.1,"Бензин",415,3.3,6,650,5200);
  191. engine.ChangeCapacity(3.5);
  192. engine.printInfo();
  193. Car Land_Cruiser = new Car ("Toyota",v.car,"White",engine,4);
  194. Land_Cruiser.Info();
  195. Land_Cruiser.ChangeNumber("X156YH76RUS");
  196. Land_Cruiser.ChangeColor("Green");
  197. // Land_Cruiser.ChangePower(350);
  198. Land_Cruiser.Info();
  199.  
  200. Complex z1 = new Complex(10,3);
  201. Complex z2 = new Complex(7,2);
  202. z1.Real();
  203. z1.Imaginary();
  204. z2.Real();
  205. z2.Imaginary();
  206. z1.AlgForm();
  207. z1.TrigForm();
  208. System.out.println(Complex.Compare(z1,z2));
  209. Complex.Sum(z1,z2);
  210. Complex.Diff(z1,z2);
  211. Complex.Mult(z1,z2);
  212. Complex.Div(z1,z2);
  213.  
  214. }
  215. }
  216.  
Advertisement
Add Comment
Please, Sign In to add comment