Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Java error

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java error

     
    public class Student {
     
    		private String FirstName;
    		private String LastName;
    		private String Address;
    		private String PhoneNumber;
    		private int Credits;
    		private double Tuition;
    		private boolean state; 
    		private boolean LateFee;
    		private boolean CampusFood;
    		private boolean HealthCare;
     
     
     
    	public Student(String studentFirstName, String studentLastName, String studentAddress,String studentPhoneNumber, int studentCredits)
    		   {
    			FirstName = studentFirstName;
    			LastName = studentLastName;
    			Address = studentAddress;
    			PhoneNumber = studentPhoneNumber;
    			Credits = studentCredits;
    		   }
    	public void readInput()
    	   {
    	     System.out.println("Name: " + FirstName + " " + LastName);
    	     System.out.println("Address: " + Address);
    	     System.out.println("PhoneNumber: " + PhoneNumber);
    	     System.out.println("Credits: " + Credits);
    	   }
     
     
    	public Student(double Tuition)
    	{
    	}
    		   public Student calculateData()
    			{
    				double Tuition;
     
    						if (Credits < 12)
    						{
    							Tuition = (Credits*102.50);
    							Student Tuition = new Student(Tuition);
    							return Tuition;
    						}

    this is part of my program. I am getting an error on the line Student Tuition = new Student(Tuition); It says the constructor Student(student) is undefined.


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Java error

    Copy and paste the full and exact error message.
    Improving the world one idiot at a time!

  3. #3
    Junior Member
    Join Date
    Nov 2011
    Location
    china
    Posts
    12
    My Mood
    Sad
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: Java error

    在你的程序里我只看到一个构造方法public Student(String studentFirstName, String studentLastName, String studentAddress,String studentPhoneNumber, int studentCredits)
    你再new对象的时候 Student Tuition = new Student(Tuition); 调用的是public Studnet(Studnet s) 这个构造方法 因为此时Tuition 是Student类型 不是double类型
    你应该改为
    Student tt = new Student(Tuition);
    return tt;

  4. #4
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Java error

    The reason is:
    Your local variable is named as Tuition and you are creating new object of Student with the same name. JVM can not recognize the difference between the local variable and class object.
    Change your object's or variable's name.

Similar Threads

  1. Java Error cannot be applied to (java.lang.String), phone book entry program.
    By iceyferrara in forum What's Wrong With My Code?
    Replies: 5
    Last Post: September 23rd, 2011, 06:32 AM
  2. [SOLVED] Java run time error: 'java.lang.NullPointerException"
    By ChandanSharma in forum What's Wrong With My Code?
    Replies: 9
    Last Post: June 20th, 2011, 11:53 AM
  3. OS Specific Java Error
    By JavaStudents in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 4th, 2011, 07:13 AM
  4. A Java Error
    By Shyamz1 in forum Java Theory & Questions
    Replies: 9
    Last Post: October 7th, 2010, 07:56 AM
  5. Java error
    By d7o0om in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 12th, 2010, 08:14 AM

Tags for this Thread