Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

First I will give you the intro and hints for the Homework, then i will give the

ID: 3568358 • Letter: F

Question

First I will give you the intro and hints for the Homework, then i will give the codes i have written, and the last code is the one the single problem occurs, it says the symbol cannot be found for the word "Song" in the lines 14, and 18 in the last code i have provided. I already appreciate the help, Thanks!

---------------------------------

Task #1 Average Class

Create a class called Average according to the UML diagram.

Average
- data[]: int
- mean: doub le
+ Average()
+ calculateMean(): void
+ toString( ): String
+ selectionSort( ): void


This class will allow a user to enter 5 scores into an array. It will then rearrange the data in
descending order and calculate the mean for the data set.

Attributes:

Explanation / Answer

Task #1: Average Class

Average.Java

import java.util.*;

public class Average {
int data[] = new int[5];//the array which will contain the scores
double mean = 0.0;//the arithmetic average of the scores
int total = 0;
//Average method
public Average() {
System.out.println("Enter the Scores: ");
Scanner scanner = new Scanner(System.in);
for(int i= 0; i<data.length;i++){
data[i] = scanner.nextInt();
}

calculateMean(data);
selectionSort(data);
String str = toString();
System.out.println("The Scores and mean are ");
System.out.println(str);
}
//Calculate method
public void calculateMean(int[] data) {
for(int i= 0; i<data.length;i++){
total = data[i]+total;
}
mean = total/data.length;
}
//toString method
public String toString() {
StringBuilder result = new StringBuilder();
for(int i= 0; i<data.length;i++){
result.append(data[i]);
result.append(" ");
}
result.append(mean);
return result.toString();
}
//selectionSort method
public void selectionSort(int[] data) {
     Arrays.sort(data);
}
}

Task #2 : AverageDriver Class


AverageDemo.java

public class AverageDriver
{
public static void main(String args[])
{
Average average = new Average();
}
}

Sample output:

Enter the Scores:

22

33

44

55

68

The Scores and mean are

22 33 44 55 68 44.0

Task # 3: Array of Objects

CompactDisc.java

//This program creates a list of songs for a CD by reading from a file
import java.io.*;
import java.util.Scanner;
//CompactDisc class
public class CompactDisc {
public static void main(String[] args) throws IOException {
   //Open the file
   File file = new File("Classic.txt");
   Scanner input = new Scanner(file);
   String title;
   String artist;
//object created for Song class
Song[] cd = new Song[6];
for (int i = 0; i < cd.length; i++) {
    title = input.nextLine();
    artist = input.nextLine();
    cd[i] = new Song(title, artist);
}
System.out.println("Contents of Classics: ");
    for (int i = 0; i < cd.length; i++) {
    System.out.println(cd[i]);
}
}
}
Song.java

//Song Class
public class Song
{
//declaring the variables
private String title;
private String artist;
//Constructor
public Song(String title, String artist)
{
   this.title = title;
   this.artist = artist;
}
//toString method
public String toString()
{
   return title + " by " + artist + " ";
}
}

Note: You need to add Classics.txt file.

Sample output:

Contents of Classics:

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

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote