Results 1 to 2 of 2
  1. #1
    RarkMowe is offline Member
    Join Date
    Oct 2012
    Posts
    6
    Rep Power
    0

    Default Unable to call/declare methods. Causes errors such as "Object Not Found"

    Hi guys, I was wondering if somebody could help me with a problem I'm having with one of my assignments. I want to have a music library program that can show the user the contents of his/her library as well as give the ability to edit or delete elements of an array list. For some reason when I create the methods (In a separate methods class?) they cause errors such as "Object not found" & illegal statement? Could somebody take a look at my code and tell me where I went wrong? I would be very grateful




    Main Class

    package ca1;

    import java.util.ArrayList;
    import java.util.Scanner;

    public class MainClass extends UserInput {

    public String nextInt;

    public static void main(String[] args) {
    Scanner keyb = new Scanner(System.in);
    UserInput ui = new UserInput(); // Declaring object to store user input
    Scanner input = new Scanner(System.in);

    Song s;
    int opt;



    //initial prompt
    System.out.println("Welcome");



    //do loop
    do {




    //declare array list
    ArrayList<String> library = new ArrayList<>();

    //add items to array list
    library.add("Track 1");
    library.add("Track 2");
    library.add("Track 3");
    library.add("Track 4");
    library.add("Track 5");



    //Menu Prompts
    System.out.println("........ \n");
    System.out.println("Press 0 to Exit\n");
    System.out.println("Press 1 to View All Songs\n");
    System.out.println("Press 2 to Add a Song\n");
    System.out.println("Press 3 to Remove a Song\n");
    System.out.println("Press 4 to Edit a Song\n");
    System.out.println("Press 5 to Count Songs\n");
    System.out.println("Press 5 to Delete All Songs\n");
    opt = input.nextInt();
    String opt1 = input.nextLine();





    //if statements
    if (opt == 0) {

    System.out.println("You have selected option " + opt + "\n");
    System.out.println("Goodbye!");
    } else if (opt == 1) {
    System.out.println("You have selected option " + opt + "\n");
    System.out.println(library);
    } else if (opt == 2) {
    System.out.println("You have selected option " + opt + "\n");
    System.out.println("Please name your new track");

    } else if (opt == 3) {
    System.out.println("You have selected option " + opt + "\n");
    System.out.println("Please select what you would like to remove from your library");
    System.out.println(library);
    } else if (opt == 4) {
    System.out.println("You have selected option " + opt + "\n");
    System.out.println("What song would you like to edit?");
    System.out.println(library);
    } else if (opt == 5) {
    System.out.println("You have selected option " + opt + "\n");
    System.out.println("There are " + library.size() + " songs in your music library");
    } else if (opt == 6) {


    System.out.println("You have selected option " + opt + "\n");
    System.out.println("Are you sure you want to delete all?");
    System.out.println("Y/N");


    if (opt1 == "y") {
    library.removeAll(library);
    } else if (opt1 == "n") {

    System.out.println("okay");
    }





    } else {
    System.out.println("Incorrect Entry");
    }

    } //do-while loop
    while (opt > 0);

    }
    }

    Method Class


    package ca1;

    public class Methods extends MainClass {


    public void editLibrary(){

    }

    public void deleteSongs(){

    }

    public void exitSys (){

    }

    public void deleteAll()
    {
    System.out.println("You have selected option\n");
    System.out.println("Are you sure you want to delete all?");
    System.out.println("Y/N");
    }
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Unable to call/declare methods. Causes errors such as "Object Not Found"

    You didn't bother to return to the first thread you started.

    You didn't bother to find out and apply what Reeling told you about code tags.

    Not the best way to continue to get free help on a forum, that.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 0
    Last Post: 02-02-2012, 07:24 AM
  2. Replies: 1
    Last Post: 08-07-2011, 02:35 AM
  3. Replies: 4
    Last Post: 06-14-2011, 04:59 AM
  4. Replies: 3
    Last Post: 05-21-2009, 03:48 PM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •