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

    Default Creating an album class

    I have this project I have to do and I am completely lost.
    Java Code:
    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
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default Re: Creating an album class

    Cross-posted here: Clueless on classes

    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.

  3. #3
    antnas is offline Member
    Join Date
    Oct 2012
    Posts
    15
    Rep Power
    0

    Default Re: Creating an album class

    Quote Originally Posted by curmudgeon View Post
    Cross-posted here: Clueless on classes

    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.
    So sorry about that. I just wanted to get my post out to as many people as possible in a short period of time. After reading this post I can understand how this could be frustrating
    Sorry again everyone.

  4. #4
    curmudgeon is offline Senior Member
    Join Date
    May 2010
    Posts
    436
    Rep Power
    5

    Default Re: Creating an album class

    I have posted an answer in your cross-post. You need to hit the Java tutorials, pure and simple.

  5. #5
    crankzz is offline Member
    Join Date
    Dec 2012
    Posts
    1
    Rep Power
    0

    Default Re: Creating an album class

    Hi, I was just assign a project similar to the one you posted. Is it possible to see the code??

  6. #6
    antnas is offline Member
    Join Date
    Oct 2012
    Posts
    15
    Rep Power
    0

    Default Re: Creating an album class

    Quote Originally Posted by crankzz View Post
    Hi, I was just assign a project similar to the one you posted. Is it possible to see the code??
    This is the code that goes with it.
    Java Code:
    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;
      }
    }

Similar Threads

  1. Replies: 9
    Last Post: 07-29-2011, 02:18 PM
  2. creating class
    By J7571 in forum New To Java
    Replies: 4
    Last Post: 11-18-2010, 02:55 PM
  3. java photo album api
    By karq in forum Advanced Java
    Replies: 3
    Last Post: 11-06-2010, 05:03 PM
  4. Help with creating a class
    By cdawg_2010 in forum New To Java
    Replies: 22
    Last Post: 11-03-2010, 05:34 AM
  5. Java Image Album 1.1
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 07-04-2007, 07:59 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
  •