Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help with this codding assignment. I'm using java netbeans. I can't figure out how to print the contents of an array. Please leave comments

Please help with this codding assignment. I'm using java netbeans. I can't figure out how to print the contents of an array. Please leave comments explaining what you did, thank you, and on how to do input.

DOMAIN

/*This program represents a song*/

public class Song { private String title; //The title of the song private String artist; //The artist who sings the song /** * constructor * * @param title The title of the song * @param artist The artist who sings the song */ public Song() { } public Song(String title, String artist) { this.title = title; this.artist = artist; }

/** * toString method returns a description of the song * * @return a String containing the name of the song and the artist */ public String toString() { return title + " by " + artist; } }

DRIVER

/*This program creates a list of songs for a CD by reading from a file*/

import java.io.*;

public class CompactDisc { public static void main(String[] args) throws IOException { FileReader file = new FileReader("Classics.txt"); BufferedReader input = new BufferedReader(file); String title; String artist; Song cd[] = new Song[6];

//Declare an array of songs, called cd, of size 6

for (int i = 0; i < cd.length; i++) { System.out.println("Enter title: " + i); title = input.readLine(); System.out.println("Enter artist: " + i); artist = input.readLine(); // fill the array by creating a new song with // the title and artist and storing it in the // appropriate position in the array }

System.out.println("Contents of Classics:"); for (int i = 0; i < cd.length; i++) { //print the contents of the array to the console System.out.println(cd.toString()); } } }

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

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions

Question

s. Discuss what is meant by high- and low-

Answered: 1 week ago