0% found this document useful (0 votes)
13 views

CSE114Assign6 S24

Uploaded by

Myriam Maamar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

CSE114Assign6 S24

Uploaded by

Myriam Maamar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

CSE 114 Spring 2024: Assignment 6

Due: May 1, 2024 at 11:59 PM [KST]

Read This Right Away


Directions
• At the top of every file you submit, include the following information in a comment
o Your first and last name
o Your Stony Brook email address
• Please read carefully and follow the directions exactly for each problem.
• Your files, Java classes, and Java methods must be named as stated in the directions
(including capitalization). Work that does not meet the specifications may not be
graded.
• Your source code is expected to compile and run without errors. Source code that
does not compile will have a heavy deduction (i.e. at least 50% off).
• You should create your program using a text editor (e.g. emacs, vim, atom,
notepad++, etc).
• You may use the command-line interface to compile and run your programs or you
can now use IntelliJ IDEA.
• Your programs should be formatted in a way that is readable. In other words, indent
appropriately, use informative names for variables, etc. If you are uncertain about
what a readable style is, see the examples from class and textbook as a starting point
for a reasonable coding style.

What Java Features to Use


For this assignment, you are not allowed to use more advanced features in Java than what we have
studied at the time the assignment is posted. If you have a question about features you may use,
please ask!

What to Submit
Combine all your .java files from the problems below into a single zip file named as indicated
in the Submission Instructions section at the end of this assignment. Upload this file to
Brightspace as described in that section.

Multiple submissions are allowed before the due date. Only the last submission will be
graded.

Please do not submit .class files or any that I did not ask for.
Problem 1 (5 Points)
Create a class called Circle2D. This will hold a circle with a specific center given by X and Y
coordinates and having a radius..

Part 1
Define the Circle2D class that contains:
Two fields of type double named x and y that specify the center of the circle.
A field of type double named radius
A no-arg constructor that creates a default circle with (0, 0) for (x, y) and 1.0 for radius.
A constructor that creates a circle with the specified x, y, and radius.
Getter methods for x,y, and radius

Add methods to do the following:


1. A method that returns the area of the circle. The method header is:

public double getArea();

2. A method that returns the perimeter of the circle. The method header is:

public double getPerimeter();

3. A method that returns true if the specified point (x, y) is inside the circle (see the figure
below). The method header is:

public boolean contains(double x, double y);

4. A method that returns true if the specified circle is inside this circle (see the figure below).
The method header is:

public boolean contains (Circle2D circle);

5. A method that returns true if the specified circle overlaps with this circle (see the figure
below). The method header is:

public boolean overlaps(Circle2D circle);

For methods in 3-5 above, see the figures below in part 2.


Part 2

Write a test program named UseCircle2D that creates a Circle2D object c1 with its x, y coordinates
of 2.0, 2.0 and the radius as 5.5.
Display the area and the perimeter of c1. Limit the printed values to 2 decimal places.
Display the result of:

c1.contains(3.0, 3.0)

c1.contains (new Circle2D(4, 5, 10.5))


c1.overlaps(new Circle2D(3, 5, 2.3))
c1.contains(new Circle2D(3, 5, 2.3))
P

(a) (b) (c)


Figure: (a): A point inside the circle. (b): A circle inside another circle. (c): A circle overlaps another
circle.
Turn in Circle2D.java and UseCircle2D.java.

Problem 2 (20 Points)


In this problem, we will model a couple of baseball teams. As you will see below, the entire program
will consist of at least three classes: Player, Team, and UseTeam in Player.java, Team.java, and.
UseTeam java respectively.

I am providing an almost complete implementation of UseTeam.java and your job is to complete the
remainder of UseTeam.java and create Player.java and Team.java in such a way that
UseTeam.java will work without modifying its existing code. By that I mean that you may add more
to UseTeam.java but you are NOT allowed to modify the methods that I have already included. In
other words, you are not allowed to change the signatures of the methods called in UseTeam..

Below this PDF in the assignment, you will see two files:

• UseTeam.java: the use code of the classes that you will provide. Read my comments in
this file carefully. Additional problem requirements are specified in this file.
• output.txt: a sample output generated by running the main of UseTeam in my model
solution. Your completed program will have to generate the output that is identical to my
sample output. The batting averages should be exact or very close (within .001). If you want
to add other features in addition to my sample output, you are welcome to do so, but try to be
brief for readability.

Restrictions: Do not use public fields in the classes that you design. Use private fields and provide
getters and setters where appropriate so that accesses can be made to the fields through the getters and
setters.
Hand in your Player.java, Team.java, and UseTeam.java. If your solution uses additional
files, hand in the source files for them as well.
Submission Instructions
Please follow this procedure for submission:

0. Place the deliverable source files into a folder by themselves (Circle2D.java,


UseCircle2D.java, Player.java, Team.java, and UseTeam.java [if
enhanced]). The folder’s name should be CSE114_HW6_<yourname>_<yourid>. So if your
name is Alice Kim and your id is 12345678, the folder should be named
‘CSE114_HW6_AliceKim_12345678’

1. Compress the folder and submit the zip file.


a. On Windows, do this by clicking the right-mouse button while hovering over the
folder. Select ‘Send to -> Compressed (zipped) folder’. The compressed folder will
have the same name with a .zip extension. You will upload that file to the
Brightspace.
b. On Mac, move the mouse over the folder then right-click (or for single button
mouse, use Control-click) and select Compress. There should now be a file with the
same name and a .zip extension. You will upload that file to the Brightspace.
2. Navigate to the course Brightspace site. Click Assignments in the top navbar menu. Look
under the category ‘Assignments’. Click Assignment6.
a. Scroll down and under Submit Assignment, click the Add a File button.
b. Click My Computer (first item in list).
c. Find the zip file and drag it to the ‘Upload’ area of the presented dialog box.
d. Click the Add button in the dialog.
e. You may write comments in the comment box at the bottom.
f. Click Submit.  Be sure to do this so I or the grading TA can retrieve the
submission!

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy