Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The comments should meet javadoc standards. Block at the top - Summarize the point of the lab, the date and your name Comment each instance

The comments should meet javadoc standards.

  • Block at the top - Summarize the point of the lab, the date and your name

  • Comment each instance variable - what it is

  • Each method should have a comment - the point of the method. If it has a parameter use the @param tag. If you have a return value use the @return tag.

You do not need to comment the driver (other than your name).

In this lab you will create 4 classes

Singer

Song

Album

Driver

Attach the .java for the 4 above programs. The programs should include javadoc comments.

Follow the steps carefully.

  1. Create a class called Singer.java.(Need to import the Scanner and setup)

    1. This class has 2 instance variables

      1. private String fName

      2. private String lName

      3. Also have a static variable called countSinger

    2. Create 3 constructors - each constructor should increment the countSinger variables

      1. One constructor has no parameters. Inside the constructor prompt the user to enter the first and last name and store them in the instance variables.

      2. One constructor has 2 Strings as parameters public Singer(String fn, String ln)

      3. One is a copy constructor

    3. Create setters and getters for each instance variables-(require total 4 methods) public String getFName() - example header for getters public void setFName(String fn) - example header for setter

    4. Create a toString method public String toString()

Output should look like:

Singer is Taylor Swift

  1. Create an equals method - if the first and last name are the same return true, otherwise false public boolean equals (Singer other)

2. Create a class called Driver.

Create three Singer objects using the three constructor. Use setters and getters, toString and equals. Print out the static variable countAuthors

3. Create a class called Song.java. a. It has 3 instance variables( Need to import Scanner and setup)

i. private String title;

ii. private Singer singer;

iii. private double length;

b. Create 3 constructors for Song. One has 3 parameters. The second constructor has no parameters- prompt the user to enter the field.The third is a copy constructor

c. Create a setters/getters for each instance variable.(6 total methods)

d. Create a toString for Song(make sure uses toString from Singer)

public String toString(){

Output should be:

Title is Bad Blood

Singer is Taylor Swift

Length is 2.45 minutes

e. Write an equals method for song. Same Title, singer and length means the songs are the same.

4. Modify the Driver to now create 3 Song objects( use each constructor) and test.

Test the methods you added in Songsetters/getters/toString/equals)

5. Create a class called Album

  1. Library has two instance variables

    1. String name

ii. private ArrayList album = new ArrayList()

b. Album has one constructor - pass the String name . In the constructor prompt for

The number of songs in the album. Use this to make a loop that then prompts the user to

Male a song and add the song to the album..

c. . Write a toString for aLBUM. This method should use a loop that builds up a single String that shows all the information about each SONG. Use the ArrayList get method to get the ong and add to the String.

6. . Modify Driver to include creating a album

  1. Album alb = new Album();

  2. Print out the information- uses toString

c. Run the driver . Copy the output from the terminal window to the Driver program as a comment at the bottom. Go back and make sure you proved in the Driver that each piece of the code worked. Both the true and false part of the equals, all setters/getters etc.

Make sure you do your javadoc

Two points extra credit

Part 3

Boolean 2-d arrays

You can make an array of boolean values. In this case a true is represented by a * and it represents this row is friends with this column. For example friend 0 is friends with 1,3,4.

0

1

2

3

4

0

FALSE

TRUE

FALSE

TRUE

TRUE

1

TRUE

FALSE

TRUE

FALSE

TRUE

2

FALSE

TRUE

FALSE

FALSE

FALSE

3

TRUE

FALSE

FALSE

FALSE

TRUE

4

TRUE

TRUE

FALSE

TRUE

FALSE

Make the above array - easiest way is probably to use nested loops to set all the values to false - then update the true values like friends[0][1]=true and friends [1][0]=true.

Now write code to count the friend pairs.(in the above code the answer is 6 pairs)

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_2

Step: 3

blur-text-image_3

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 Design And SQL For DB2

Authors: James Cooper

1st Edition

1583473572, 978-1583473573

More Books

Students also viewed these Databases questions

Question

What does the start( ) method defined by Thread do?

Answered: 1 week ago