Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Supporting Files Driverjaya Person.java Rectangle.java Course Concept(s) Covered Refactoring Using Objects Basic Class Structure Instance Variables Instructions Create a folder called CSC1130_Using Classes_4_yourlastname, Store all

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Supporting Files Driverjaya Person.java Rectangle.java Course Concept(s) Covered Refactoring Using Objects Basic Class Structure Instance Variables Instructions Create a folder called CSC1130_Using Classes_4_yourlastname, Store all of the files for this lab in that folder. Once you have completed the lab, upload the zipped folder in Canvas You will need the code from: Rectangle.java, Person.java, and Driver java to complete this tab. . Fix the documentation so it has your name in it. . Look through the Rectangle class and make a list of all of the fields (he, attributes) and methods te behaviors) a Rectangle possesses (you can write these within comments in the code Compile and execute the code. Were all of the Rectangle's behaviors utilized? If not, which one(s) was not? Hy it bad programming to create a method in a class that a program is not using (be sure you can explain your answer)? . Once you have successfully executed your project, try to change it so that after calculating the area of the rectangle. It asks for the radius of a circle and calculates the area of the circle. To do this, you will need to write a new Circle class which means you will create a Circle.java file) - use the Rectangle class as a guide. You will also need to change the Driver class * Name: 1 2 3 4 5 6 7 8 9 10 11 12 Description: The Driver class is part of a minimal application that allows the user to enter data and work with a Rectangle 13 import java.util.Scanner; public class Driver 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 public static void main(String args (1) { Person user; Rectangle r; double len; double wid; Scanner sc = new Scanner(System.in); System.out.println("What is your name?"); user = new Person(sc.nextLine()); System.out.println(" Hello " + user.getName() + ","); System.out.println("You can enter the dimensions of a rectangle."); System.out.println("The area of the rectangle will then be calculated"); System.out.println("and displayed."); 32 33 34 35 36 37 38 System.out.println(" Enter the length of the rectangle:"); len - sc.nextDouble(); System.out.println(" Enter the width of the rectangle:"); wid = sc.nextDouble(); 20 r = new Rectangle(len, wid); 39 40 41 42 43 44 45 System.out.println(" The area of the rectangle is: + r.getArea()); } Name: * * * public class Person { String name; 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 Person() { name = "Anonymous"; } Person(String id) { name = id; } public String getName() { return name; } } Name: 1 2 3 4 5 6 7 8 9 10 11 class Rectangle { double length; double width; 12 13 14 15 16 17 18 19 20 21 Rectangle() { length = 0; width = 0; } 22 Rectangle (double 1, double w) { length = 1; width = w; } 23 24 25 26 27 28 29 30 31 32 33 34 35 36 public double getArea() { return length * width; } public double getPerimeter() { return 2 * length + 2 * width; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Reliability Engineering Designing And Operating Resilient Database Systems

Authors: Laine Campbell, Charity Majors

1st Edition

978-1491925942

More Books

Students also viewed these Databases questions