Question

Task #3 Arrays of Objects 1. Copy the files Song java (see Code Listing 7.1), Compact Disc.java (see Code Listing 7.2) and Cl
Code Listing 7.1 (Song.java) /* This class stores data about a song. */ public class Song private String title; private Strin
public class Compact Disc public static void main(String[] args) throws IOException fileReader file = new FileReader(Classic
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
=================================

Ode to Joy
Bach
The Sleeping beauty
Tchaikovsky
Lullaby
Brahms
Canon
Bach
Symphony No 5
Beethoven
The Blue Danube Waltz
Strauss

==============================

// Song.java

public class Song {

   private String title;
   private String artist;

   /**
   * @param title
   * @param artist
   */
   public Song(String title, String artist) {
       this.title = title;
       this.artist = artist;
   }

   /**
   * @return the title
   */
   public String getTitle() {
       return title;
   }

   /**
   * @param title
   * the title to set
   */
   public void setTitle(String title) {
       this.title = title;
   }

   /**
   * @return the artist
   */
   public String getArtist() {
       return artist;
   }

   /**
   * @param artist
   * the artist to set
   */
   public void setArtist(String artist) {
       this.artist = artist;
   }

   /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#toString()
   */
   @Override
   public String toString() {
       return title + " by " + artist+"\n";
   }

}

=================================

package org.students;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class CompactDisk {

   public static void main(String[] args) throws IOException {
       FileReader fr = new FileReader("Classics.txt");
       BufferedReader input = new BufferedReader(fr);
       String title, artist;

       Song cd[] = new Song[6];
       for (int i = 0; i < cd.length; i++) {
           title = input.readLine();
           artist = input.readLine();
cd[i]=new Song(title, artist);
       }
      
       input.close();
       for(int i=0;i<cd.length;i++)
       {
           System.out.print(cd[i]);
       }

   }

}

==================================

output:

Ode to Joy by Bach
The Sleeping beauty by Tchaikovsky
Lullaby by Brahms
Canon by Bach
Symphony No 5 by Beethoven
The Blue Danube Waltz by Strauss

=====================Could you plz rate me well.Thank You

> Exception in thread "main" java.io.FileNotFoundException: Classics.txt (The system cannot find the file specified)
can you tell me how to fix this

Phạm Hiếu Wed, Dec 22, 2021 11:37 PM

Add a comment
Know the answer?
Add Answer to:
Task #3 Arrays of Objects 1. Copy the files Song java (see Code Listing 7.1), Compact...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Lab Objectives Be able to write methods Be able to call methods Be able to declare...

    Lab Objectives Be able to write methods Be able to call methods Be able to declare arrays Be able to fill an array using a loop Be able to access and process data in an array Introduction Methods are commonly used to break a problem down into small manageable pieces. A large task can be broken down into smaller tasks (methods) that contain the details of how to complete that small task. The larger problem is then solved by implementing...

  • Task #1 Character and String Class Methods 1. Copy the files Time.java (code listing 9.1) and...

    Task #1 Character and String Class Methods 1. Copy the files Time.java (code listing 9.1) and TimeDemo.java (code listing 9.2) from the StudentCD or as directed by your instructor. 2. In the Time.java file, add conditions to the decision structure which validates the data. Conditions are needed that will a. Check the length of the string b. Check the position of the colon c. Check that all other characters are digits 3. Add lines that will separate the string into...

  • Java Programming Task #2 String.split and the StringBuilder Class 1. Copy the file secret.txt (Code Listing...

    Java Programming Task #2 String.split and the StringBuilder Class 1. Copy the file secret.txt (Code Listing 9.3) from the Student CD or as directed by your instructor. This file is only one line long. It contains 2 sentences. 2. Write a main method that will read the file secret.txt, separate it into word tokens. 3. You should process the tokens by taking the first letter of every fifth word, starting with the first word in the file. Convert these letters...

  • Please Implement this code using Java Eclipse. CIS 1068 Assignment 8 Warm Up with Objects Due:...

    Please Implement this code using Java Eclipse. CIS 1068 Assignment 8 Warm Up with Objects Due: Wednesday, March 25 70 points (+ up to 15 extra credit) The purpose of this assignment is to give you practice implementing your own classes. It also provides extra practice with arrays. Task Implement a class Task, which is used to represent a job that should be done. It should contain the following private fields: .name text description of what job should be done...

  • Use java and continue stage 2 and 3 stage 1 code public abstract class BabyItem { protected String name;...

    Use java and continue stage 2 and 3 stage 1 code public abstract class BabyItem { protected String name; public BabyItem() { name=""; } public BabyItem(String name) { this.name = name; } public String getName() { return name; } public void setName(String name) { } public abstract double getCost(); } ======================================================================================== public class BabyFood extends BabyItem { private int numberOfJars; private double pricePerDozen; public BabyFood() { super(); numberOfJars = 0; pricePerDozen = 0; } public BabyFood(int numberOfJars, double pricePerDozen) {...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT