Click here to Skip to main content
15,917,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I asked a similar question awhile ago but my code has changed and i'm still struggling with this error. Basically i'm getting 3 'cannot find symbol' errors and I have no idea why. These are the exact error.

Student.java:13: error: cannot find symbol
		residency=argResidency;
		          ^
  symbol:   variable argResidency
  location: class Student
Student.java:48: error: cannot find symbol
	for(int i=0;i<courses.hours();i++){
	                     ^
  symbol:   method hours()
  location: variable courses of type ArrayList<Course>
Student.java:53: error: cannot find symbol
		creditHours=c.calculateCreditHours()+creditHours;
		             ^
  symbol:   method calculateCreditHours()
  location: variable c of type Course


and here's the code


import java.util.ArrayList;

public class Student{
	private String name;
	private String studentnumber;
	private String residency;

	private ArrayList<Course> courses = new ArrayList<Course>();

	public Student(String argName, String argStudentNumber, String arg){
		name=argName;
		studentnumber=argStudentNumber;
		residency=argResidency;
	}

	public void setName(String arg){
		name=arg;
	}

	public String getName(){
		return name;
	}

	public void setStudentNumber(String arg){
		studentnumber=arg;
	}

	public String getStudentNumber(){
		return studentnumber;
	}

	public void setResidency(String arg){
		residency=arg;
	}

	public String getResidency(){
		return residency;
	}

	public void addCourse(Course arg){
		courses.add(arg);

	}

	public double calculateCreditHours(){
	double creditHours=0;

	for(int i=0;i<courses.hours();i++){
		//grabs next pizza on list
		Course c=courses.get(i);

		//adds that pizza's price to running total
		creditHours=c.calculateCreditHours()+creditHours;

		//price=pizzas.get(i).calculatePrice()+price;

	}
	return creditHours;
}

}


and
public class Course{

	//attributes
	private String courseName;
	private String courseId;
	private String creditHours;

	public Course(String argcourseName, String argcourseId, String argcreditHours){
		courseName=argcourseName;
		courseId=argcourseId;
		creditHours=argcreditHours;

	}


	public void setCourseName(String arg){

		courseName=arg;
	}
	public void setCourseId(String arg){
		courseId=arg;
	}
	public void setcreditHours(String arg){

		creditHours=arg;
	}

	public String getCourseName(){
		return courseName;
	}

	public String getCourseId(){
		return courseId;
	}

	public String getCreditHours(){
		return creditHours;
	}



	}

I can also supply my unittest code if that's needed. Thanks in advance for any help.

What I have tried:

researching the error and trying to fix it according to that
Posted
Updated 16-Mar-20 10:44am

There is a misnamed parameter, apparently.
Java
public Student(String argName, String argStudentNumber, String argResidency){
		name=argName;
		studentnumber=argStudentNumber;
		residency=argResidency;
	}

A logic error:
Java
for(int i=0;i<courses.size();i++){

And a miscalled method:
Java
creditHours=c.getCreditHours()+creditHours;


All these errors are rather trivial to solve. What path did you follow, starting from the error messages, to try and solve them?
 
Share this answer
 
v3
Comments
Member 14637431 16-Mar-20 16:03pm    
I'm still getting the error using courses.length and the error with c.getCreditHours() just started pointing to the + instead.

I can't believe I missed the argResidency one, I initially had it in but then I was changing a couple things before changing it back and must have just mistyped that one.
phil.o 16-Mar-20 16:09pm    
The count function for an ArrayList in java is size().
https://www.w3schools.com/java/java_arraylist.asp
So replace length() by size() and you should get rid of that one.

The second one is because getCreditHours() returns a string instead of a double. Why don't you use proper numeric types for numeric values?
I leave to you the responsibility to tackle this one: either parse the result of the method, or change the method to return a proper double value. Second solution is cleaner, but may require you to adjust the code in some other places.
Look at your code: when it says 'cannot find symbol' it is trying to tell you that nothing can be found with that name.
Student.java:13: error: cannot find symbol
		residency=argResidency;
                          ^

So the arrow is pointing at argResidency I would suspect you missed out a dot, but since arg is a string, and they don't have a Residency property, that's unlikely. So have a closer look:
Java
public Student(String argName, String argStudentNumber, String arg){
    name=argName;
    studentnumber=argStudentNumber;
    residency=argResidency;
}
Since you have a string called arg you almost certainly meant to call arg argResidency instead...

Follow that process for your other errors, and you should be able to start solving them for yourself.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900