Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6190839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:39:35+00:00 2026-05-24T02:39:35+00:00

I have to write a program with 3 classes and lots of different methods.

  • 0

I have to write a program with 3 classes and lots of different methods.
I’ve written a simpler example to try and get an idea where I am going wrong

First class (music) is defining a music object with three data types. And should have a method to print the contents of an array.

the second class (musicArray) has all the data for the array and should build the array when the third class tells it too.

the third class(searchclass) has the main method it should tell the second class to make the array then with user input search the array for songs that match the rating.

        import java.util.Arrays;

public class Music extends musicArray {

        private  String songTitle;
        private  double songLength;
        private  int rating;
        static String everything;

    public Music(String songTitle, double songLength, int rating) {
           this.songTitle = songTitle;
           this.songLength = songLength;
           this.rating = rating;
        }
    public  String getsongTitle()
    {
        return songTitle;
    }
    public  double getsongLength()
    {
        return songLength;
    }
    public    int rating()
    {
        return rating();
    }
@Override
public String toString() {
    return "music{"+ "songTitle= " + songTitle + ", songLength=  "
    + songLength + ",rating=" + rating + '}';
}
    public Music[] printsonglibrary(char[][] songDetails){

         for (int count = 0; count <= 6; count++)
             {
             return System.out.println(songDetails[count]);
             System.out.println(" ");
             }
         }
}

public class musicArray extends Searchclass{

    static Music song1 = new Music ("achy breaky", 5.32, 10);
    static Music song2 = new Music ("billy",1.2, 8 );
    static Music song3 = new Music ("hello", 1.5, 9 );
    static //Create array and make posistion 0 = song1

    Music[] songDetails ={song1,song2,song3};
        import java.util.Scanner;

        public class Searchclass {
      public static void main(String[] args) {
        for(int count = 1; count <= songDetails.length; count++){
         system out put for debugging
          System.out.println(songDetails.length);
          System.out.println(songDetails[count - 1]);}
        }

        /* public String songSeach(){
        System.out.println("what rating of song do you want to search for?");
        Scanner keyboard = new Scanner(System.in);
        int searchValue = keyboard.nextInt();
         if searchValue == rating in array use the printsonglibrary
        method in the music class to print the array entry
   */
        }
}  

If I have the main method in the musicArray class I can print the array
So the question is how do I make the Songdetails array available in the seachclass?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T02:39:37+00:00Added an answer on May 24, 2026 at 2:39 am

    You shouldn’t directly expose any variables of one class to another. Instead consider giving the MusicArray class (note that by convention class names should begin with a capital letter) a public method, say public void printOutSongDetails() that would print out the contents of the array. Your main method can then call this method off of the MusicArray object that it has created. e.g.,

    Edit 1
    Also, the Music class should most definitely not extend the MusicArray class for there is no way that a Music object should behave like a MusicArray object. And on the same token, MusicArray should not extend the SearchClass.

    Edit 2
    Note that there are several other significant issues with your code that each one would prevent it from compiling, and this suggests that you should modify how you program (if you can’t use an IDE). Try to compile early and often, and only add new code to the program after fixing any compilation errors so that the current code base compiles.

    Edit 3
    A small code example of what I was describing above.

    class SearchClass {
       public static void main(String[] args) {
          MusicArray musicArray = new MusicArray();
          musicArray.addMusic(new Music("Foobars Unit", 10.4, 5));
          musicArray.addMusic(new Music("Spamalot", 11.0, 7));
          //... etc ...
    
          musicArray.printOutSongDetails();
       }
    }
    

    Also, you’ll probably not want those static Music variables but rather give MusicArray a method to add Music to its array, a public void addMusic method that accepts a Music object as a parameter.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write a program used internally where different users will have different
I have already written a C++ program and I would like to write a
I'm doing a test program to write in a xml. I have 3 classes:
I have written a simple program that use some classes and procol buffers. These
I have to write a program that read from a file that contains the
I have to write a program that sniffs network packets (part1-the simple part). And
I have been asked to write a program using python for an assignment. I
I have been assigned wit the task to write a program that takes a
I wanted to write a program that test if two files are duplicates (have
I have been asked to write a java program on linux platform. According to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.