Kelsey kelskjs

Ranch Hand
+ Follow
since Nov 07, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Kelsey kelskjs

How come this isn't running right now? Isn't this what I was supposed to do?...are there areas that you can see that need to be fixed?...please help me to get this running right...

19 years ago
Am I on the right rack?

19 years ago
I understand how many people thing it is a homework problem, and indeed it could be...but like I said I am just really trying to visualize how this example in the book would work...and therefore learn by putting that code into eclipse to make it work...to see the process and how each segment of the code would work...so thats why I was searching out just help on the last part of that coding...so I could move on...when I did research on the recursion part of fibonacci, All of the examples which I did find made it to where I had not 2 inputs of n and k which I need to have, in order to solve this problem...they simply did it with the:

public static int fibonacci (int n)
{
if (n == 0 || n == 1)
return n;
else
return fibonacci (n - 1) + fibonacci (n - 2);
}

but I know that I need to have the list sequence be the output on one single line from inputing a k and a n value...to find the nth sequence...I just do not know how to write the code to do so...

thats why I was just looking for the finishing touch so I could move on and learn more material...thank you...
19 years ago
I have...all morning...for 6 hours now I have googled the life out of this! haha!...I don't understand it and was hoping that someone could just help me with the code so that I can at least look at it, I learn from examples and I was hoping someone could help me this way...please...
19 years ago
this isn't a homework problem but thank you...i am just trying to do these practice problems on my own to better understand the information before i take an advanced placement test...i am patient, and will be even more so...thank you for your response...
19 years ago
can someone please see if they can respond to my earlier post please!? i am desperately trying to work on this right now...thank you...
19 years ago
I have a question that I was curious if anyone could help me fill in the missing code, I have no idea how to go about finishing this up in order to have it completed...

I need to take as input the values for k and n and output the nth member of the k-step sequence on a line by itself...for the fibonacci numbers. I am to do this recursively. I am to implement a generalization of the fibonacci sequence called the fibonacci k-step number. The idea is to add up the previous k values to get the next, rather than just the previous two. Example sequences are like this...
k sequence
1 1,1,2,2,2,2
2 1,1,2,4,5,8
3 1,1,2,4,7,13,24,44,81
4 1,1,2,4,8,15,29,108

Again, I need to take as input the values for n and k and output the nth member orf the k-step sequence on a line by itself...

Here is what I have so far, can anyone help me see what I need to add in order to complete this? Thank you so much.

/**
* This class computes the k step Fibonacci sequence.
*
*/
public class Fibonacci {
public Fibonacci(){}

public int solveIt(int k, int n){

}

public static void main(String[] args) {
int k=4; //the default values
int n=9;
//here we look for k and n on the command line:
if(args.length ==2){
try{
k = Integer.parseInt(args[0]);
n = Integer.parseInt(args[1]);
}catch(Exception e){
System.out.println("Improper arguments. Using k="+k+" and n="+n);
}
}
else{
System.out.println("Improper arguments. Using k="+k+" and n="+n);
}
//now we do the work:
Fibonacci f = new Fibonacci();
int sol = f.solveIt(k,n);
System.out.println(sol);
}
}
19 years ago
I'm sorry I didn't know I couldn't post in more than one forum to get help...its just that I'm really worried about this and I can't figure it out...I just wanted someone to help me...please....I'm sorry I didn't know the rules of this site, I guess...
20 years ago
Hello. I am new to JAVA and I am really confused by this problem that I am trying to work on..I am supposed to write a program using BlueJ to create a stoplight with a black rectangle as its base and three individual lamps inside, a red, yellow and green lamp that each turn on and off and when they turn off and another color turns on...they must return to being black. I have no idea how to go about this...all I know is that these methods should be used..can someone please help me get on the right track? I am supposed to create a Lamp class and a TrafficLight class...and the MyApp class is as below:
import OOPS.SP.*;
public class MyApp extends OOPS.SP.Frame
{
private Simulation _light;
public MyApp()
{
// initialize instance variables
_light = new Simulation();
_light.runSimulation(30);
}

/**
* Method to run the program
*/
public static void main( String[] argv)
{
new MyApp();
}
}
And this is the Simulation class...
public class Simulation
{
// instance variables
private TrafficLight _light1;
private TrafficLight _light2;
/**
* Constructor for objects of class Simulation
*/
public Simulation()
{
int startCycleTime, timeLightStaysOn;
// initialize instance variables
_light1=new TrafficLight(50,50);
_light2=new TrafficLight(250,50);
_light1.setCycleTimes(7,2,5);
_light2.setCycleTimes(10,3,7);
}
/**
* An method to run the simulation for the specified time
*
* @param time amount of time to run simulation
*/
public void runSimulation(int time)
{
int startCycleTime, timeLightStaysOn;
for (int currTime=1; currTime<time; currTime++)
{
startCycleTime = _light1.getWhenLastChanged();
timeLightStaysOn = _light1.getTimeOn();
if ((currTime-startCycleTime) >= timeLightStaysOn)
_light1.cycle(currTime);
startCycleTime = _light2.getWhenLastChanged();
timeLightStaysOn = _light2.getTimeOn();
if ((currTime-startCycleTime) >= timeLightStaysOn)
_light2.cycle(currTime);
}
}
}
Now I am supposed to create a Lamp class with the following in it...
Class Lamp
Instance variables:
� The color of the light bulb, or glass cover of the light bulb. It should be of type java.awt.Color.
� The circle that represents the light bulb. It will be black when turned off and the specified color when turned on.
� An int to specify how long the light should stay on. Note: for realism the time the red lamp is on should be the sum of the times for the yellow and the green lamps.
Methods:
� Lamp() � A default constructor which places the lamp at the center or the frame. The lamp is red, and the lamp is set to off. The time on is set to 1.
� Lamp(int x, int y) � A constructor, which sets the lamp to an arbitrary color, instantiates the circle, specifies that the lamp is off, and that the time on is 1, and the next lamp to itself, or 0. The lamp is placed at position (x,y), where x,y defines the position of the upper left corner of a square which circumscribes the circle.
� Lamp(java.awt.Color, int x, int y) - A constructor, with a parameter for the color which stores the color of the lamp, and creates a lamp which is on and of that color, the time is again set to 1, and the next lamp is set to itself or 0.
� void turnOn() - A method to turn the lamp on.
� void turnOff() - A method to turn the lamp off.
� void setTimeOn(int) - A method to set the value of the time the light is on, again it will take one parameter, which is the time to be used.
� int getTimeOn() - A method to return the time the light is to be on
And then the trafficLight class with the following...
Class TrafficLight
The traffic light consists of a black box that holds three lamps (from top to bottom: red, yellow, green).
Instance variables:
 The black box for the traffic light.
 The three instance variables of type Lamp, one for the red light, one for the yellow light, and one for the green light.
 The time the light last changed, which is an int.
 The lamp that is on, which can be an int, a java.awt.Color, or a Lamp.
Methods:
� TrafficLight() - The default constructor, which will construct the light with its three lamps in their correct position based on the lamp being in the center of the screen. It will also set the red light on, and the time the light last changed to 1.
� TrafficLight(int x, int y) - The default constructor, which will construct the light with its three lamps in their correct position based on the upper left corner of the lamp being at position (x,y) on the center of the screen. It will also set the red light on, and the time the light last changed to 1.
� void cycle(int) � This method will cycle the lights, by turning the current light which is on to off, and turning the next light that should be turned on to on. Note: It will enforce the cycle pattern: red ->green; green -> yellow, and yellow -> red. It will also store the int into the time when the light last changed.
� int getWhenLastChanged() � This method will return the time when the light last changed.
� int getTimeOn() � This method will return the time the light which is currently on is supposed to stay on.
� void setCycleTimes(int red, int yellow, int green) � This method will set the instance variables for the time the lamp is to be on, in each instance of the lamps, to the appropriate values. The time on for the red lamp will be set red. The time on for the yellow lamp will be set to yellow, and the time on for the green lamp will be set to green.

Please help me understand how to implement these all together and how to create a class based on the definitions above. I am not asking for the answer necessarily, I just need a frame to work from...please help me...
20 years ago
Hello. I am new to JAVA and I am really confused by this problem that I am trying to work on..I am supposed to write a program using BlueJ to create a stoplight with a black rectangle as its base and three individual lamps inside, a red, yellow and green lamp that each turn on and off and when they turn off and another color turns on...they must return to being black. I have no idea how to go about this...all I know is that these methods should be used..can someone please help me get on the right track? I am supposed to create a Lamp class and a TrafficLight class...and the MyApp class is as below:
import OOPS.SP.*;
public class MyApp extends OOPS.SP.Frame
{
private Simulation _light;
public MyApp()
{
// initialize instance variables
_light = new Simulation();
_light.runSimulation(30);
}

/**
* Method to run the program
*/
public static void main( String[] argv)
{
new MyApp();
}
}
And this is the Simulation class...
public class Simulation
{
// instance variables
private TrafficLight _light1;
private TrafficLight _light2;
/**
* Constructor for objects of class Simulation
*/
public Simulation()
{
int startCycleTime, timeLightStaysOn;
// initialize instance variables
_light1=new TrafficLight(50,50);
_light2=new TrafficLight(250,50);
_light1.setCycleTimes(7,2,5);
_light2.setCycleTimes(10,3,7);
}
/**
* An method to run the simulation for the specified time
*
* @param time amount of time to run simulation
*/
public void runSimulation(int time)
{
int startCycleTime, timeLightStaysOn;
for (int currTime=1; currTime<time; currTime++)
{
startCycleTime = _light1.getWhenLastChanged();
timeLightStaysOn = _light1.getTimeOn();
if ((currTime-startCycleTime) >= timeLightStaysOn)
_light1.cycle(currTime);
startCycleTime = _light2.getWhenLastChanged();
timeLightStaysOn = _light2.getTimeOn();
if ((currTime-startCycleTime) >= timeLightStaysOn)
_light2.cycle(currTime);
}
}
}
Now I am supposed to create a Lamp class with the following in it...
Class Lamp
Instance variables:
� The color of the light bulb, or glass cover of the light bulb. It should be of type java.awt.Color.
� The circle that represents the light bulb. It will be black when turned off and the specified color when turned on.
� An int to specify how long the light should stay on. Note: for realism the time the red lamp is on should be the sum of the times for the yellow and the green lamps.
Methods:
� Lamp() � A default constructor which places the lamp at the center or the frame. The lamp is red, and the lamp is set to off. The time on is set to 1.
� Lamp(int x, int y) � A constructor, which sets the lamp to an arbitrary color, instantiates the circle, specifies that the lamp is off, and that the time on is 1, and the next lamp to itself, or 0. The lamp is placed at position (x,y), where x,y defines the position of the upper left corner of a square which circumscribes the circle.
� Lamp(java.awt.Color, int x, int y) - A constructor, with a parameter for the color which stores the color of the lamp, and creates a lamp which is on and of that color, the time is again set to 1, and the next lamp is set to itself or 0.
� void turnOn() - A method to turn the lamp on.
� void turnOff() - A method to turn the lamp off.
� void setTimeOn(int) - A method to set the value of the time the light is on, again it will take one parameter, which is the time to be used.
� int getTimeOn() - A method to return the time the light is to be on
And then the trafficLight class with the following...
Class TrafficLight
The traffic light consists of a black box that holds three lamps (from top to bottom: red, yellow, green).
Instance variables:
 The black box for the traffic light.
 The three instance variables of type Lamp, one for the red light, one for the yellow light, and one for the green light.
 The time the light last changed, which is an int.
 The lamp that is on, which can be an int, a java.awt.Color, or a Lamp.
Methods:
� TrafficLight() - The default constructor, which will construct the light with its three lamps in their correct position based on the lamp being in the center of the screen. It will also set the red light on, and the time the light last changed to 1.
� TrafficLight(int x, int y) - The default constructor, which will construct the light with its three lamps in their correct position based on the upper left corner of the lamp being at position (x,y) on the center of the screen. It will also set the red light on, and the time the light last changed to 1.
� void cycle(int) � This method will cycle the lights, by turning the current light which is on to off, and turning the next light that should be turned on to on. Note: It will enforce the cycle pattern: red ->green; green -> yellow, and yellow -> red. It will also store the int into the time when the light last changed.
� int getWhenLastChanged() � This method will return the time when the light last changed.
� int getTimeOn() � This method will return the time the light which is currently on is supposed to stay on.
� void setCycleTimes(int red, int yellow, int green) � This method will set the instance variables for the time the lamp is to be on, in each instance of the lamps, to the appropriate values. The time on for the red lamp will be set red. The time on for the yellow lamp will be set to yellow, and the time on for the green lamp will be set to green.

