Commit 0dc598bf authored by mahdikarami0111's avatar mahdikarami0111

initial commit

parents
Pipeline #5963 failed with stages
# Default ignored files
/shelf/
/workspace.xml
<html>Simple <b>Java</b> application that includes a class with <code>main()</code> method</html>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="PROJECT" charset="UTF-8" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectKey">
<option name="state" value="project://e2804f05-5315-4fc6-a121-c522a6c26470" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_15" default="true" project-jdk-name="15" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/APW_S5.iml" filepath="$PROJECT_DIR$/APW_S5.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<template>
<input-field default="com.company">IJ_BASE_PACKAGE</input-field>
</template>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>
\ No newline at end of file
<?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>
\ No newline at end of file
package com.company;
/**
* Cirlcle class implements Shape class
*/
public class Circle extends Shape{
private int radius;
/**
* constructor for the class, sets the radius
* @param radius int radius of the circle
*/
public Circle(int radius){
this.radius = radius;
}
@Override
public int calculatePerimeter() {
return (int)Math.round(2*3.14*radius);
}
@Override
public int calculateArea() {
return (int) Math.round(radius * radius * 3.14);
}
@Override
public void draw() {
System.out.println("Circle - Area : "+calculateArea()+" - Perimeter : " +calculatePerimeter());
}
@Override
public boolean equals(Shape shape) {
if(!(shape instanceof Circle)){
return false;
}
return ((Circle) shape).radius == radius;
}
@Override
public String toString() {
return "Circle, Radius : "+radius+"\n";
}
}
package com.company;
/**
* circle class without inheritance
*/
public class Circle1 {
private int radius;
public Circle1(int radius){
this.radius = radius;
}
public int calculatePerimeter() {
return (int)Math.round(2*3.14*radius);
}
public int calculateArea() {
return (int) Math.round(radius * radius * 3.14);
}
public void draw() {
System.out.println("Circle - Area : "+calculateArea()+" - Perimeter : " +calculatePerimeter());
}
public boolean equals(Circle1 circle1) {
return this.radius == circle1.radius;
}
@Override
public String toString() {
return "Circle, Radius : "+radius+"\n";
}
public int getRadius() {
return radius;
}
}
package com.company;
public class Main {
public static void main(String[] args) {
Circle c1 = new Circle(19);
Circle c2 = new Circle(3);
Rectangle r1 = new Rectangle(1,4,1,4);
Rectangle r2 = new Rectangle(5,8,5,8);
Rectangle r3 = new Rectangle(6,6,6,6);
Triangle t1 = new Triangle(2,2,2);
Triangle t2 = new Triangle(4,4,6);
Paint p = new Paint();
p.addShape(c1);
p.addShape(c2);
p.addShape(r1);
p.addShape(r2);
p.addShape(r3);
p.addShape(t1);
p.addShape(t2);
p.drawAll();
p.printAll();
p.describeEqualSides();
// **without inheritance
// Circle1 c1 = new Circle1(19);
// Circle1 c2 = new Circle1(3);
//
// Rectangle1 r1 = new Rectangle1(1,4,1,4);
// Rectangle1 r2 = new Rectangle1(8,5,8,5);
// Rectangle1 r3 = new Rectangle1(6,6,6,6);
//
// Triangle1 t1 = new Triangle1(2,2,2);
// Triangle1 t2 = new Triangle1(4,4,6);
//
// Paint1 paint1 = new Paint1();
//
//
// paint1.addCircle(c1);
// paint1.addCircle(c2);
// paint1.addRectangle(r1);
// paint1.addRectangle(r2);
// paint1.addRectangle(r3);
// paint1.addTriangle(t1);
// paint1.addTriangle(t2);
// paint1.drawAll();
// paint1.printAll();
}
}
package com.company;
import java.util.ArrayList;
/**
* Paint class keeps and manages all the Shapes that are created
*/
public class Paint {
/**
* a list to keep track of all shapes
*/
private ArrayList<Shape> shapes;
/**
* constructor for the class allocates memory
*/
public Paint(){
shapes = new ArrayList<>();
}
/**
* adds a new shape to shapes list
* @param shape new shape to be added
*/
public void addShape(Shape shape){
shapes.add(shape);
}
/**
* draws all shapes
*/
public void drawAll(){
for(Shape shape : shapes){
shape.draw();
}
}
/**
* prints all shapes
*/
public void printAll(){
for(Shape shape : shapes){
System.out.print(shape);
}
}
/**
* goes through all shapes and prints them if they are square or an equilateral triangle
*/
public void describeEqualSides(){
System.out.println("Shapes with equal sides : ");
for(Shape shape : shapes){
if(shape instanceof Triangle && ((Triangle) shape).isEquilateral()){
System.out.print(shape);
}
if(shape instanceof Rectangle && ((Rectangle) shape).isSquare()){
System.out.print(shape);
}
}
}
}
package com.company;
import java.util.ArrayList;
/**
* paint class without inheritance
*/
public class Paint1 {
private ArrayList<Circle1> circles;
private ArrayList<Triangle1> triangles;
private ArrayList<Rectangle1> rectangles;
public Paint1(){
circles = new ArrayList<>();
triangles = new ArrayList<>();
rectangles = new ArrayList<>();
}
public void addTriangle(Triangle1 triangle1){
triangles.add(triangle1);
}
public void addRectangle(Rectangle1 rectangle1){
rectangles.add(rectangle1);
}
public void addCircle(Circle1 circle1){
circles.add(circle1);
}
public void drawAll(){
for(Circle1 circle1 : circles){
circle1.draw();
}
for (Triangle1 triangle1 : triangles){
triangle1.draw();
}
for (Rectangle1 rectangle1 : rectangles){
rectangle1.draw();
}
}
public void printAll(){
for(Circle1 circle1 : circles){
System.out.print(circle1);
}
for (Triangle1 triangle1 : triangles){
System.out.print(triangle1);
}
for (Rectangle1 rectangle1 : rectangles){
System.out.print(rectangle1);
}
}
}
package com.company;
import java.util.ArrayList;
import java.util.Arrays;
/**
* a class that inherits Shape class and hold common features of polygon shapes
*/
public abstract class Polygon extends Shape{
/**
* each polygon shape has a number of sides
*/
public ArrayList<Integer> sides;
/**
* constructor for the class gets an unfixed number of sides and adds them to the sides list
* @param args int sides of the shape
*/
public Polygon(Integer... args){
sides = new ArrayList<>();
sides.addAll(Arrays.asList(args));
}
/**
* since perimeter calculation is the same for all types of polygons
* the implementation is done here rather than being individually done for each specific type
* of polygon
* @return returns perimeter of the polygon
*/
@Override
public int calculatePerimeter(){
int sum = 0;
for(int x : sides){
sum += x;
}
return sum;
}
public ArrayList<Integer> getSides() {
return sides;
}
}
package com.company;
/**
* Rectangle class implements all methods from Shape class
*/
public class Rectangle extends Polygon{
public Rectangle(int s1,int s2,int s3,int s4){
super(s1,s2,s3,s4);
}
@Override
public int calculateArea() {
return (sides.get(0) * sides.get(1));
}
@Override
public void draw() {
System.out.println("Rectangle - Perimeter : " + calculatePerimeter() +" - Area : " +calculateArea());
}
@Override
public boolean equals(Shape shape) {
if(!(shape instanceof Rectangle)){
return false;
}
return ((Rectangle) shape).sides.get(0).equals(sides.get(0)) && ((Rectangle) shape).sides.get(1).equals(sides.get(1));
}
public boolean isSquare(){
return (sides.get(0).equals(sides.get(1)));
}
@Override
public String toString() {
return "Rectangle, side1 : "+sides.get(0) +",side2 : "+sides.get(1)+
",side3 : "+sides.get(2)+",side4 : " +sides.get(3) +"\n";
}
}
package com.company;
import java.util.ArrayList;
/**
* Rectangle class without inheritance
*/
public class Rectangle1 {
private ArrayList<Integer> sides;
public Rectangle1(int x,int y,int z,int r){
sides = new ArrayList<>();
sides.add(x);
sides.add(y);
sides.add(z);
sides.add(r);
}
public int calculatePerimeter(){
return (sides.get(0)+sides.get(1)+sides.get(2)+sides.get(3));
}
public int calculateArea() {
return (sides.get(0) * sides.get(1));
}
public void draw() {
System.out.println("Rectangle - Perimeter : " + calculatePerimeter() +" - Area : " +calculateArea());
}
public boolean equals(Rectangle1 rectangle1){
int i;
for(i=0;i<4;i++){
if(!sides.get(i).equals(rectangle1.sides.get(i))){
return false;
}
}
return true;
}
public boolean isSquare(){
return (sides.get(0).equals(sides.get(1)));
}
@Override
public String toString() {
return "Rectangle, side1 : "+sides.get(0) +",side2 : "+sides.get(1)+
",side3 : "+sides.get(2)+",side4 : " +sides.get(3) +"\n";
}
}
package com.company;
/**
* an abstract class that shares common methods among all shapes
*/
public abstract class Shape {
/**
* each shape has a method to calcualte its perimeter
* @return perimeter of the shape
*/
public abstract int calculatePerimeter();
/**
* each shape has a method to calculate its area
* @return area of the shape
*/
public abstract int calculateArea();
/**
* each shape has a method to print shape type, perimeter, area
*/
public abstract void draw();
/**
* each shape has a method to check if its equal to another shape
* @param shape Shape second shape
* @return true if two shapes are equal, false if not
*/
public abstract boolean equals(Shape shape);
/**
* returns shape information as a String
* @return shape information as a String
*/
@Override
public abstract String toString();
}
package com.company;
/**
* Triangle class implements methods from Shape class
*/
public class Triangle extends Polygon{
public Triangle(int s1,int s2,int s3){
super(s1,s2,s3);
}
@Override
public int calculateArea() {
double area;
int p = calculatePerimeter()/2;
area = Math.sqrt(p * (p-sides.get(0)) * (p - sides.get(1)) * (p - sides.get(2)));
return (int)Math.round(area);
}
@Override
public void draw() {
System.out.println("Triangle - Perimeter : " + calculatePerimeter() +" - Area : " +calculateArea());
}
@Override
public boolean equals(Shape shape) {
if(!(shape instanceof Triangle)){
return false;
}
int i;
for(i = 0 ; i < 3 ; i++){
if(!sides.get(i).equals(((Triangle) shape).sides.get(i))){
return false;
}
}
return true;
}
public boolean isEquilateral(){
return (sides.get(0).equals(sides.get(1)) && sides.get(1).equals(sides.get(2)));
}
@Override
public String toString() {
return "Triangle ,side1 : " +sides.get(0)+",side2 : "+sides.get(1)+",side3 : "+sides.get(2)+"\n";
}
}
package com.company;
import java.util.ArrayList;
/**
* Triangle class without inheritance
*/
public class Triangle1 {
private ArrayList<Integer> sides;
public Triangle1(int x,int y, int z){
sides = new ArrayList<>();
sides.add(x);
sides.add(y);
sides.add(z);
}
public int calculatePerimeter(){
return (sides.get(0) + sides.get(1) + sides.get(2));
}
public int calculateArea() {
double area;
int p = calculatePerimeter()/2;
area = Math.sqrt(p * (p-sides.get(0)) * (p - sides.get(1)) * (p - sides.get(2)));
return (int)Math.round(area);
}
public void draw() {
System.out.println("Triangle - Perimeter : " + calculatePerimeter() +" - Area : " +calculateArea());
};
public boolean isEquilateral(){
return (sides.get(0).equals(sides.get(1)) && sides.get(1).equals(sides.get(2)));
}
public boolean equals(Triangle1 triangle1){
return sides.get(0).equals(triangle1.sides.get(0)) && sides.get(1).equals(triangle1.sides.get(1)) && sides.get(2).equals(triangle1.sides.get(2));
}
@Override
public String toString() {
return "Triangle ,side1 : " +sides.get(0)+",side2 : "+sides.get(1)+",side3 : "+sides.get(2)+"\n";
}
public ArrayList<Integer> getSides() {
return sides;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment