bbtitle]
» CC HOME » FORUM HOME

Go Back   College Confidential > College Admissions and Search > SAT and ACT Tests & Test Preparation > AP Tests Preparation
New User

Welcome to College Confidential, the leading college-bound community on the Web!
 
Here you'll find hundreds of pages of articles about choosing a college, getting into the college you want, how to pay for it, and much more. You'll also find the Web's busiest discussion community related to college admissions, and our College Visits section!

You are currently viewing the site as a guest.
Registration is simple and easy, and provides full site access.

Join our FREE community:

  • Post and reply to topics
  • Talk privately with other members
  • Participate in polls
  • View less ads
  • Remove this welcome message

 REGISTER NOW

Discussion Menu
»Discussion Home
»Help & Rules
»Latest Posts
»NEW! College Visits
»NEW! Stats Profiles
Top Forums
»College Search
»College Admissions
»Financial Aid
»SAT/ACT
»Parents
»Colleges
»Ivy League
Main CC Site
»College Confidential
»College Search
»College Admissions
»Paying for College
Sponsors
Reply
 
Thread Tools
Old 05-04-2008, 05:02 PM   #1
Junior Member
 
Join Date: May 2008
Posts: 45
Comp Sci AB question: Error in sample free response question?

Was doing a sample free response test and I hit a question where it seems impossible to fulfill all the required postconditions.

Problem 3. (b), on pages 9-12 here:
http://www.collegeboard.com/prod_dow...ter_sci_ab.pdf

I'd copy and paste the text but my adobe reader does not want to seem to cooperate.

Anyways, basically the writer needs to implement two methods of a WaitingList which is a singly linked list class. The second (b) not yet made method when given another linked list and a number of nodes to copy, cuts the last n nodes to the current list.

The problems are that
a) the sizes of the two WaitingLists (as stored in the numNode variable) after moving the nodes must be kept correct.

There is no way I can find to modify the private numNode variable of the passed list. I ended up creating a method that allows the list to be resized but I was only told to make one method.

b) if one is told to move all the nodes from the second WaitingList the list must be made empty

once again there is no way to do this. The WaitingLists keep the references to their front nodes as private variables and there is no way to change these instance fields to null without creating a third method


Is there something I am missing, or is the problem flawed? Cause since this was on the 2006 test one would think that it would have a proper solution. Or are you allowed to create three methods in problems that only call on you to make one?
pyrotix is offline   Reply   
Old 05-04-2008, 05:33 PM   #2
Junior Member
 
Join Date: Apr 2007
Location: Berkeley, CA
Posts: 238
I think I remember my teacher saying that if you had private variables from the same class, you can still access them. In this case, I think you can just do other.numNodes and other.front to modify/access them.
Chairman Meow is offline   Reply   
Old 05-04-2008, 05:39 PM   #3
Member
 
Join Date: Apr 2008
Posts: 310
Well, it's theoretically possible to do both with just one method, although it's not too pretty.

For example, you could define transferNodesFromEnd( WaitingList other, int num ) so that if num is positive, the method proceeds as planned and num is added to the size of the current array. After that is done, you call the method again, this time using other.transferNodesFromEnd( this, -num ). Implement the method so that if num is negative, the size is decremented by that amount; also, if abs(num) equals size(), then set the value of front to null. Essentially, it's a very messy way to utilize one method to do the job of two methods. I bet you were supposed to "assume" there were other methods like setNull() and setSize(), though.

Edit: never mind, the poster above me is correct. That would seem to defeat the entire purpose of encapsulation, but it's right. Controlling Access to Members of a Class (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
Begoner is offline   Reply   
Old 05-04-2008, 07:02 PM   #4
Junior Member
 
Join Date: May 2008
Posts: 45
That's funny. Thanks both of you. You're right about private, I thought that it meant that only methods of the same instance of a class could modify.

Code:
class TheClassCaller {
	public static void main(String[] args) {
		TheClass classA = new TheClass(4);
		TheClass classB = new TheClass(5);
		classB.setOtherValue(classA, 10);
		System.out.println(classA.getValue());
	}
}

class TheClass {
	private int value;

	public TheClass(int aValue) {
		value = aValue;
	}

	public void setOtherValue(TheClass a, int num) {
		a.value = num;
	}

	public int getValue() {
		return value;
	}

}
Returns 10. So the problem is possible just requires pretty ugly programming practices that I was unaware were allowed. Greatly appreciated.
pyrotix is offline   Reply   
Reply

Bookmarks

Thread Tools



All times are GMT -5. The time now is 03:37 PM.


Copyright 2001-2009, Hobsons, Inc., All Rights Reserved