Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-12-2008, 06:59 AM
Deon's Avatar
Member
 
Join Date: Jan 2008
Posts: 12
Deon is on a distinguished road
i don understand this error
Hi guys please help me slove this problem =D

this is my half way yet to complete code but i already got some error

PHP Code:
import java.util.Scanner;
public class 
PersonApp{
public static 
void main(String args[]){

String nameGendericNo;
Integer DOB;

Scanner input = new Scanner(System.in);

System.out.print("Enter your name :");
name input.nextstring ();

System.out.print("Enter your date of birth (dd/mm/yyyy) :");
DOB input.nextInt ();

System.out.print("Enter your gender :");
Gender input.nextString ();

System.out.print("Enter your IC number :");
icNo=input.nextInt ();


    }
//Main

}//class 
This is the error i got


__________________
I LOVE JAVA!
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-12-2008, 07:59 AM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 740
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
Well first, there is no nextString() method within the Scanner or String classes. So I would suggest:
Code:
String name; DataInputStream in = new DataInputStream(System.in); System.out.print("Enter your name :"); try { name = in.readLine(); } catch (Exception e) { e.printStackTrace(); }
And that should take care of reading your string inputs. As far as icNo, I'm unclear whether you wish to retrieve a string from the input, or whether icNo is really supposed to be declared as an int(which it's not). If you want it to return an int, declare as one instead of a string. If it's really supposed to be a string - follow the method above for now, but find a better way as readLine() is deprecated.

See how that works for you...
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on July 13, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)

Last edited by CaptainMorgan : 01-12-2008 at 08:05 AM.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-12-2008, 10:37 AM
Deon's Avatar
Member
 
Join Date: Jan 2008
Posts: 12
Deon is on a distinguished road
I'm doing a driver and a class file

here's my class file
PHP Code:
/*
person
==============
-name: String
-DOB : Integer
-icNo: String
-Gender: String
===============================
+ findAge():int
+ setName(name:String):void
+ setDOB(DOS:Integer):void
+ seticNo(icNo:String):void
+ setGender(gender:String):void
+ getName():String
+ getDOB():integer
+ geticNo():String
+ getGender():String

*/

public class person{
    private 
String name;
    private 
String DOB;
    private 
String icNo;
    private 
String Gender;

    public 
person(String naString ic,String dateString sex){
    
name na;
    
icNo ic;
    
DOB date;
    
Gender sex;
}

public 
void setName(String na){
    
name na;

}

public 
void seticNo(String ic){
    
icNo ic;
}

public 
void setDOB(String date){
    
DOB date;
}

public 
void setGender(String sex){
    
Gender sex;
}

public 
String getName(){
    return 
name;
}
public 
String geticNo(){
    return 
icNo;
}

public 
String getDOB(){
    return 
DOB;
}
public 
String getGender(){
    return 
Gender;
}

public 
int findAge(){ 
 
    
String b icNo.substring(1,3);
    
int c Integer.parseInt(b);
    
1900 c;
    
int age 2008 ;
    return 
age;


    }
//main

}//class 
and here is my driver file

PHP Code:
import java.util.Scanner;
public class 
PersonApp{
public static 
void main(String args[]){

String name,DOB,Gender,icNo;

Scanner input = new Scanner(System.in);

System.out.print("Enter your name :");
name input.nextLine ();

System.out.print("Enter your date of birth (dd/mm/yyyy) :");
DOB input.nextLine ();

System.out.print("Enter your gender :");
Gender input.nextLine ();

System.out.print("Enter your IC number :");
icNo input.nextLine ();

icNo.seticNo(icNo);

System.out.printlnname " is " icNo.findAge()+ " years old. ");
System.out.println("Gender is " Gender " and IC number is " icNo.geticNo()); 

    }
//Main

}//class 
this is the output i must get :



but somehow i don really know how to make use of the seticNo can anyone teach mi how to use it?
i already got a formula to find the age in my class file
__________________
I LOVE JAVA!

Last edited by Deon : 01-12-2008 at 10:44 AM.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-12-2008, 10:54 AM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 740
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
You appeared to make a valid effort, thus I've made the necessary corrections - although do not pass it in as is, you must review and edit where necessary.

In the PersonApp class you did not instantiate an object. This neglect made the constructor and Person class's methods virtually useless. I suggest you review your object creation and object use sections in your textbook. Objects and classes are the heart and soul of Java, you must learn these concepts through and through.

Best of luck! And if you're still not clear, let me know.

** also, after a test run or two, your age calculation is not accurate, but I'll leave that to you.

Code:
/* person ============== -name: String -DOB : Integer -icNo: String -Gender: String =============================== + findAge():int + setName(name:String):void + setDOB(DOS:Integer):void + seticNo(icNo:String):void + setGender(gender:String):void + getName():String + getDOB():integer + geticNo():String + getGender():String */ public class Person{ private String name; private String DOB; private String icNo; private String Gender; // four param constructor public Person(String na, String date, String ic, String sex){ name = na; DOB = date; icNo = ic; Gender = sex; } // setters public void setName(String na){ name = na; } public void setDOB(String date){ DOB = date; } public void seticNo(String ic){ icNo = ic; } public void setGender(String sex){ Gender = sex; } // getters public String getName(){ return name; } public String getDOB(){ return DOB; } public String geticNo(){ return icNo; } public String getGender(){ return Gender; } // age calculator public int findAge() { String b = icNo.substring(1,3); int c = Integer.parseInt(b); c = 1900 + c; int age = 2008 - c ; return age; } }
Code:
import java.util.Scanner; public class PersonApp { public static void main(String args[]){ String name, dob, gender, icNo; Scanner input = new Scanner(System.in); System.out.print("Enter your name :"); name = input.nextLine (); System.out.print("Enter your date of birth (dd/mm/yyyy) :"); dob = input.nextLine (); System.out.print("Enter your gender :"); gender = input.nextLine (); System.out.print("Enter your IC number :"); icNo = input.nextLine (); // *** instantiate an object! *** // *** this is why we created the constructor *** Person p = new Person(name, dob, icNo, gender); // *** now we can use it!! System.out.println(p.getName() + " is " + p.findAge() + " years old. "); System.out.println("Gender is " + p.getGender() + " and IC number is " + p.geticNo()); } }
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on July 13, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)

Last edited by CaptainMorgan : 01-12-2008 at 10:57 AM.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-12-2008, 11:03 AM
Deon's Avatar
Member
 
Join Date: Jan 2008
Posts: 12
Deon is on a distinguished road
thank you! captain morgan i will try my best if i got any more question i will ask u again THX!
__________________
I LOVE JAVA!
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
help me need to understand queries hossainsadd Database 1 05-26-2008 01:02 AM
Errors I don't understand MattyB New To Java 4 04-02-2008 12:55 AM
Cannot understand whats wrong Lehane_9 New To Java 1 03-06-2008 08:57 PM
New: Want to understand Drawing... diRisig New To Java 1 02-05-2008 09:13 AM
i can't understand using interface as a type sireesha New To Java 3 11-20-2007 11:07 PM


All times are GMT +3. The time now is 11:56 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org