College Discussion

Go Back   College Discussion > College Admissions and Search > SAT and ACT Tests & Test Preparation > AP Tests Preparation
Register FAQ     Search Today's Posts Mark Forums Read

 
Welcome to College Discussion at College Confidential, the Web's leading discussion forum for college admissions, financial aid, SAT prep, and much more! You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, etc. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us.
   College Confidential is dedicated to providing the best free college admissions information available on the Web, through our many articles and this discussion forum.

This welcome message goes away when you register and log in!
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, 04:02 PM   #1
Junior Member
 
Join Date: May 2008
Threads: 6
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  
Old 05-04-2008, 04:33 PM   #2
Junior Member
 
Join Date: Apr 2007
Location: CA
Threads: 6
Posts: 76
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  
Old 05-04-2008, 04:39 PM   #3
Junior Member
 
Join Date: Apr 2008
Threads: 4
Posts: 198
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  
Old 05-04-2008, 06:02 PM   #4
Junior Member
 
Join Date: May 2008
Threads: 6
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


Thread Tools

 


All times are GMT -5. The time now is 12:49 AM.


Copyright 2001-2008, CollegeConfidential.com, Inc., All Rights Reserved
SEO by vBSEO 3.1.0