Artem-Darius Weber 2 months ago
commit 9645d9c4e7

29
.gitignore vendored

@ -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

8
.idea/.gitignore vendored

@ -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

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_23" default="true" project-jdk-name="homebrew-23" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/lab1.iml" filepath="$PROJECT_DIR$/lab1.iml" />
</modules>
</component>
</project>

Binary file not shown.

@ -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));
}
}

@ -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);
}
}

@ -0,0 +1,7 @@
package calc.operation;
public class Adder {
public static int calculate(int a, int b) {
return a + b;
}
}

@ -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;
}
}

@ -0,0 +1,7 @@
package calc.operation;
public class Multiplier {
public static int calculate(int a, int b) {
return a * b;
}
}

@ -0,0 +1,7 @@
package calc.operation;
public class Squarer {
public static int calculate(int a) {
return a * a;
}
}

@ -0,0 +1,7 @@
package calc.operation;
public class Subtractor {
public static int calculate(int a, int b) {
return a - b;
}
}

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

Binary file not shown.

Binary file not shown.

@ -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);
}
});
}
}

Binary file not shown.

Binary file not shown.

@ -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);
}
}

Binary file not shown.

@ -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();
}
}
};

Binary file not shown.

Binary file not shown.

@ -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("Моя программа");
}
}

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>lab1</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>23</maven.compiler.source>
<maven.compiler.target>23</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

@ -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);
}
}

@ -0,0 +1,55 @@
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> 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 <shortcut actionId="ShowIntentionActions"/> 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 <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
// // for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
// System.out.println("i = " + i);
// }
// }
//}

@ -0,0 +1,17 @@
package org.example;
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
public static void main(String[] args) {
//TIP Press <shortcut actionId="ShowIntentionActions"/> 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 <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
System.out.println("i = " + i);
}
}
}
Loading…
Cancel
Save