Lab 4
This commit is contained in:
parent
754c8bceab
commit
6a4af426ea
|
@ -1,17 +1,47 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="563d5a49-589a-44ca-b92d-59680eab1914" name="Changes" comment="" />
|
<list default="true" id="563d5a49-589a-44ca-b92d-59680eab1914" name="Changes" comment="">
|
||||||
|
<change afterPath="$PROJECT_DIR$/src/Building.java" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/src/Genre.java" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/src/GetStudentData.java" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/src/Person.java" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/src/PersonData.java" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/src/Rectangle1.java" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/src/Student.java" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/src/geometry/Circle.java" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/src/geometry/Cone.java" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/src/geometry/Cube.java" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/src/geometry/Cuboid.java" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/src/geometry/GeoCalculator.java" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/src/geometry/Rectangle.java" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/src/geometry/Sphere.java" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/src/geometry/Square.java" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Main.java" afterDir="false" />
|
||||||
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||||
<option name="LAST_RESOLUTION" value="IGNORE" />
|
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="FileTemplateManagerImpl">
|
||||||
|
<option name="RECENT_TEMPLATES">
|
||||||
|
<list>
|
||||||
|
<option value="Class" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
<component name="Git.Settings">
|
<component name="Git.Settings">
|
||||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="MarkdownSettingsMigration">
|
||||||
|
<option name="stateVersion" value="1" />
|
||||||
|
</component>
|
||||||
<component name="ProjectId" id="2HFpHtKx3vTSdvkKECF3AmEpSQt" />
|
<component name="ProjectId" id="2HFpHtKx3vTSdvkKECF3AmEpSQt" />
|
||||||
<component name="ProjectLevelVcsManager" settingsEditedManually="true" />
|
<component name="ProjectLevelVcsManager" settingsEditedManually="true">
|
||||||
|
<ConfirmationsSetting value="2" id="Add" />
|
||||||
|
</component>
|
||||||
<component name="ProjectViewState">
|
<component name="ProjectViewState">
|
||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
<option name="showLibraryContents" value="true" />
|
<option name="showLibraryContents" value="true" />
|
||||||
|
@ -22,9 +52,24 @@
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true"
|
"RunOnceActivity.ShowReadmeOnStart": "true"
|
||||||
}
|
}
|
||||||
}]]></component>
|
}]]></component>
|
||||||
|
<component name="RunManager">
|
||||||
|
<configuration name="Main" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
|
||||||
|
<option name="MAIN_CLASS_NAME" value="Main" />
|
||||||
|
<module name="Lab4" />
|
||||||
|
<method v="2">
|
||||||
|
<option name="Make" enabled="true" />
|
||||||
|
</method>
|
||||||
|
</configuration>
|
||||||
|
<recent_temporary>
|
||||||
|
<list>
|
||||||
|
<item itemvalue="Application.Main" />
|
||||||
|
</list>
|
||||||
|
</recent_temporary>
|
||||||
|
</component>
|
||||||
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
||||||
<component name="TaskManager">
|
<component name="TaskManager">
|
||||||
<task active="true" id="Default" summary="Default task">
|
<task active="true" id="Default" summary="Default task">
|
||||||
|
<changelist id="563d5a49-589a-44ca-b92d-59680eab1914" name="Changes" comment="" />
|
||||||
<created>1667890605459</created>
|
<created>1667890605459</created>
|
||||||
<option name="number" value="Default" />
|
<option name="number" value="Default" />
|
||||||
<option name="presentableId" value="Default" />
|
<option name="presentableId" value="Default" />
|
||||||
|
@ -32,4 +77,15 @@
|
||||||
</task>
|
</task>
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="Vcs.Log.Tabs.Properties">
|
||||||
|
<option name="TAB_STATES">
|
||||||
|
<map>
|
||||||
|
<entry key="MAIN">
|
||||||
|
<value>
|
||||||
|
<State />
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
</project>
|
</project>
|
|
@ -0,0 +1,20 @@
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.Period;
|
||||||
|
|
||||||
|
public class Building {
|
||||||
|
LocalDate date;
|
||||||
|
String name;
|
||||||
|
int floors;
|
||||||
|
|
||||||
|
public Building(LocalDate date, String name, int floors) {
|
||||||
|
this.date = date;
|
||||||
|
this.name = name;
|
||||||
|
this.floors = floors;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void displayBuildingData() {
|
||||||
|
System.out.println("Building " + name);
|
||||||
|
System.out.println("with " + floors + " floors");
|
||||||
|
System.out.println("Built " + Math.abs(Period.between(LocalDate.now(), date).getYears()) + " years ago");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,44 @@
|
||||||
|
public class Genre {
|
||||||
|
String typeName;
|
||||||
|
String genreName;
|
||||||
|
int chromosomes;
|
||||||
|
int baseXchromosomes;
|
||||||
|
String desc;
|
||||||
|
|
||||||
|
public Genre(String typeName, String genreName, int chromosomes, int baseXchromosomes, String desc) {
|
||||||
|
this.typeName = typeName;
|
||||||
|
this.genreName = genreName;
|
||||||
|
this.chromosomes = chromosomes;
|
||||||
|
this.baseXchromosomes = baseXchromosomes;
|
||||||
|
this.desc = desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Genre(Genre g) {
|
||||||
|
this.typeName = g.typeName;
|
||||||
|
this.genreName = g.genreName;
|
||||||
|
this.chromosomes = g.chromosomes;
|
||||||
|
this.baseXchromosomes = g.baseXchromosomes;
|
||||||
|
this.desc = g.desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAll() {
|
||||||
|
return "Type name: " + typeName +
|
||||||
|
"\nGenre name: " + genreName +
|
||||||
|
"\nChromosomes number: " + chromosomes +
|
||||||
|
"\nBase X chromosomes number: " + baseXchromosomes +
|
||||||
|
"\nDescription: " + desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFullName() {
|
||||||
|
return typeName + ", " + genreName + " genre";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getChromosomes() {
|
||||||
|
return 2 * chromosomes + " chromosomes, of which " + baseXchromosomes + " are X";
|
||||||
|
}
|
||||||
|
|
||||||
|
public Genre clone() {
|
||||||
|
Genre g = new Genre(this);
|
||||||
|
return g;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class GetStudentData {
|
||||||
|
public static void getStudentData() {
|
||||||
|
String name, surname, specialty;
|
||||||
|
int age, indexNumber, collegeYear;
|
||||||
|
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
|
||||||
|
System.out.print("Name: ");
|
||||||
|
name = scanner.next();
|
||||||
|
|
||||||
|
System.out.print("Surname: ");
|
||||||
|
surname = scanner.next();
|
||||||
|
|
||||||
|
System.out.print("Age: ");
|
||||||
|
age = scanner.nextInt();
|
||||||
|
|
||||||
|
System.out.print("Index number: ");
|
||||||
|
indexNumber = scanner.nextInt();
|
||||||
|
|
||||||
|
System.out.print("Specialty: ");
|
||||||
|
specialty = scanner.next();
|
||||||
|
|
||||||
|
System.out.print("College year: ");
|
||||||
|
collegeYear = scanner.nextInt();
|
||||||
|
|
||||||
|
Student s = new Student(name, surname, age, indexNumber, specialty, collegeYear);
|
||||||
|
s.getStudentData();
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,96 @@
|
||||||
|
import geometry.*;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.out.println("Hello world!");
|
System.out.println("=== Zadanie L.1 (prostokąt) ===");
|
||||||
|
Rectangle1 rect1 = new Rectangle1(3, 4);
|
||||||
|
System.out.println("Rectangle W:" + rect1.width + " H:" + rect1.height);
|
||||||
|
System.out.println("Area: " + rect1.getArea());
|
||||||
|
System.out.println("Circumference: " + rect1.getCircumference());
|
||||||
|
System.out.println("Axis: " + rect1.getAxis());
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("=== Zadanie L.2 (budynek) ===");
|
||||||
|
Building b1 = new Building(LocalDate.of(1991, 4, 1), "wsiz", 3);
|
||||||
|
b1.displayBuildingData();
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("=== Zadanie L.3 (gatunki) ===");
|
||||||
|
Genre cat = new Genre("cat", "felis domestic", 20, 10, "Garfield");
|
||||||
|
System.out.println(cat.getAll());
|
||||||
|
System.out.println(cat.getFullName());
|
||||||
|
System.out.println(cat.getChromosomes());
|
||||||
|
|
||||||
|
Genre notDog = cat.clone();
|
||||||
|
System.out.println(notDog.getAll());
|
||||||
|
System.out.println(notDog.getFullName());
|
||||||
|
System.out.println(notDog.getChromosomes());
|
||||||
|
notDog.typeName = "dog";
|
||||||
|
notDog.genreName = "dogus domesticus";
|
||||||
|
notDog.desc = "Pluto";
|
||||||
|
System.out.println(notDog.getAll());
|
||||||
|
System.out.println(notDog.getFullName());
|
||||||
|
System.out.println(notDog.getChromosomes());
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("=== Zadanie K.1 (osoba) ===");
|
||||||
|
PersonData.getPersonData();
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("=== Zadanie K.2 (student) ===");
|
||||||
|
Student s1 = new Student("Zdzichu", "Zdzichowski", 19, 12345, "IT", 2021);
|
||||||
|
Student s2 = new Student("Eustachy", 21, 54321, "Cosmetics", 2019);
|
||||||
|
Student s3 = new Student(11223, "Management", 2018);
|
||||||
|
Student s4 = new Student("Andrzej", "Kula", 22, 32213, "Networking");
|
||||||
|
|
||||||
|
s1.getStudentData();
|
||||||
|
s2.getStudentData();
|
||||||
|
s3.getStudentData();
|
||||||
|
s4.getStudentData();
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("=== Zadanie K.3 (wprowadź studenta) ===");
|
||||||
|
GetStudentData.getStudentData();
|
||||||
|
|
||||||
|
|
||||||
|
System.out.println("=== Zadanie K.4 (figury) ===");
|
||||||
|
System.out.println("Circle");
|
||||||
|
Circle circle = new Circle(4);
|
||||||
|
System.out.println(circle.getArea());
|
||||||
|
System.out.println(circle.getCircumference());
|
||||||
|
|
||||||
|
System.out.println("Cone");
|
||||||
|
Cone cone = new Cone(4, 2);
|
||||||
|
System.out.println(cone.getArea());
|
||||||
|
System.out.println(cone.getVolume());
|
||||||
|
|
||||||
|
System.out.println("Cube");
|
||||||
|
Cube cube = new Cube(4);
|
||||||
|
System.out.println(cube.getArea());
|
||||||
|
System.out.println(cube.getCircumference());
|
||||||
|
|
||||||
|
System.out.println("Cuboid");
|
||||||
|
Cuboid cuboid = new Cuboid(4, 5, 6);
|
||||||
|
System.out.println(cuboid.getArea());
|
||||||
|
System.out.println(cuboid.getVolume());
|
||||||
|
|
||||||
|
System.out.println("Rectangle");
|
||||||
|
Rectangle rectangle = new Rectangle(3, 4);
|
||||||
|
System.out.println(rectangle.getArea());
|
||||||
|
System.out.println(rectangle.getCircumference());
|
||||||
|
|
||||||
|
System.out.println("Sphere");
|
||||||
|
Sphere sphere = new Sphere(4);
|
||||||
|
System.out.println(sphere.getArea());
|
||||||
|
System.out.println(sphere.getVolume());
|
||||||
|
|
||||||
|
System.out.println("Square");
|
||||||
|
Square square = new Square(4);
|
||||||
|
System.out.println(square.getArea());
|
||||||
|
System.out.println(square.getCircumference());
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
public class Person {
|
||||||
|
String name, surname;
|
||||||
|
int age;
|
||||||
|
|
||||||
|
public Person(String name, String surname, int age) {
|
||||||
|
this.name = name;
|
||||||
|
this.surname = surname;
|
||||||
|
this.age = age;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Person(String name, int age) {
|
||||||
|
this.name = name;
|
||||||
|
this.surname = "Kowalski";
|
||||||
|
this.age = age;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Person() {
|
||||||
|
this.name = "Jan";
|
||||||
|
this.surname = "Kowalski";
|
||||||
|
this.age = 20;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getPersonData() {
|
||||||
|
System.out.println(name + " " + surname + ", age " + age);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
public class PersonData {
|
||||||
|
public static void getPersonData() {
|
||||||
|
Person p1 = new Person("Zdzichu", "Zdzichowski", 19);
|
||||||
|
Person p2 = new Person("Eustachy", 21);
|
||||||
|
Person p3 = new Person();
|
||||||
|
|
||||||
|
p1.getPersonData();
|
||||||
|
p2.getPersonData();
|
||||||
|
p3.getPersonData();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
public class Rectangle1 {
|
||||||
|
int width, height;
|
||||||
|
|
||||||
|
public Rectangle1(int width, int height) {
|
||||||
|
if(width <= 0 || height <= 0) throw new IllegalArgumentException("Width/height must be greater than zero");
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getArea() {
|
||||||
|
return width * height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCircumference() {
|
||||||
|
return (2 * width) + (2 * height);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getAxis() {
|
||||||
|
return Math.sqrt(Math.pow(width, 2) + Math.pow(height, 2));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
public class Student extends Person {
|
||||||
|
int indexNumber;
|
||||||
|
String specialty;
|
||||||
|
int collegeYear;
|
||||||
|
|
||||||
|
public Student(String name, String surname, int age, int indexNumber, String specialty, int collegeYear) {
|
||||||
|
super(name, surname, age);
|
||||||
|
this.indexNumber = indexNumber;
|
||||||
|
this.specialty = specialty;
|
||||||
|
this.collegeYear = collegeYear;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Student(String name, int age, int indexNumber, String specialty, int collegeYear) {
|
||||||
|
super(name, age);
|
||||||
|
this.indexNumber = indexNumber;
|
||||||
|
this.specialty = specialty;
|
||||||
|
this.collegeYear = collegeYear;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Student(int indexNumber, String specialty, int collegeYear) {
|
||||||
|
super();
|
||||||
|
this.indexNumber = indexNumber;
|
||||||
|
this.specialty = specialty;
|
||||||
|
this.collegeYear = collegeYear;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Student(String name, String surname, int age, int indexNumber, String specialty) {
|
||||||
|
super(name, surname, age);
|
||||||
|
this.indexNumber = indexNumber;
|
||||||
|
this.specialty = specialty;
|
||||||
|
this.collegeYear = 2022;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getStudentData() {
|
||||||
|
this.getPersonData();
|
||||||
|
System.out.println("Student at " + specialty + ", index no. " + indexNumber + ", studying since " + collegeYear);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package geometry;
|
||||||
|
|
||||||
|
public class Circle {
|
||||||
|
int radius;
|
||||||
|
|
||||||
|
public Circle(int radius) {
|
||||||
|
if(radius <= 0) throw new IllegalArgumentException("Radius must be greater than 0");
|
||||||
|
this.radius = radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getArea() {
|
||||||
|
return Math.PI * Math.pow(radius, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getCircumference() {
|
||||||
|
return 2 * Math.PI * radius;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package geometry;
|
||||||
|
|
||||||
|
public class Cone {
|
||||||
|
double height, radius, slant;
|
||||||
|
|
||||||
|
public Cone(double height, double radius) {
|
||||||
|
if(height <= 0 || radius <= 0) throw new IllegalArgumentException("Height/radius must be greater than zero");
|
||||||
|
this.height = height;
|
||||||
|
this.radius = radius;
|
||||||
|
this.slant = Math.sqrt(Math.pow(height, 2) + Math.pow(radius, 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getArea() {
|
||||||
|
return Math.PI * radius * slant + Math.PI * Math.pow(radius, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getVolume() {
|
||||||
|
return (Math.PI * Math.pow(radius, 2) * height) / 3;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package geometry;
|
||||||
|
|
||||||
|
public class Cube {
|
||||||
|
int edge;
|
||||||
|
|
||||||
|
public Cube(int edge) {
|
||||||
|
if(edge <= 0) throw new IllegalArgumentException("Edge must be greater than 0");
|
||||||
|
this.edge = edge;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getArea() {
|
||||||
|
return 6 * Math.pow(edge, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getCircumference() {
|
||||||
|
return Math.pow(edge, 3);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
package geometry;
|
||||||
|
|
||||||
|
public class Cuboid {
|
||||||
|
int a, b, c;
|
||||||
|
|
||||||
|
public Cuboid(int a, int b, int c) {
|
||||||
|
if(a <= 0 || b <= 0 || c <= 0) throw new IllegalArgumentException("Edge must be greater than 0");
|
||||||
|
this.a = a;
|
||||||
|
this.b = b;
|
||||||
|
this.c = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getArea() {
|
||||||
|
return 2 * (a * b) +
|
||||||
|
2 * (b * c) +
|
||||||
|
2 * (a * c);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getVolume() {
|
||||||
|
return a * b * c;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package geometry;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class GeoCalculator {
|
||||||
|
public static void start() {
|
||||||
|
int choice;
|
||||||
|
Scanner scanner = new Scanner(System.in);
|
||||||
|
|
||||||
|
System.out.println("1. Circle");
|
||||||
|
System.out.println("2. Cone");
|
||||||
|
System.out.println("3. Cube");
|
||||||
|
System.out.println("4. Cuboid");
|
||||||
|
System.out.println("5. Rectangle");
|
||||||
|
System.out.println("6. Sphere");
|
||||||
|
System.out.println("7. Square");
|
||||||
|
|
||||||
|
while(true) {
|
||||||
|
choice = scanner.nextInt();
|
||||||
|
if(choice >= 1 && choice <= 7) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(choice) {
|
||||||
|
case 1:
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
package geometry;
|
||||||
|
|
||||||
|
public class Rectangle {
|
||||||
|
int width, height;
|
||||||
|
|
||||||
|
public Rectangle(int width, int height) {
|
||||||
|
if(width <= 0 || height <= 0) throw new IllegalArgumentException("Width/height must be greater than zero");
|
||||||
|
this.width = width;
|
||||||
|
this.height = height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getArea() {
|
||||||
|
return width * height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getCircumference() {
|
||||||
|
return (2 * width) + (2 * height);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package geometry;
|
||||||
|
|
||||||
|
public class Sphere {
|
||||||
|
int radius;
|
||||||
|
|
||||||
|
public Sphere(int radius) {
|
||||||
|
if(radius <= 0) throw new IllegalArgumentException("Radius must be greater than 0");
|
||||||
|
this.radius = radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getArea() {
|
||||||
|
return 4 * Math.PI * Math.pow(radius, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getVolume() {
|
||||||
|
return (4 / 3) * Math.PI * Math.pow(radius, 3);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package geometry;
|
||||||
|
|
||||||
|
public class Square {
|
||||||
|
int edge;
|
||||||
|
|
||||||
|
public Square(int edge) {
|
||||||
|
if(edge <= 0) throw new IllegalArgumentException("Edge must be greater than zero");
|
||||||
|
this.edge = edge;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getArea() {
|
||||||
|
return Math.pow(edge, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getCircumference() {
|
||||||
|
return 4 * edge;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue