Java programming question…?
Java programming question…?
// the following program has a error statement that I dont undestand
// how to fix this (Im a total noob programmer)…any help?
/*
3 errors found:
File: C:\Users\Jonathan\Documents\School\Computer Science\lab-8-combinationLock\CombinationLockTest.java [line: 18]
Error: C:\Users\Jonathan\Documents\School\Computer Science\lab-8-combinationLock\CombinationLockTest.java:18: cannot find symbol
symbol : variable c1
location: class CombinationLockTest
File: C:\Users\Jonathan\Documents\School\Computer Science\lab-8-combinationLock\CombinationLockTest.java [line: 21]
Error: C:\Users\Jonathan\Documents\School\Computer Science\lab-8-combinationLock\CombinationLockTest.java:21: cannot find symbol
symbol : variable c1
location: class CombinationLockTest
File: C:\Users\Jonathan\Documents\School\Computer Science\lab-8-combinationLock\CombinationLockTest.java [line: 24]
Error: C:\Users\Jonathan\Documents\School\Computer Science\lab-8-combinationLock\CombinationLockTest.java:24: cannot find symbol
symbol : variable c1
location: class CombinationLockTest
*/
import java.util.Scanner;
public class CombinationLockTest {
public static void main(String[] args){
Scanner kb = new Scanner(System.in);
String a, b, c;
System.out.println(“This is a Combination Lock tester start ”
+”by imputing any letter or number and pressing enter…”);
a = kb.next();
System.out.println(“imput another letter or number:”);
b = kb.next();
System.out.println(“imput the final letter of number:”);
c = kb.next();
CombinationLock cl = new CombinationLock(a+b+c);
System.out.println(“Now that you have made a combonation lock try opening it.”);
System.out.println(“imput first: “);
String x,y,z;
x=kb.next();
c1.setPosition(x);
System.out.println(“imput second: “);
y=kb.next();
c1.setPosition(y);
System.out.println(“imput third: “);
z=kb.next();
c1.setPosition(z);
}
}
public class CombinationLock {
private boolean myState; // myState is true if the lock is open and
// false otherwise
private String myCombination;// A three character string
// representing the combination
private String myPositions; // A string that represents the positions
// set on the dial. This string can
private int num = 0; // be any length.
/*
Constructs a lock with a given combination. The state is initially
closed (false) and the positions is (are?) an empty string (“”).
@param combination is a string with three uppercase letters A..Z
*/
public CombinationLock(String combination){
myCombination = combination;
myPositions = “”;
myState = false;
}
/*
Set the dial to a position. See chart above for an example.
@param position is a string consisting of a single uppercase letter A..Z
*/
public void setPosition(String aPosition){
myPositions += aPosition;
num++; if(num == 3){
num = 0; unlock(); myPositions = “”;
System.out.println(“Now to find out if that combo was correct type ‘open’”);
}
}
/*
Try unlocking the lock. If the lock is closed and the length of the
positions is >= 3, test to see if the combination is equal to the
last three positions. If they are equal, open the lock otherwise
leave it unchanged.
*/
public void unlock(){
if(myPositions.equals(myCombination))myState = true;
else myState = false;
}
/*
Check whether the lock is unlocked.
@return true if the lock is currently open.
*/
public boolean isOpen(){
return myState;
}
/*
Close the lock and start over by setting the state and the
positions to the empty string “”
*/
public void startOver(){
myState = false;
myCombination = “”;
myPositions = “”;
}
}
omg lol i just found out that the problem was that java didn’t like my naming my object c1 so i changed it to combo and now it works thx for your time anyways…
Best answer:
Don’t worry, happens to all of us.
Tags: java, programming, question
Under Forum

1 Comment for Java programming question…?
1. wanswong | September 22nd, 2008 at 11:42 pm
You declared CombinationLock as “cl” (lower case CL)
However when you assigned them, you use “c1″ — name mismatched.
Leave a Comment for Java programming question…?
You must be logged in to post a comment.
Trackback this post | Subscribe to the comments via RSS Feed