Ling
Posts: 13
Nickname: ling
Registered: Feb, 2003
|
|
anyone can point out the mistakes?
|
Posted: Feb 19, 2003 2:46 AM
|
|
Advertisement
|
Hi, i am writing a program to produce the following output in dos:
Preset password (number only, 3 tries): 12345
Enter password: 12355 No! 2 tires left.
Enter password: 12345 Yes!
I know that my program isn't completed yet but i just hope that someone can point out the mistakes that i have made so far. Thanx!
import java.io.*;
class Lab_03
{
public static void main(String[] args) {
System.out.print("\nPreset password (number only, 3 tries): ");
int i = Integer.parseInt(getKeyboardBuffer());
Password pass = new Password(i);
while (pass.getTriesLeft() > 0) {
System.out.println("Enter password:");
}
}
private static String getKeyboardBuffer() {
String s = "";
try {
s = new BufferedReader(
new InputStreamReader(System.in)).readLine();
}
catch (IOException e) {
System.out.println(e);
}
return s;
}
}
class Password
{
int grace = 3, int attempts = 1;
private int magic;
magic = pass;
public Password(int password, int tries) {
magic = password;
}
public int getTriesLeft() {
int getTriesLeft = 3 - attempts;
}
public boolean verify(int password) {
if (magic == pass && attempts <= grace)
System.out.println("Yes!");
else {
System.out.println("No!" + pass.getTriesLeft() + "tries left."));
}
}
|
|