Question
Create a Java Eclipse project named lastfirstA01, replacing last and first with your name. Unless otherwise stated, each object should be alone in a file.
Create a Java Eclipse project named lastfirstA01, replacing last and first with your name. Unless otherwise stated, each object should be alone in a file. Remember: You must use methods effectively to avoid duplicating code. Be sure to zip and submit the entire project.
Do not use inheritance or polymorphism in this lab
Create a package called shapes. It will hold a location object and different shape objects. In package shapes:
o Create a class called Location that has Two private integers that represent the coordinate location in 2D space named, x and y Note: We will refer to coordinates as (x, y), e.g., (0, 0)
A default no-argument constructor that sets the coordinate to (0, 0)
A constructor with two parameters. The parameters are named x, y just like the class members. The arguments will set the coordinate values
Public accessors and mutators for x, y
Public accessor that returns this Location object
A public method that calculates the distance from (0, 0) Returns the distance as a double Uses the Euclidian formula for distance = square root of ((x2-x1)2 + (y2-y1)2)) You can hard code x2 and y2 as 0.
A public print() method that uses printf to print the current state as (x, y), e.g., (1, 2) This method will have no arguments
A properly overridden public toString() method Returns the current state as the string (x, y), e.g. (1, 2)
A properly overridden public equals method Returns equal if the coordinates match between the two objects
A properly overridden the compareTo() method Bases the comparison on the distance the objects are from (0, 0) Hint: remember how to compare doubles to a tolerance of 0.0001 Hint: Collections.sort would order them in ascending order by distance from (0, 0)
o Create a class for each of the following shapes: Rectangle, Circle, Cube, and Sphere. Each shape must: Be in a separate file
Have private double class members to represent dimensional aspects according to the shape (for example, length, width, height, radius, etc.) to calculate areas and volumes You will need to find out what dimensions are needed for areas and volumes A shape only has the dimension needed for it
Private String that stores its name, e.g., rectangle
Private Location object, instantiated in the constructors
Have a default no-argument constructor that Instantiates and sets the location to (0, 0) Sets the name to its name, e.g., rectangle Sets dimension measures to 0.0
Have a constructor that Instantiates and sets the location to (0, 0) Sets the name, but not using a passed in value Sets dimensions to arguments passed in
Have a constructor that Sets the dimension and location to arguments passed into it The location argument is a Location object passed in Set the shape name, but not using a passed in value
Public accessors and mutators for each dimensional member (e.g. length, width, etc.)
Public accessor to return the name Public accessor to return the location object (i.e., returns a Location)
Public mutator for the Location that has two arguments for (x, y)
Public mutator for the Location that has one argument for a Location object
Public method to calculate and return the area (2D objects only)
Public method to calculate and return the surface area (3D objects only)
Public method to calculate and return the volume (3D object only)
Private print methods that uses printf and prints doubles to four decimal places Double are formatted to 4 decimal places One that prints area (if 2D object) or surface area (if 3D object) One that prints volume for (if 3D objects) One that prints the current state (name, location, and dimensions)
Public print method that displays all information of the object, e.g.: rectangle (1, 2) l = 2.5500, w = 2.5500 Area = 6.5025
A properly overridden public toString() method Returns the string name (x, y) A = value for 2D objects o Example: rectangle (1, 2) A = 6.5025 Returns the string name (x, y) SA = value V = value for 3D objects o Example: sphere (1, 2) SA = 6.5025 V= 99.9535 Doubles are formatted to 4 decimal places
A properly overridden the compareTo() method Bases the comparison on the area the objects Hint: remember how to compare doubles to a tolerance of 0.0001 Collections.sort should order them in ascending order by area If 2D, use the area; if 3D, use the surface area
A properly overridden public equals method Returns equal if the areas are equal between the two objects Hint: remember how to compare doubles to a tolerance of 0.0001 If 2D, used the area; if 3D, use the surface area
A properly overridden public clone() method to perform a deep copy
Use the Java Math library for Pi, powers, and square roots as needed
Create a package called example. This will hold your driver program. In package example:
o Create a class called Driver with one main method
o The main method should read the data file locations.txt of coordinates For each line, read in the two coordinates and instantiate a Location object Put each Location object in an array list Use Collections.sort to sort the locations Print the sorted list by having System.out.println automatically use the toString() method You will not know how many locations in my test file, so read until the end of the file
o The main method should read the data file shapes.txt of shapes For each line, read in the name, location, and dimension, and instantiate the shape Each line format is String int int double [double] The first int is x, the second int is y, for the location If it is a rectangle, it will have two doubles; otherwise one double
Put each shape object in an array list for that object type (i.e., there is an array list for each type)
Use Collections.sort to sort each array list
Print the sorted lists by having System.out.println automatically use the toString method
------------------------------------------Locations.txt----------------------------------------
53 86 79 96 19 -53 -98 47 -91 14 -14 70 -90 6 -83 -67 89 -99 70 76 67 63 -4 27 -37 53 -80 23 15 3 -21 -49 -44 6
--------------------------Shapes.txt-------------------------
rectangle 29 3 21.91 99.67 circle 76 -93 12.35 sphere -84 29 35.47 cube -84 55 15.66 rectangle 52 -56 75.21 52.13 sphere 39 36 83.59 rectangle 27 86 68.87 42.92 circle 2 -58 0.63 circle 0 53 51.05 cube 83 -30 17.79 rectangle -68 39 49.91 49.75 cube -99 3 54.02 sphere -34 -44 78.22 rectangle 88 -73 73.03 56.72 sphere 21 86 28.49 circle 74 -11 69.33 circle -88 -29 76.89
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started