The Artima Developer Community
Sponsored Link

Java Answers Forum
anyone can point out the mistakes?

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Ling

Posts: 13
Nickname: ling
Registered: Feb, 2003

anyone can point out the mistakes? Posted: Feb 19, 2003 2:46 AM
Reply to this message Reply
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."));
       	
    }
}
 

Topic: Assignment Help Please Previous Topic   Next Topic Topic: truncating

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use