Please help me understand how to implement these all together and how to create a class based on the definitions above. I am not asking for the answer necessarily, I just need a frame to work from...please help me...
20 years ago
Hello. I am new to JAVA and I am really confused by this problem that I am trying to work on..I am supposed to write a program using BlueJ to create a stoplight with a black rectangle as its base and three individual lamps inside, a red, yellow and green lamp that each turn on and off and when they turn off and another color turns on...they must return to being black. I have no idea how to go about this...all I know is that these methods should be used..can someone please help me get on the right track? I am supposed to create a Lamp class and a TrafficLight class...and the MyApp class is as below:
import OOPS.SP.*;
public class MyApp extends OOPS.SP.Frame
{
private Simulation _light;
public MyApp()
{

// initialize instance variables
_light = new Simulation();
_light.runSimulation(30);
}

/**
* Method to run the program
*/
public static void main( String[] argv)
{
new MyApp();
}
}
And this is the Simulation class...
public class Simulation
{
// instance variables
private TrafficLight _light1;
private TrafficLight _light2;
/**
* Constructor for objects of class Simulation
*/
public Simulation()
{

int startCycleTime, timeLightStaysOn;
// initialize instance variables
_light1=new TrafficLight(50,50);
_light2=new TrafficLight(250,50);
_light1.setCycleTimes(7,2,5);
_light2.setCycleTimes(10,3,7);
}
/**
* An method to run the simulation for the specified time
*
* @param time amount of time to run simulation
*/
public void runSimulation(int time)
{
int startCycleTime, timeLightStaysOn;
for (int currTime=1; currTime<time; currTime++)
{
startCycleTime = _light1.getWhenLastChanged();
timeLightStaysOn = _light1.getTimeOn();
if ((currTime-startCycleTime) >= timeLightStaysOn)
_light1.cycle(currTime);
startCycleTime = _light2.getWhenLastChanged();
timeLightStaysOn = _light2.getTimeOn();
if ((currTime-startCycleTime) >= timeLightStaysOn)
_light2.cycle(currTime);
}
}
}
Now I am supposed to create a Lamp class with the following in it...
Class Lamp
Instance variables:
�The color of the light bulb, or glass cover of the light bulb. It should be of type java.awt.Color.
�The circle that represents the light bulb. It will be black when turned off and the specified color when turned on.
�An int to specify how long the light should stay on. Note: for realism the time the red lamp is on should be the sum of the times for the yellow and the green lamps.
Methods:
�Lamp() � A default constructor which places the lamp at the center or the frame. The lamp is red, and the lamp is set to off. The time on is set to 1.
�Lamp(int x, int y) � A constructor, which sets the lamp to an arbitrary color, instantiates the circle, specifies that the lamp is off, and that the time on is 1, and the next lamp to itself, or 0. The lamp is placed at position (x,y), where x,y defines the position of the upper left corner of a square which circumscribes the circle.
�Lamp(java.awt.Color, int x, int y) - A constructor, with a parameter for the color which stores the color of the lamp, and creates a lamp which is on and of that color, the time is again set to 1, and the next lamp is set to itself or 0.
�void turnOn() - A method to turn the lamp on.
�void turnOff() - A method to turn the lamp off.
�void setTimeOn(int) - A method to set the value of the time the light is on, again it will take one parameter, which is the time to be used.
�int getTimeOn() - A method to return the time the light is to be on
And then the trafficLight class with the following...
Class TrafficLight
The traffic light consists of a black box that holds three lamps (from top to bottom: red, yellow, green).


