Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Completed part 1 JUST NEED PART 2 PLEASE! import java.util.Scanner; import java.

ID: 3808330 • Letter: C

Question

Completed part 1 JUST NEED PART 2 PLEASE!

import java.util.Scanner;

import java.text.DecimalFormat;

import java.io.BufferedWriter;

import java.io.File;

import java.io.FileWriter;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.OutputStreamWriter;

import java.io.Writer;

public class TestCircle

{

  

   public class Circle

   {

       //Declare needed variable

       private final double PI_Val = 3.14159;

       private double cRadius;

       private String cColor;

       private String cLabel;

     

       //Constructor

       public Circle()

       {

           //Initialize

           cRadius = 0.0;

       }

     

       //Constructor

       public Circle(double r)

       {

           //Initialize

           cRadius = r;

         

       }

     

       //Constructor

       public Circle(double r, String c, String l)

       {

           //Initialize

           cRadius = r;

           cColor= c;

           cLabel =l;

       }

     

       //Method setcRadius()

       public void setcRadius(double r)

       {

           //Initialize

           cRadius = r;

       }

       //Method getcRadius()

       public double getcRadius()

       {

           //Return

           return cRadius;

       }

       //Method getcColor()

       public String getcColor()

       {

           //Return

           return cColor;

       }

     

       //Method getcLabel()

       public String getcLabel()

       {

           //Return

           return cLabel;

       }

     

       //Method setcLabel()

       public void setcLabel()

       {

           //Initialize

           cLabel = "a1";

       }

     

       //Method getcArea()

       public double getcArea()

       {

           //Return

           return PI_Val * cRadius * cRadius;

       }

     

       //Method getcCircumference()

       public double getcCircumference()

       {

           //Return

           return 2 * PI_Val * cRadius;

       }

   }

   //Driver

   public static void main(String[] args)

   {

       //Create instance

       Scanner ourSc = new Scanner(System.in);

     

       //Create instance

       DecimalFormat two = new DecimalFormat("#0.00");

     

       //Prompt for input

       System.out.print("What is the label of the circle? ");

     

       //Read input

       String cLabel = ourSc.next();

             

       //Prompt for input

       System.out.print("What is the color of the circle? ");

     

       //Read input

       String cColor = ourSc.next();

     

       //Prompt for input

       System.out.print("What is the radius of the circle? ");

     

       //Read input

       double cRadius = ourSc.nextDouble();

     

       //Close scanner

       ourSc.close();

       //Create instance

       TestCircle ccT = new TestCircle();

       Circle circle = ccT.new Circle(cRadius);

       //Output

       System.out.println(" ");

       System.out.println("The color of the circle is: " + cColor);

       System.out.println("The radius of the circle is: " + cRadius);

       System.out.println("The area of the circle is " + two.format(circle.getcArea()));

       System.out.println("The circumference of the circle is " + two.format(circle.getcCircumference()));

     

       //Create instance

       BufferedWriter foutput = null;

       //Try     

       try

       {

//Output

           String fpath="out.txt";

File file = new File(fpath);

//Check

           if (!file.exists())

           {

file.createNewFile();

}

         

           //Create instance

FileWriter fw1 = new FileWriter(file.getAbsoluteFile());

BufferedWriter bw1 = new BufferedWriter(fw1);

// Write in file

bw1.write(" The color of the circle is: " + cColor);

           bw1.write(" The radius of the circle is: " + cRadius);

           bw1.write(" The area of the circle is " + two.format(circle.getcArea()));

           bw1.write(" The circumference of the circle is " + two.format(circle.getcCircumference()));

           // Close connection

bw1.close();

}

     

       //Catch

catch(Exception e)

       {

//Display

           System.out.println(e);

}

   }

}

Project 2-part 1 1. In the following picture, you can see the diagram of class circle. Design class Circle with the following information: Circle tvarName: type-default-value denotes private access -radius: double-1.0 -color: String "green" denotes public access label: String al +Circle0 Overloaded constructors +Circle(r: double) +Circle double, c string, l:strin +getRadius 0: double +methodName ame: +getArea0: double type, return Type +getCircumference 0: double +getLabel0: string +setLabel(l: string) void Class Circle contains: three instance variables radius: it is a private instance variable ofthe type double, with default value of 1.0. color it is a private instance variable of the type String), with default value of"green". label: it is a public instance variable of the type String), with default value of"groupl".

Explanation / Answer

TestCylinder.java


import java.util.Scanner;

public class TestCylinder {

  
   public static void main(String[] args) {
       Scanner scan = new Scanner(System.in);
       System.out.println("Enter the radius1: ");
       double r = scan.nextDouble();
       System.out.println("Enter the height1: ");
       double h = scan.nextDouble();
      
       Cylinder c = new Cylinder(h, r);
       System.out.println(c.toString());
       System.out.println("Area: "+c.getArea());
       System.out.println("Volumn: "+c.getVolumn());
       System.out.println("Circumreference: "+c.getCircumference());
      
       System.out.println("Enter the radius2: ");
       double r2 = scan.nextDouble();
       System.out.println("Enter the height2: ");
       double h2 = scan.nextDouble();
       System.out.println("Enter the color2: ");
       String color = scan.next();
       System.out.println("Enter the label: ");
       String l = scan.next();
      
       Cylinder c1 = new Cylinder(h2, r2,color,l);
       System.out.println(c1.toString());
       System.out.println("Area: "+c1.getArea());
       System.out.println("Volumn: "+c1.getVolumn());
       System.out.println("Circumreference: "+c1.getCircumference());
      
   }

}

Circle.java

public class Circle {
   private double radius;
   private String color;
   private String label;
  
   public Circle(){
       radius = 1.0;
       color = "green";
       label = "a1";
   }
   public Circle(double r){
       radius = r;
       color = "green";
       label = "a1";
   }
   public Circle(double r, String c, String l){
       radius = r;
       color = c;
       label = l;
   }
  
   public String getColor() {
       return color;
   }
   public String getLabel() {
       return label;
   }
   public void setLabel(String label) {
       this.label = label;
   }
   public double getRadius() {
       return radius;
   }
   public double getArea() {
       return radius * radius * Math.PI;
   }
   public double getCircumference() {
       return 2 * Math.PI * radius;
   }
}

Cylinder.java

public class Cylinder extends Circle{

   private double height ;
   public Cylinder() {
       height = 1.0;
   }
   public Cylinder(double r){
       super(r);
   }
   public Cylinder(double h,double r){
       super(r);
       height = h;
   }
   public Cylinder(double h,double r, String c, String l){
       super(r,c,l);
       height = h;
   }
   public double getHeight() {
       return height;
   }
   public void setHeight(double height) {
       this.height = height;
   }
   public double getVolumn(){
       return getArea() * height;
   }
   public String toString() {
       return "Cylinder [radius="+ getRadius()+" height= "+getHeight()+" Color= "+getColor()+" Label: "+getLabel();
   }
}

Output:

Enter the radius1:
1.1
Enter the height1:
2.2
Cylinder [radius=1.1 height= 2.2 Color= green Label: a1
Area: 3.8013271108436504
Volumn: 8.362919643856031
Circumreference: 6.911503837897546
Enter the radius2:
3.3
Enter the height2:
4.4
Enter the color2:
red
Enter the label:
c1
Cylinder [radius=3.3 height= 4.4 Color= red Label: c1
Area: 34.21194399759284
Volumn: 150.5325535894085
Circumreference: 20.734511513692635

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote