f



COMPUTER PROJECT

import java.io.*;
class Account1
{
    static InputStreamReader x=new InputStreamReader(System.in);
    static BufferedReader y=new BufferedReader(x);
    public static void Account()throws IOException
    {
        
        System.out.println("\f");
        System.out.println("Enter your name");
        String aa=y.readLine();
        int l=aa.length();
        for(int i=0;i<l;i++)
        {
            char ch=aa.charAt(i);
           int p=(int)ch;
            while(p<67 ||p>122)
            {
                System.out.println("Error please retype");
                System.out.println("Enter your name");
                aa=y.readLine();
            }
        }
        System.out.println("Enter your age");
        int ab=Integer.parseInt(y.readLine());

        while(ab>120 || ab<=0)
        {
            System.out.println("You are either too young or old to use the compouter try again");
            ab=Integer.parseInt(y.readLine());
        }

        System.out.println("Enter 1 for male enter 2 for female");
        int ac=Integer.parseInt(y.readLine());
        while(ac>=1 && ac<=2)
        {
            System.out.println("Error there are only two options");
            System.out.println("Enter 1 for male enter 2 for female");
            ac=Integer.parseInt(y.readLine());
        }

        System.out.println("Enter your username(max 10 characters )");
        String aat=y.readLine();
        while(aat.length()>10)
        {
            System.out.println("Error retype");
            aat=y.readLine();
        }

        System.out.println("Enter password for account(max 10 charcters)");
        String ad=y.readLine();
        while(ad.length()>10)
        {
            System.out.println("Please enter correctly again");
            ad=y.readLine();
        }

        System.out.println("Confirm password");
        String ae=y.readLine();
        while(ae.equals(ad))
        {
            System.out.println("pls enter properly");
            ae=y.readLine();
        }

        System.out.println("Enter birthday dd mm yyyy separately please");
        System.out.println("Example day=2");
        System.out.println(" day=2");
        System.out.println(" month=2");
        System.out.println(" year=2001");
        
        int age=Integer.parseInt(y.readLine());
        while(age>31 && age<0)
        {
            System.out.println("Error!Enter agian");
            age=Integer.parseInt(y.readLine());
        }
        int month=Integer.parseInt(y.readLine());
        while(month<=12 && month>0)
        {
            System.out.println("errorenter agian");
            month=Integer.parseInt(y.readLine());
        }
        int year=Integer.parseInt(y.readLine());
        while(year<2016 && year>1915)
        {
            System.out.println("Error enter agian");
            year=Integer.parseInt(y.readLine());
        }
        System.out.println("Enter 8 digit landline number");
        long aaam=Long.parseLong(y.readLine());
        while(aaam<10000000 && aaam>99999999) 
        { 

            System.out.println("Error retype moblie number");
            aaam=Long.parseLong(y.readLine());
        }

        System.out.println("Your location is Perungudi");
        

        System.out.println("YOU HAVE CREATED YOUR ACCOUNT.ENTER ANY NUMBER TO PROCEED");
        int ak=Integer.parseInt(y.readLine());

    }
}



In this program if i enter wrong value it doesnt say ERROR BUT I PUT CORRECT STATEMENT it says error.Please help.
0
naarayana
11/30/2016 5:47:36 AM
comp.lang.java.programmer 52714 articles. 0 followers. Post Follow

6 Replies
102 Views

Similar Articles

[PageSpeed] 4

On 11/30/2016 12:47 AM, naarayana.kumar@gmail.com wrote:
> import java.io.*;
> class Account1
> [...]

     Is this the *exact* program you are running?  I notice, for example,
that it has no `main' method, which is the method Java calls to start a
program.  (It is possible to run a program in other ways, but unusual.)

> In this program if i enter wrong value it doesnt say ERROR BUT I PUT CORRECT STATEMENT it says error.Please help.

     It would be helpful to know what "wrong value" and what "CORRECT
STATEMENT" you entered.  Without knowing that, all I can do is guess
at what is going on.

     Here's a guess at one of the problems.  In this fragment:

 >         String aa=y.readLine();
 >         int l=aa.length();
 >         for(int i=0;i<l;i++)
 >         {
 >             char ch=aa.charAt(i);
 >            int p=(int)ch;
 >             while(p<67 ||p>122)
 >             {
 >                 System.out.println("Error please retype");
 >                 System.out.println("Enter your name");
 >                 aa=y.readLine();
 >             }
 >         }

.... consider what happens if the user entered "NAARAYANA" at the first
`readLine' call.  The `for' loop inspects the entered characters, one by
one.  The 'N' gives `p' the value 78, so the `while' loop is skipped.
Then the 'A' sets `p' to 65, which is less than 67, so the program goes
into the `while' loop.  Inside, it outputs "Error please retype" and
"Enter your name", then reads another line.  What is the value of `p'
at this point?  It is still 65, so the `while' loop executes again:
It outputs "Error please retype" and "Enter your name" and reads a
third line.  And since `p' is still 65, the loop executes yet again ...
If the `while' ever executes at all, it will keep on executing forever
no matter what you enter, until you pull the plug.

     You will learn (I'm surprised that you have not already learned)
that there are less error-prone ways to write the numerical codes for
'C' and 'z' than 67 and 122.  You could instead have written

	char ch = aa.charAt(i);
	while (ch < 'C' || ch > 'z')

.... if that was truly your intent -- although I have no idea why you
reject names containing 'A' and 'B' while accepting some others with
obvious non-letters; it seems "Cr[_a_]zy^" to me, but ...

     I have not studied the rest of your code, in part because of the
strong suspicion that what you have shown is *not* actually your code
but some kind of paraphrase.  Even without study, though, I'd bet that
the problem I describe is only one of several.  If you need further
help with additional problems, please post the *exact* code you run,
and show *exactly* what you entered and *exactly* the output you got --
no "something like" or "sort of," but *exact*.

-- 
esosman@comcast-dot-net.invalid
"Nobody ever went broke underestimating the intelligence of the
American public." -- HLM (paraphrased)
0
Eric
11/30/2016 1:38:49 PM
naarayana.kumar@gmail.com <naarayana.kumar@gmail.com> wrote:
>         System.out.println("Enter your name");
>         String aa=y.readLine();
>         int l=aa.length();
>         for(int i=0;i<l;i++)
>         {
>             char ch=aa.charAt(i);
>            int p=(int)ch;
>             while(p<67 ||p>122)
>             {
>                 System.out.println("Error please retype");
>                 System.out.println("Enter your name");
>                 aa=y.readLine();
>             }
>         }
> In this program if i enter wrong value it doesnt say ERROR BUT I PUT CORRECT STATEMENT it says error.Please help.

One approach to find bugs is to step it through in thoughts. 
It writes the prompt, reads the name, then iterates over each 
character of the name.

If the character's code, e.g. 65 for 'A' satisfies the while-
condition, then ...

now, try to continue.

0
Andreas
11/30/2016 2:30:40 PM
On 2016-11-30 12:47 AM, naarayana.kumar@gmail.com wrote:
> import java.io.*;
> class Account1
> {
>     static InputStreamReader x=new InputStreamReader(System.in);
>     static BufferedReader y=new BufferedReader(x);
>     public static void Account()throws IOException
>     {
>
>         System.out.println("\f");
>         System.out.println("Enter your name");
>         String aa=y.readLine();
>         int l=aa.length();
>         for(int i=0;i<l;i++)
>         {
>             char ch=aa.charAt(i);
>            int p=(int)ch;
>             while(p<67 ||p>122)
>             {
>                 System.out.println("Error please retype");
>                 System.out.println("Enter your name");
>                 aa=y.readLine();
>             }
>         }
>         System.out.println("Enter your age");
>         int ab=Integer.parseInt(y.readLine());
>
>         while(ab>120 || ab<=0)
>         {
>             System.out.println("You are either too young or old to use the compouter try again");
>             ab=Integer.parseInt(y.readLine());
>         }
>
>         System.out.println("Enter 1 for male enter 2 for female");
>         int ac=Integer.parseInt(y.readLine());
>         while(ac>=1 && ac<=2)
>         {
>             System.out.println("Error there are only two options");
>             System.out.println("Enter 1 for male enter 2 for female");
>             ac=Integer.parseInt(y.readLine());
>         }
>
>         System.out.println("Enter your username(max 10 characters )");
>         String aat=y.readLine();
>         while(aat.length()>10)
>         {
>             System.out.println("Error retype");
>             aat=y.readLine();
>         }
>
>         System.out.println("Enter password for account(max 10 charcters)");
>         String ad=y.readLine();
>         while(ad.length()>10)
>         {
>             System.out.println("Please enter correctly again");
>             ad=y.readLine();
>         }
>
>         System.out.println("Confirm password");
>         String ae=y.readLine();
>         while(ae.equals(ad))
>         {
>             System.out.println("pls enter properly");
>             ae=y.readLine();
>         }
>
>         System.out.println("Enter birthday dd mm yyyy separately please");
>         System.out.println("Example day=2");
>         System.out.println(" day=2");
>         System.out.println(" month=2");
>         System.out.println(" year=2001");
>
>         int age=Integer.parseInt(y.readLine());
>         while(age>31 && age<0)
>         {
>             System.out.println("Error!Enter agian");
>             age=Integer.parseInt(y.readLine());
>         }
>         int month=Integer.parseInt(y.readLine());
>         while(month<=12 && month>0)
>         {
>             System.out.println("errorenter agian");
>             month=Integer.parseInt(y.readLine());
>         }
>         int year=Integer.parseInt(y.readLine());
>         while(year<2016 && year>1915)
>         {
>             System.out.println("Error enter agian");
>             year=Integer.parseInt(y.readLine());
>         }
>         System.out.println("Enter 8 digit landline number");
>         long aaam=Long.parseLong(y.readLine());
>         while(aaam<10000000 && aaam>99999999)
>         {
>
>             System.out.println("Error retype moblie number");
>             aaam=Long.parseLong(y.readLine());
>         }
>
>         System.out.println("Your location is Perungudi");
>
>
>         System.out.println("YOU HAVE CREATED YOUR ACCOUNT.ENTER ANY NUMBER TO PROCEED");
>         int ak=Integer.parseInt(y.readLine());
>
>     }
> }
>
>
>
> In this program if i enter wrong value it doesnt say ERROR BUT I PUT CORRECT STATEMENT it says error.Please help.
>
I don't know what tools you are using to develop your program but you 
may want to consider something like Eclipse, which is free and includes 
many tools to help you right better code. One of the most useful tools 
in Eclipse - and many other development environments - is a debugger 
which lets you execute your program one statement at a time and monitor 
the values of the variables in the program. That would let you see how 
the program actually behaves, as opposed to the way you *want* it to 
behave. As you soon as you see the behaviour diverge from what you 
wanted, you've found the problem in your code. (Or at least *one* 
problem in your code; if you keep going through the code, you'll likely 
find others.)

-- 
Rhino
0
Rhino
11/30/2016 4:26:00 PM
On 11/30/2016 11:26 AM, Rhino wrote:
> On 2016-11-30 12:47 AM, naarayana.kumar@gmail.com wrote:
>> [...]
> I don't know what tools you are using to develop your program but you
> may want to consider something like Eclipse, which is free and includes
> many tools to help you right better code.

     I'd recommend against this course, at Naarayana's current stage of
learning.  IDE's are indeed useful tools, but they are complex tools
that take time and effort to learn.  A beginner, I think, would be
better off with a command line and a plain-vanilla file editor, so as
not to be confronted with learning Java *and* a complicated IDE at the
same time.  Too steep a learning curve, plus the chance to get confused
about what Java does and what the IDE does.

> One of the most useful tools
> in Eclipse - and many other development environments - is a debugger
> which lets you execute your program one statement at a time and monitor
> the values of the variables in the program. That would let you see how
> the program actually behaves, as opposed to the way you *want* it to
> behave. As you soon as you see the behaviour diverge from what you
> wanted, you've found the problem in your code. (Or at least *one*
> problem in your code; if you keep going through the code, you'll likely
> find others.)

     A way to accomplish much of this without needing to learn how to use
somebody's debugger is to sprinkle the code with print statements that
display the values of "interesting" variables.  They are easy to insert,
easy to remove -- and easy to understand.

-- 
esosman@comcast-dot-net.invalid
"Nobody ever went broke underestimating the intelligence of the
American public." -- HLM (paraphrased)
0
Eric
11/30/2016 5:03:48 PM
On Wednesday, November 30, 2016 at 12:04:07 PM UTC-5, Eric Sosman wrote:
>      I'd recommend against this course, at Naarayana's current stage of
> learning.  IDE's are indeed useful tools, but they are complex tools
> that take time and effort to learn.  A beginner, I think, would be
> better off with a command line and a plain-vanilla file editor, so as
> not to be confronted with learning Java *and* a complicated IDE at the
> same time.  Too steep a learning curve, plus the chance to get confused
> about what Java does and what the IDE does.
> 
> > One of the most useful tools
> > in Eclipse - and many other development environments - is a debugger
> > which lets you execute your program one statement at a time and monitor
> > the values of the variables in the program. That would let you see how
> > the program actually behaves, as opposed to the way you *want* it to
> > behave. As you soon as you see the behaviour diverge from what you
> > wanted, you've found the problem in your code. (Or at least *one*
> > problem in your code; if you keep going through the code, you'll likely
> > find others.)
> 
>      A way to accomplish much of this without needing to learn how to use
> somebody's debugger is to sprinkle the code with print statements that
> display the values of "interesting" variables.  They are easy to insert,
> easy to remove -- and easy to understand.
> 

I taught myself Java from scratch using Eclipse, but after years of coding in other languages.
For a beginner who hasn't coded before Eclipse is fine if there's an expert to help.  To teach themselves maybe a beginner IDE like BlueJ?
0
Eric
11/30/2016 6:04:44 PM
On Wednesday, November 30, 2016 at 5:38:58 AM UTC-8, Eric Sosman wrote:
> On 11/30/2016 12:47 AM, naarayana.kumar@gmail.com wrote:
> > import java.io.*;
> > class Account1
> > [...]
> 
>      Is this the *exact* program you are running?  I notice, for example,
> that it has no `main' method, which is the method Java calls to start a
> program.  (It is possible to run a program in other ways, but unusual.)
> 
> > In this program if i enter wrong value it doesnt say ERROR BUT I PUT CORRECT STATEMENT it says error.Please help.
> 
>      It would be helpful to know what "wrong value" and what "CORRECT
> STATEMENT" you entered.  Without knowing that, all I can do is guess
> at what is going on.
> 
>      Here's a guess at one of the problems.  In this fragment:
> 
>  >         String aa=y.readLine();
>  >         int l=aa.length();
>  >         for(int i=0;i<l;i++)
>  >         {
>  >             char ch=aa.charAt(i);
>  >            int p=(int)ch;
>  >             while(p<67 ||p>122)
>  >             {
>  >                 System.out.println("Error please retype");
>  >                 System.out.println("Enter your name");
>  >                 aa=y.readLine();
>  >             }
>  >         }
> 
> ... consider what happens if the user entered "NAARAYANA" at the first
> `readLine' call.  The `for' loop inspects the entered characters, one by
> one.  The 'N' gives `p' the value 78, so the `while' loop is skipped.
> Then the 'A' sets `p' to 65, which is less than 67, so the program goes
> into the `while' loop.  Inside, it outputs "Error please retype" and
> "Enter your name", then reads another line.  What is the value of `p'
> at this point?  It is still 65, so the `while' loop executes again:
> It outputs "Error please retype" and "Enter your name" and reads a
> third line.  And since `p' is still 65, the loop executes yet again ...
> If the `while' ever executes at all, it will keep on executing forever
> no matter what you enter, until you pull the plug.
> 
>      You will learn (I'm surprised that you have not already learned)
> that there are less error-prone ways to write the numerical codes for
> 'C' and 'z' than 67 and 122.  You could instead have written
> 
> 	char ch = aa.charAt(i);
> 	while (ch < 'C' || ch > 'z')
> 
> ... if that was truly your intent -- although I have no idea why you
> reject names containing 'A' and 'B' while accepting some others with
> obvious non-letters; it seems "Cr[_a_]zy^" to me, but ...
> 
>      I have not studied the rest of your code, in part because of the
> strong suspicion that what you have shown is *not* actually your code
> but some kind of paraphrase.  Even without study, though, I'd bet that
> the problem I describe is only one of several.  If you need further
> help with additional problems, please post the *exact* code you run,
> and show *exactly* what you entered and *exactly* the output you got --
> no "something like" or "sort of," but *exact*.
> 
> -- 
> esosman@comcast-dot-net.invalid
> "Nobody ever went broke underestimating the intelligence of the
> American public." -- HLM (paraphrased)

There are some major problems in the code as published. One is the opening of an input stream or reader as the initialization of a static variable. This should only be done locally within a function. 

-- 
Lew
0
lewbloch
12/1/2016 9:30:19 PM
Reply: