Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
|
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 10th, 2005, 03:19 AM
Registered User
 
Join Date: Nov 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Question regarding linking and moving - any advice

Hey Everyone,

Thanks for reading, heres what I'm trying to do I have an array of say 10 items each item contains the text / description for a room.

Now I would like to create a class (lets call it BookSection) this class will display the text for the current room the user is in and then have links to other rooms (left, right, east, west, etc) then dependant upon the choice made by the user will move to the new room and display the text

I've come up with the following code and after searching the books I have (Head First Java, Just Java 2 and How to Program Java) and checking online I'm at a loss and was wondering if anyone had any idea how to code this (based on the bad and very limited code I have below)

class booksection{
int index //page number
string text //the story
int[]choices // the pages links
}

to display a page the program would display the string and the choices
and then load the choice the user made

method getchoices(page, thispage){
string text = "choises are"
thispage.choices.length
for (int i=0; i<2, i++){
text = text+thispage.choice[i]
}

return text
}

this would display the story and the appropriate choices

Any replies are greatly appreciated.


 
Old November 10th, 2005, 10:32 AM
Registered User
 
Join Date: Nov 2005
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey everyone,

someone I know gave me some advice but I'm not entirely sure what to do

You should have a booksection class. This class can only contain methods and variables related to a booksection so,

a booksection can have an int ID, String text, ArrayList or array of choices: int[] choice;
and the methods it can implement are for example:(although there may be more)

public String getText(){
 return text;
}

public String getchoices(){ <----- see the difference between this and yours. No parameters
 String response = "choices are";
 for (int i=0; i<choices.length, i++){
 response = response+choice[i]
}

So each booksection can now output its text and choices.
In the main section not the booksection class we can (assuming we have created a booksection object called myBookSection) get the choices for a specific booksection by using for example:

String choices= myBookSection.getchoices();

The important point here is that each booksection object can now return the text and choices that it contains. In the main java file, you have to find the right booksection id from your ArrayList and then use its methods.

In the main program you should create around 10 booksection objects (read from file or hard coded) and add these to an ArrayList of type <booksection>.

The functionality for operating the book and turning to different booksections should be implemented in the main java file.

If the user selects page 10 for example, you should find the booksection with id 10 from your ArrayList of booksections and display the text and the links for this page. This is then a recursive process.

Pseudo code for navigating the book:

create an empty booksection object
get the first page from your book arraylist and assign it to the booksection object created above

While (number of links in booksection is not equal to 0)

{
 Display the booksection id
 Display the booksection text
 Get the user to input the id of the next booksection -(use getchoice method)
 Get the user selected page from your book arraylist and assign it to the booksection object created above
}






Similar Threads
Thread Thread Starter Forum Replies Last Post
static linking question mwindham BOOK: Professional Assembly Language 1 April 24th, 2007 11:51 AM
some advice please? liquidmonkey Java Basics 1 May 4th, 2006 08:54 AM
Need some advice wariental HTML Code Clinic 1 March 25th, 2006 09:48 PM
Advice 95_rifleman VB Databases Basics 2 February 13th, 2006 08:15 AM
Button linking question hlchuah77 Javascript How-To 4 September 18th, 2004 05:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.