Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2008

Tip: Looking for answers? Try searching our database.

Question on TextField

Thread view: 
smart - 11 Mar 2008 12:09 GMT
Hi, to all I am new to core java . Help to solve the problem is

In my panel i created 4 textfields in that 2 of subjects fields and 2
of total and average field and 1 button . I want to calculate 2
textfields integers values and average of 2 subjects . Operands are
not working. So, please guide me regarding this topic . I written code
like this

                          int English =
Integer.parseInt(tfEng.getText());
                         int Telugu   =
Integer.parseInt(tfTelugu.getText());

                   if(English.equals(1)||
English.equals(100)&&Telugu.equals(1)||Telugu.equals(100))
                   {
                         Total = English + Telugu;
                         Average = Total/2;
                   }

This is sample code of my program. Help me regarding this topic

Thanks
Andrew Thompson - 11 Mar 2008 13:07 GMT
...
> This is sample code of my program.

An SSCCE is a lot more descriptive than 'code snippets'.
Please consider posting a (short) compilable code in
future.

>..Help me regarding this topic

We are not your servants.  A 'please' would not
go astray in that sentence.

--
Andrew T.
RedGrittyBrick - 11 Mar 2008 13:41 GMT
> Hi, to all I am new to core java . Help to solve the problem is
>
[quoted text clipped - 10 lines]
>
>                     if(English.equals(1)||

Your variable "English" is an int, which is a primitive type. You can't
apply methods to primitives only to reference types (i.e. objects).
Instead use

    if (English == 1) ||

> English.equals(100)&&Telugu.equals(1)||Telugu.equals(100))

I'd use brackets to make the desired evaluation of this expression clearer.

>                     {
>                           Total = English + Telugu;
[quoted text clipped - 4 lines]
>
> Thanks
Lew - 12 Mar 2008 01:49 GMT
smart wrote:
>>                            int English =
>> Integer.parseInt(tfEng.getText());
[quoted text clipped - 8 lines]
>
>     if (English == 1) ||

Two side points for the OP:

- Variable names should start with a lower-case letter: 'int english;'
- Usenet posts should be *much* less aggressively indented; two spaces is
really enough, four is the maximum.

Signature

Lew

Roedy Green - 12 Mar 2008 07:24 GMT
>   Total = English + Telugu;
>                          Average = Total/2;

You code is hard to follow because you are ignoring coding
conventions.
see http://mindprod.com/jgloss/codingconventions.html
--

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.