Results 1 to 6 of 6
Thread: Creating an album class
- 12-02-2012, 06:17 AM #1
Member
- Join Date
- Oct 2012
- Posts
- 15
- Rep Power
- 0
Creating an album class
I have this project I have to do and I am completely lost.
This is the stub code my professor gave us.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"); } }
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[].
- 12-02-2012, 06:49 AM #2
Senior Member
- Join Date
- May 2010
- Posts
- 436
- Rep Power
- 4
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.
- 12-02-2012, 06:55 AM #3
Member
- Join Date
- Oct 2012
- Posts
- 15
- Rep Power
- 0
- 12-02-2012, 07:11 AM #4
Senior Member
- Join Date
- May 2010
- Posts
- 436
- Rep Power
- 4
Re: Creating an album class
I have posted an answer in your cross-post. You need to hit the Java tutorials, pure and simple.
- 12-02-2012, 07:29 PM #5
Member
- Join Date
- Dec 2012
- Posts
- 1
- Rep Power
- 0
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??
- 12-02-2012, 10:12 PM #6
Member
- Join Date
- Oct 2012
- Posts
- 15
- Rep Power
- 0
Re: Creating an album class
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
-
Creating and implementing class for creating a calendar object
By kumalh in forum New To JavaReplies: 9Last Post: 07-29-2011, 02:18 PM -
creating class
By J7571 in forum New To JavaReplies: 4Last Post: 11-18-2010, 02:55 PM -
java photo album api
By karq in forum Advanced JavaReplies: 3Last Post: 11-06-2010, 05:03 PM -
Help with creating a class
By cdawg_2010 in forum New To JavaReplies: 22Last Post: 11-03-2010, 05:34 AM -
Java Image Album 1.1
By JavaBean in forum Java SoftwareReplies: 0Last Post: 07-04-2007, 07:59 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks