Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Clueless on classes

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Clueless on classes

    I have this project I have to do and I am completely lost.
    public class Album
    {
      private int nPictsInAlbum;
      private Picture[] pictArray;
      private int capacity;
     
      //////////constructors//////////
      public Album(int capacityParam )
      {
        capacity = capacityParam;
      }
     
      //////////methods//////////
      public boolean addPicture( Picture p )
      {
        System.out.println("addPicture( p ) called.  The Picture object param. printed as a String is");
        System.out.println( p );
        return true;
      } 
      public boolean addPicture( Picture p, int where )
      {
        System.out.println("addPicture( p , " + where + " ) called.  The Picture object param. printed as a String is");
        System.out.println( p );
        return true;
      }
      public void explore()
      {
        System.out.println("explore called");
      }
    }
    This is the stub code my professor gave us.
    these are the only 3 method we are supposed to have, also 1 constructor.
    I am clueless on how to complete the explore method he made it print this line so we can figure out what to write in replace of it. The information he gives us on this method is:
    A new Picture is made whose height is the max of the heights, and width is the
    sum of the widths of the stored Picturess. The Pictures in the Album so far are
    copied into a new Picture and that Picture is displayed by calling the
    explore() method on it. All the added Picture copies should start at the top of
    the new Picture and be laid out horizontally, with no overlaps or gaps.


    He doesn't really tell us much info on what we are supposed to be writing in on this. Also I do not know much about class files as this is the first thing we have done with them. If I try to run this it says Static Error: This class does not have a static void main method accepting String[].


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Clueless on classes

    Crossposted here: Creating an album class

    To the original poster, while cross-posting is allowed in this forum, doing so without notifying all threads can frustrate anyone who tries to help you when they find out later that the same answer was given hours ago in a cross-posted thread. No one likes wasting their time, especially a volunteer. The polite thing to do would be that if you feel that you absolutely must cross-post, to at least provide links in both cross-posts to each other.

    --- Update ---

    And your error message is telling you exactly what is wrong -- you can't run a Java program without a main method. Please have a look at the introductory Java tutorials which you can find here:

    The Really Big Index
    The "Hello World!" Application
    Trail: Learning the Java Language

  3. #3
    Junior Member
    Join Date
    Oct 2012
    Posts
    10
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Clueless on classes

    import java.util.Scanner;
    class AlbumTester
    { 
      private static void printChoices()
      {
        System.out.println("add\nadd <0 or positive int>\nshow\nquit");
      } 
     
      public static void main(String[] asdf)
      {
        Scanner sc = new Scanner(System.in);
        System.out.println("Album capacity:");
        int requestedCapacity = sc.nextInt();
        sc.nextLine(); 
        //Read and throw away the newline after the int
        Album myAlbum = new Album(requestedCapacity);
        System.out.println("Pick the directory for your digital images.");
        FileChooser.pickMediaPath();
     
        boolean stillChoosing = true;
        int nAdds = 0;
        while( stillChoosing )
        {
          printChoices();
          String choice = sc.nextLine();
          if(choice.equals("quit"))
          {
            System.out.println("Thanks for the test!");
            stillChoosing = false;
          }
          else if(choice.equals("add"))
          {
            System.out.println("You chose add");
            Picture p = new Picture(FileChooser.pickAFile());
            boolean added;
            added = myAlbum.addPicture(p);
            if(added) nAdds++;
            else System.out.println("addPicture(Picture) returned false.");
          }
          else if(choice.equals("show"))
          {
            System.out.println("You chose show");
            System.out.println("You should see " + nAdds 
                                 + " images in your Album");
            myAlbum.explore();
          }
          else if(choice.startsWith("add "))
          {
            System.out.println("Your choice started with \"add \".");
            String[] tokens = choice.split("\\s+");
            //Purpose: Split the input line into tokens separated by whitespace
            int inputNumber = 0;
            boolean inputNumberOK = false;
            try {
              inputNumber = Integer.parseInt(tokens[1]);
              inputNumberOK = true;   
            }
            catch (NumberFormatException e)
            {
              System.out.println("Whoops, you mistyped the number after add!");
            }
            if(inputNumberOK)
            {
              Picture p = new Picture(FileChooser.pickAFile());
              boolean added;
              added = myAlbum.addPicture(p,inputNumber);
              if(added) nAdds++;
              else System.out.println("addPicture(Picture,int) returned false.");
            }     
          } 
          else
          {
            System.out.println("The command to the tester was not recognized.");
            System.out.println("Try again.");
          }
        }     
        return;
      }
    }
    This is what goes with the class. I need to write something in the explore method so that I can continue with what this program executes which is to create a picture album.

Similar Threads

  1. How to implement GregoraianCalendar which is subclass of Calender?
    By Meirikai in forum Object Oriented Programming
    Replies: 4
    Last Post: October 30th, 2012, 03:15 PM
  2. Clueless on request.getContextPath()
    By ram.java in forum What's Wrong With My Code?
    Replies: 0
    Last Post: August 29th, 2011, 12:07 PM
  3. Need Help with using classes [HELP]
    By dragon40226 in forum Java Theory & Questions
    Replies: 4
    Last Post: May 19th, 2011, 01:59 PM
  4. [SOLVED] First assignment, clueless student, involving coordinates and distances
    By Kerrigan in forum Java Theory & Questions
    Replies: 7
    Last Post: March 10th, 2011, 04:52 PM
  5. [SOLVED] Java program using two classes
    By AZBOY2000 in forum Object Oriented Programming
    Replies: 7
    Last Post: April 21st, 2009, 06:55 AM