commit 9645d9c4e736da2fbfe6460ea579cae3613ae01a Author: Artem Darius Weber Date: Wed Feb 12 12:43:27 2025 +0300 rel diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..eeb80f7 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..e7763c5 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Calc/classes/calc/Calc.class b/Calc/classes/calc/Calc.class new file mode 100644 index 0000000..ee8dca1 Binary files /dev/null and b/Calc/classes/calc/Calc.class differ diff --git a/Calc/classes/calc/Calculator.class b/Calc/classes/calc/Calculator.class new file mode 100644 index 0000000..b59a425 Binary files /dev/null and b/Calc/classes/calc/Calculator.class differ diff --git a/Calc/classes/calc/operation/Adder.class b/Calc/classes/calc/operation/Adder.class new file mode 100644 index 0000000..7efcb65 Binary files /dev/null and b/Calc/classes/calc/operation/Adder.class differ diff --git a/Calc/classes/calc/operation/Divider.class b/Calc/classes/calc/operation/Divider.class new file mode 100644 index 0000000..5a6cb09 Binary files /dev/null and b/Calc/classes/calc/operation/Divider.class differ diff --git a/Calc/classes/calc/operation/Multiplier.class b/Calc/classes/calc/operation/Multiplier.class new file mode 100644 index 0000000..42e2c52 Binary files /dev/null and b/Calc/classes/calc/operation/Multiplier.class differ diff --git a/Calc/classes/calc/operation/Squarer.class b/Calc/classes/calc/operation/Squarer.class new file mode 100644 index 0000000..132dc7d Binary files /dev/null and b/Calc/classes/calc/operation/Squarer.class differ diff --git a/Calc/classes/calc/operation/Subtractor.class b/Calc/classes/calc/operation/Subtractor.class new file mode 100644 index 0000000..3244230 Binary files /dev/null and b/Calc/classes/calc/operation/Subtractor.class differ diff --git a/Calc/src/calc/Calc.java b/Calc/src/calc/Calc.java new file mode 100644 index 0000000..0764233 --- /dev/null +++ b/Calc/src/calc/Calc.java @@ -0,0 +1,17 @@ +package calc; + +public class Calc { + public static void main(String[] args) { + Calculator calc = new Calculator(); + + int a = 10; + int b = 4; + + System.out.println("Сложение: " + calc.add(a, b)); + System.out.println("Вычитание: " + calc.sub(a, b)); + System.out.println("Умножение: " + calc.mul(a, b)); + System.out.println("Деление: " + calc.div(a, b)); + + System.out.println("Квадрат числа a=" + a + " равен " + calc.square(a)); + } +} diff --git a/Calc/src/calc/Calculator.java b/Calc/src/calc/Calculator.java new file mode 100644 index 0000000..25b37b5 --- /dev/null +++ b/Calc/src/calc/Calculator.java @@ -0,0 +1,35 @@ +package calc; + +import calc.operation.Adder; +import calc.operation.Subtractor; +import calc.operation.Multiplier; +import calc.operation.Divider; +import calc.operation.Squarer; + +public class Calculator { + + // Сложение + public int add(int a, int b) { + return Adder.calculate(a, b); + } + + // Вычитание + public int sub(int a, int b) { + return Subtractor.calculate(a, b); + } + + // Умножение + public int mul(int a, int b) { + return Multiplier.calculate(a, b); + } + + // Деление + public int div(int a, int b) { + return Divider.calculate(a, b); + } + + // Дополнительная операция – возведение в квадрат + public int square(int a) { + return Squarer.calculate(a); + } +} diff --git a/Calc/src/calc/operation/Adder.java b/Calc/src/calc/operation/Adder.java new file mode 100644 index 0000000..f09b0ba --- /dev/null +++ b/Calc/src/calc/operation/Adder.java @@ -0,0 +1,7 @@ +package calc.operation; + +public class Adder { + public static int calculate(int a, int b) { + return a + b; + } +} diff --git a/Calc/src/calc/operation/Divider.java b/Calc/src/calc/operation/Divider.java new file mode 100644 index 0000000..4524843 --- /dev/null +++ b/Calc/src/calc/operation/Divider.java @@ -0,0 +1,10 @@ +package calc.operation; + +public class Divider { + public static int calculate(int a, int b) { + if (b == 0) { + return -1; + } + return a / b; + } +} diff --git a/Calc/src/calc/operation/Multiplier.java b/Calc/src/calc/operation/Multiplier.java new file mode 100644 index 0000000..6dba082 --- /dev/null +++ b/Calc/src/calc/operation/Multiplier.java @@ -0,0 +1,7 @@ +package calc.operation; + +public class Multiplier { + public static int calculate(int a, int b) { + return a * b; + } +} diff --git a/Calc/src/calc/operation/Squarer.java b/Calc/src/calc/operation/Squarer.java new file mode 100644 index 0000000..eeb743a --- /dev/null +++ b/Calc/src/calc/operation/Squarer.java @@ -0,0 +1,7 @@ +package calc.operation; + +public class Squarer { + public static int calculate(int a) { + return a * a; + } +} diff --git a/Calc/src/calc/operation/Subtractor.java b/Calc/src/calc/operation/Subtractor.java new file mode 100644 index 0000000..4c568cb --- /dev/null +++ b/Calc/src/calc/operation/Subtractor.java @@ -0,0 +1,7 @@ +package calc.operation; + +public class Subtractor { + public static int calculate(int a, int b) { + return a - b; + } +} diff --git a/lab1.iml b/lab1.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/lab1.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/listings/GraphTest01$1.class b/listings/GraphTest01$1.class new file mode 100644 index 0000000..17791cc Binary files /dev/null and b/listings/GraphTest01$1.class differ diff --git a/listings/GraphTest01.class b/listings/GraphTest01.class new file mode 100644 index 0000000..3e5ddfd Binary files /dev/null and b/listings/GraphTest01.class differ diff --git a/listings/GraphTest01.java b/listings/GraphTest01.java new file mode 100644 index 0000000..c41e58d --- /dev/null +++ b/listings/GraphTest01.java @@ -0,0 +1,30 @@ +import java.awt.*; +import java.awt.event.*; + +class GraphTest01 extends Frame { + GraphTest01(String s) { + super(s); + setBounds(0, 0, 500, 300); + setVisible(true); + } + + public void paint(Graphics g) { + Dimension d = getSize(); + int dx = d.width / 20, dy = d.height / 20; + int myWidth = 250, myHeight = 250; + g.drawLine(0, 0, myWidth, myHeight); + g.drawLine(0, 0, d.width, d.height); + setBackground(Color.blue); + setForeground(Color.red); + } + + public static void main(String[] args) { + GraphTest01 f = new GraphTest01("Пример рисования"); + f.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent ev) { + System.exit(0); + } + }); + } +} + diff --git a/listings/HelloWorldFrame$1.class b/listings/HelloWorldFrame$1.class new file mode 100644 index 0000000..d73e143 Binary files /dev/null and b/listings/HelloWorldFrame$1.class differ diff --git a/listings/HelloWorldFrame.class b/listings/HelloWorldFrame.class new file mode 100644 index 0000000..03d00a6 Binary files /dev/null and b/listings/HelloWorldFrame.class differ diff --git a/listings/HelloWorldFrame.java b/listings/HelloWorldFrame.java new file mode 100644 index 0000000..7be7279 --- /dev/null +++ b/listings/HelloWorldFrame.java @@ -0,0 +1,20 @@ +import javax.swing.*; +import java.awt.*; + +class HelloWorldFrame extends JFrame { + HelloWorldFrame (String s) { + super(s); + } + + public void paint(Graphics g) { + g.setFont(new Font("Serif", Font.ITALIC | Font.BOLD, 30)); + g.drawString("Hello, XXI century World!", 20, 100); + } + + public static void main(String[] args) { + JFrame f = new HelloWorldFrame("Здраствуй, мир XXI века!"); + f.setSize(400, 150); + f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + f.setVisible(true); + } +} diff --git a/listings/JavaApplication1$Adder.class b/listings/JavaApplication1$Adder.class new file mode 100644 index 0000000..67084bf Binary files /dev/null and b/listings/JavaApplication1$Adder.class differ diff --git a/listings/JavaApplication1$Calculator.class b/listings/JavaApplication1$Calculator.class new file mode 100644 index 0000000..445525c Binary files /dev/null and b/listings/JavaApplication1$Calculator.class differ diff --git a/listings/JavaApplication1.class b/listings/JavaApplication1.class new file mode 100644 index 0000000..f68f25c Binary files /dev/null and b/listings/JavaApplication1.class differ diff --git a/listings/JavaApplication1.java b/listings/JavaApplication1.java new file mode 100644 index 0000000..ad564a7 --- /dev/null +++ b/listings/JavaApplication1.java @@ -0,0 +1,31 @@ +public class JavaApplication1 { + public static void main(String[] args) { + System.out.println("Hello World!"); + Calculator calc = new Calculator(); + System.out.println("2+2=" + calc.sum(2, 2)); + } + + public static class Adder { + + private int sum; + public Adder() { sum = 0; } + public Adder(int a) { this.sum = a; } + + public void add (int b) { + sum += b; + } + + public int getSum() { return sum; } + + } + + public static class Calculator { + public int sum(int... a) { + Adder adder = new Adder(); + for (int i:a) { + adder.add(i); + } + return adder.getSum(); + } + } +}; diff --git a/listings/SimpleFrame$1.class b/listings/SimpleFrame$1.class new file mode 100644 index 0000000..d034706 Binary files /dev/null and b/listings/SimpleFrame$1.class differ diff --git a/listings/SimpleFrame.class b/listings/SimpleFrame.class new file mode 100644 index 0000000..8067d26 Binary files /dev/null and b/listings/SimpleFrame.class differ diff --git a/listings/SimpleFrame.java b/listings/SimpleFrame.java new file mode 100644 index 0000000..d00010c --- /dev/null +++ b/listings/SimpleFrame.java @@ -0,0 +1,23 @@ +import java.awt.*; +import java.awt.event.*; + +class SimpleFrame extends Frame { + SimpleFrame(String s) { + super(s); + setSize(400, 150); + setVisible(true); + + addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent ev) { + dispose(); + System.exit(0); + } + }); + + } + + + public static void main(String[] args) { + new SimpleFrame("Моя программа"); + } +} diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..e094e33 --- /dev/null +++ b/pom.xml @@ -0,0 +1,17 @@ + + + 4.0.0 + + org.example + lab1 + 1.0-SNAPSHOT + + + 23 + 23 + UTF-8 + + + \ No newline at end of file diff --git a/src/GraphicsPrimitives.java b/src/GraphicsPrimitives.java new file mode 100644 index 0000000..3f9d521 --- /dev/null +++ b/src/GraphicsPrimitives.java @@ -0,0 +1,54 @@ +import javax.swing.*; +import java.awt.*; + +public class GraphicsPrimitives extends JPanel { + + @Override + protected void paintComponent(Graphics g) { + super.paintComponent(g); + + // Рисуем круг + g.setColor(Color.RED); + // (50, 50) – координаты левого верхнего угла ограничивающего прямоугольника, 100 – диаметр + g.drawOval(50, 50, 100, 100); + + // Рисуем квадрат + g.setColor(Color.BLUE); + // (200, 50) – координаты левого верхнего угла, 100 – размер стороны квадрата + g.drawRect(200, 50, 100, 100); + + // Линия + g.setColor(Color.GREEN); + g.drawLine(50, 200, 150, 250); + + // Заполненный прямоугольник + g.setColor(Color.MAGENTA); + // Метод fillRect() заполняет прямоугольник цветом + g.fillRect(200, 200, 100, 50); + + // Эллипс + g.setColor(Color.ORANGE); + g.drawOval(350, 200, 120, 60); + + // "звездообразный" узор + g.setColor(Color.BLACK); + int centerX = 450; + int centerY = 300; + int radius = 50; + // Рисуем линии расходящиеся из центра с шагом 30 градусов + for (int angle = 0; angle < 360; angle += 30) { + int xEnd = centerX + (int) (radius * Math.cos(Math.toRadians(angle))); + int yEnd = centerY + (int) (radius * Math.sin(Math.toRadians(angle))); + g.drawLine(centerX, centerY, xEnd, yEnd); + } + } + + public static void main(String[] args) { + JFrame frame = new JFrame("Пример графических примитивов"); + frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + frame.setSize(600, 400); + frame.add(new GraphicsPrimitives()); + frame.setLocationRelativeTo(null); + frame.setVisible(true); + } +} diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..e19af3c --- /dev/null +++ b/src/Main.java @@ -0,0 +1,55 @@ +//TIP To Run code, press or +// click the icon in the gutter. + + +import java.awt.*; +import java.awt.event.*; + +class GraphTest01 extends Frame { + +} + + +//import java.awt.*; +//import java.awt.event.*; +// +//class HelloWorldFrame extends Frame { +// HelloWorldFrame (String s) { +// super(s); +// } +// +// public void paint (Graphics g) { +// g.setFont(new Font("Serif", Font.ITALIC | Font.BOLD, 30)); +// g.drawString("Hello, XXI century World!", 20, 100); +// } +// +// public static void main(String[] args) { +// Frame f = new HelloWorldFrame("Здраствуй, мир XXI века!"); +// f.setSize(400, 150); +// f.setVisible(true); +// +// f.addWindowListener(new WindowAdapter() { +// public void windowClosing(WindowEvent ev) { +// System.exit(0); +// } +// }); +// } +//} + + + + + +//public class Main { +// public static void main(String[] args) { +// //TIP Press with your caret at the highlighted text +// // to see how IntelliJ IDEA suggests fixing it. +// System.out.printf("Hello and welcome!"); +// +// for (int i = 1; i <= 5; i++) { +// //TIP Press to start debugging your code. We have set one breakpoint +// // for you, but you can always add more by pressing . +// System.out.println("i = " + i); +// } +// } +//} \ No newline at end of file diff --git a/src/main/java/org/example/Main.java b/src/main/java/org/example/Main.java new file mode 100644 index 0000000..a02700f --- /dev/null +++ b/src/main/java/org/example/Main.java @@ -0,0 +1,17 @@ +package org.example; + +//TIP To Run code, press or +// click the icon in the gutter. +public class Main { + public static void main(String[] args) { + //TIP Press with your caret at the highlighted text + // to see how IntelliJ IDEA suggests fixing it. + System.out.printf("Hello and welcome!"); + + for (int i = 1; i <= 5; i++) { + //TIP Press to start debugging your code. We have set one breakpoint + // for you, but you can always add more by pressing . + System.out.println("i = " + i); + } + } +} \ No newline at end of file