Trying to run this Java Code, but errors, can someone help me to fix it.. thank you! I have provided my code at the bott
Posted: Tue May 24, 2022 8:10 am
Trying to run this Java Code, but errors, can someone help me to
fix it.. thank you! I have provided my code at the bottom, you can
edit it and paste here
class twoD.java
class Rectangle.java
class Circle.java
1 5.2.1 Example 1. Steps: STEP 1: Create a folder named twoD. STEP 2: Defining the following class as abstract class and save in folder. //To declare abstract object TwoD in a file named TwoD.java //Put class TwoD in a package package twoD; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.lang. Math; //Class declaration and definition abstract) public class TwoDeal cless protected double area: protected double perimeter; > //Constructor public TwoD() area=0; perimeter 0; } //Getter or accessor methods public double getArea () { return area;} public double getPerimeter () {return perimeter;} //Processor methods. abstract public void calculateArea(); obsweet method Conly function declado) 3 common dhitute ok on, Caltribute 18 without implemention 2 abstract public void calculatePerimeter (); sed method abstract public void display();d method STEP 3: Define the following classes as the concrete classes and save in the folder twoD. // To declare concrete object Rectangle in a file named // Rectangle.java //Put class Rectangle in a package package twoD; import javax.swing.*; import java.awt."; import java.awt.event."; //class declaration and definition public class Rectangle extends TwoD concrete dags' { double width; double len; Zrew vandle //constructor public Rectangle () ( super(); default width=0; len-0:1 } //setter or mutator methods. public void setWidth (double w) { width w; } public void setLength (double 1) len-1; } //getter or accessor methods public double getLength() {return len;). public double getWidth() { return width;)) ITC 510 Object Oriented Programming II Ogramming II //processor methods public void calculate Area() x pallat & dorect kat depan area-len*width; - } ✓public void calculate Perimeter () ( perimeter 2 len+2*width; - } //printer methods. public void display()) System.out.println("RECTANGLE: "); System.out.println("The width : " +width); System.out.println("The lenght: +1en); +area)"; System.out.println("The area : " System.out.println("The perimeter: " +perimeter); } a file concrete object Circle in //To declare Circle.java //put class circle in a package package twoD; import javax.swing. *; import java.awt.*; import java.awt.event."; import java.text.Decimal Format; //Class declaration and definition. public class Circle extends TwoD V I double radius; //constructor public Circle() super(); radius=0; named ITC 510 Object Oriented Programming II 4 //setter or mutator methods public void setRadius (double r) { radius=r; } //getter or accessor methods public void calculateArea () 1 area-Math.PI*Math.pow (radius, 2); } public void calculatePerimeter () { perimeter 2*Math.PI*radius; } //printer methods public void display() { //Formating Decimal Format dF= new Decimal Format ("0.00"); System.out.println("CIRCLE: "); System.out.println("The width : " +radius); System.out.println("The area : " +dF. format (area)); System.out.println("The perimeter : "1 dF. format (perimeter)); } ↓ Save and compile ITC 510 Object Oriented Programming II STEP 4: Define TestingTwoD.java file as follow and save in different directory //To declare object Testing TwoD. java in a file named //TestingTwoD.java import twoD. TwoD; import twoD. Rectangle;) import twoD.Circle: import java.util.*; public class TestingTwoD |{ public static void main(String args[]) Scanner scanner new Scanner (System.in); String lineSeparator System.getProperty( "line.separator"); scanner.useDelimiter (line Separator); intlottate. Rectangle rec-new Rectangle(); Circle cir= new Circle(); polymorphom //To declare an aray of TwoD ab lokejogans of TwoD td[] new TwoD[5]; may of obje for (int i=0; i<3; i++) { //display menu 1-circle 2-rectangle System.out.print (("Your choice? (1/2) "); 2/1 int c scanner.nextInt (); if (c==1) 1 //input data System.out.print("Input the width :"); double width scanner.nextDouble(); System.out.print("Input the length :"); double len scanner.nextDouble(); //Setting the data into an object rec.setWidth (width); ✔ rec.setLength (len); ✓ //calculation. rec.calculateArea(); rec.calculate Perimeter (); td rec; } "pplication wreefned 5 -Polymophism canne crede
fix it.. thank you! I have provided my code at the bottom, you can
edit it and paste here
class twoD.java
class Rectangle.java
class Circle.java
1 5.2.1 Example 1. Steps: STEP 1: Create a folder named twoD. STEP 2: Defining the following class as abstract class and save in folder. //To declare abstract object TwoD in a file named TwoD.java //Put class TwoD in a package package twoD; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.lang. Math; //Class declaration and definition abstract) public class TwoDeal cless protected double area: protected double perimeter; > //Constructor public TwoD() area=0; perimeter 0; } //Getter or accessor methods public double getArea () { return area;} public double getPerimeter () {return perimeter;} //Processor methods. abstract public void calculateArea(); obsweet method Conly function declado) 3 common dhitute ok on, Caltribute 18 without implemention 2 abstract public void calculatePerimeter (); sed method abstract public void display();d method STEP 3: Define the following classes as the concrete classes and save in the folder twoD. // To declare concrete object Rectangle in a file named // Rectangle.java //Put class Rectangle in a package package twoD; import javax.swing.*; import java.awt."; import java.awt.event."; //class declaration and definition public class Rectangle extends TwoD concrete dags' { double width; double len; Zrew vandle //constructor public Rectangle () ( super(); default width=0; len-0:1 } //setter or mutator methods. public void setWidth (double w) { width w; } public void setLength (double 1) len-1; } //getter or accessor methods public double getLength() {return len;). public double getWidth() { return width;)) ITC 510 Object Oriented Programming II Ogramming II //processor methods public void calculate Area() x pallat & dorect kat depan area-len*width; - } ✓public void calculate Perimeter () ( perimeter 2 len+2*width; - } //printer methods. public void display()) System.out.println("RECTANGLE: "); System.out.println("The width : " +width); System.out.println("The lenght: +1en); +area)"; System.out.println("The area : " System.out.println("The perimeter: " +perimeter); } a file concrete object Circle in //To declare Circle.java //put class circle in a package package twoD; import javax.swing. *; import java.awt.*; import java.awt.event."; import java.text.Decimal Format; //Class declaration and definition. public class Circle extends TwoD V I double radius; //constructor public Circle() super(); radius=0; named ITC 510 Object Oriented Programming II 4 //setter or mutator methods public void setRadius (double r) { radius=r; } //getter or accessor methods public void calculateArea () 1 area-Math.PI*Math.pow (radius, 2); } public void calculatePerimeter () { perimeter 2*Math.PI*radius; } //printer methods public void display() { //Formating Decimal Format dF= new Decimal Format ("0.00"); System.out.println("CIRCLE: "); System.out.println("The width : " +radius); System.out.println("The area : " +dF. format (area)); System.out.println("The perimeter : "1 dF. format (perimeter)); } ↓ Save and compile ITC 510 Object Oriented Programming II STEP 4: Define TestingTwoD.java file as follow and save in different directory //To declare object Testing TwoD. java in a file named //TestingTwoD.java import twoD. TwoD; import twoD. Rectangle;) import twoD.Circle: import java.util.*; public class TestingTwoD |{ public static void main(String args[]) Scanner scanner new Scanner (System.in); String lineSeparator System.getProperty( "line.separator"); scanner.useDelimiter (line Separator); intlottate. Rectangle rec-new Rectangle(); Circle cir= new Circle(); polymorphom //To declare an aray of TwoD ab lokejogans of TwoD td[] new TwoD[5]; may of obje for (int i=0; i<3; i++) { //display menu 1-circle 2-rectangle System.out.print (("Your choice? (1/2) "); 2/1 int c scanner.nextInt (); if (c==1) 1 //input data System.out.print("Input the width :"); double width scanner.nextDouble(); System.out.print("Input the length :"); double len scanner.nextDouble(); //Setting the data into an object rec.setWidth (width); ✔ rec.setLength (len); ✓ //calculation. rec.calculateArea(); rec.calculate Perimeter (); td rec; } "pplication wreefned 5 -Polymophism canne crede