Instance variables:
The black box for the traffic light.
The three instance variables of type Lamp, one for the red light, one for the yellow light, and one for the green light.
The time the light last changed, which is an int.
The lamp that is on, which can be an int, a java.awt.Color, or a Lamp.
Methods:
�TrafficLight() - The default constructor, which will construct the light with its three lamps in their correct position based on the lamp being in the center of the screen. It will also set the red light on, and the time the light last changed to 1.
�TrafficLight(int x, int y) - The default constructor, which will construct the light with its three lamps in their correct position based on the upper left corner of the lamp being at position (x,y) on the center of the screen. It will also set the red light on, and the time the light last changed to 1.
�void cycle(int) � This method will cycle the lights, by turning the current light which is on to off, and turning the next light that should be turned on to on. Note: It will enforce the cycle pattern: red ->green; green -> yellow, and yellow -> red. It will also store the int into the time when the light last changed.
�int getWhenLastChanged() � This method will return the time when the light last changed.
�int getTimeOn() � This method will return the time the light which is currently on is supposed to stay on.
�void setCycleTimes(int red, int yellow, int green) � This method will set the instance variables for the time the lamp is to be on, in each instance of the lamps, to the appropriate values. The time on for the red lamp will be set red. The time on for the yellow lamp will be set to yellow, and the time on for the green lamp will be set to green.

Please help me understand how to implement these all together and how to create a class based on the definitions above. I am not asking for the answer necessarily, I just need a frame to work from...please help me...
20 years ago
Can someone show me how to write that though? I don't know what both of you are saying...I cannot seem to figure that out, like how to write it. I'm sorry...
20 years ago
Yes, I did correct the tokenarr part of that problem. It did compile fine without any errors. The box appeared with the "Enter the sentence" for the user to type in a string, then when pressing enter the text area which should have shown the reverse order of that string that was entered did not show up. Instead, the compiler showed this message.
What do I do now, so that the reverse order of the string will show as output??
C:\Documents and Settings\Kels\kelsey>java TokenTest
java.lang.NullPointerException
at TokenTest$1.actionPerformed(TokenTest.java:61)
at javax.swing.JTextField.fireActionPerformed(JTextField.java:491)
at javax.swing.JTextField.postActionEvent(JTextField.java:672)
at javax.swing.JTextField$NotifyAction.actionPerformed(JTextField.java:7
86)
at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1530)
at javax.swing.JComponent.processKeyBinding(JComponent.java:2438)
at javax.swing.JComponent.processKeyBindings(JComponent.java:2473)
at javax.swing.JComponent.processKeyEvent(JComponent.java:2401)
at java.awt.Component.processEvent(Component.java:4909)
at java.awt.Container.processEvent(Container.java:1569)
at java.awt.Component.dispatchEventImpl(Component.java:3615)
at java.awt.Container.dispatchEventImpl(Container.java:1627)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.ja
va:1713)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboard
FocusManager.java:627)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeybo
ardFocusManager.java:831)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeybo
ardFocusManager.java:741)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFoc
usManager.java:592)
at java.awt.Component.dispatchEventImpl(Component.java:3506)
at java.awt.Container.dispatchEventImpl(Container.java:1627)
at java.awt.Window.dispatchEventImpl(Window.java:1606)
at java.awt.Component.dispatchEvent(Component.java:3477)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:456)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
read.java:201)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)
20 years ago
Now I fixed, or seemed to fix all the other problems except this error ran on the compiler for my code. What should I do to fix this? And to make it run finally?
C:\Documents and Settings\Kels\kelsey>javac TokenTest.java
TokenTest.java:50: cannot resolve symbol
symbol : method countTokens ()
location: class java.lang.String
StringTokenizer[st.countTokens()];
^
1 error
20 years ago
Okay, I did make that change to length-1 and re-compiled the program, and I was given the following errors.
C:\Documents and Settings\Kels\kelsey>javac TokenTest.java
TokenTest.java:1: 'class' or 'interface' expected
> import javax.swing.*;
^
TokenTest.java:2: 'class' or 'interface' expected
> import java.util.*;
^
TokenTest.java:3: 'class' or 'interface' expected
> import java.awt.event.*;
^
TokenTest.java:4: 'class' or 'interface' expected
> import java.awt.*;
^
TokenTest.java:5: 'class' or 'interface' expected
>
^
TokenTest.java:7: '{' expected
> {
^
TokenTest.java:20: unclosed string literal
> prompt = new JLabel("Enter a sentence and press
^
TokenTest.java:21: unclosed string literal
> enter");
^
TokenTest.java:92: '}' expected
} // end of Class TokenTest
^
9 errors
I am new to this and I do not know how to correct these at all. Can someone help me so that my program can run properly? Please.
Thank you. I really appreciate it.
20 years ago