Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I'm having a problem with the program i'm working on. I keep getting the cannot. find symbol error and I can't figure out why. Any help would be great.

Here are the errors
Course.java:43: error: cannot find symbol
				if(residency.equals("IC")){
				   ^
  symbol:   variable residency
  location: class Course
Student.java:64: error: cannot find symbol
	for(int i=0;i<courses.tuition();i++){
	                     ^
  symbol:   method tuition()
  location: variable courses of type ArrayList<Course>
Student.java:69: error: cannot find symbol
		tuition=c.getTuition()+tuition;
		         ^
  symbol:   method getTuition()
  location: variable c of type Course


and here's the code

public class Course{

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

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

	}


	public void setCourseName(String arg){

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

		creditHours=arg;
	}

	public String getCourseName(){
		return courseName;
	}

	public String getCourseId(){
		return courseId;
	}

	public int getCreditHours(){
		return creditHours;
	}

	public double calculateTuition(){
			double tuition=0;

				if(residency.equals("IC")){
    			tuition=139.04;
    		}

    		if(residency.equals("OOC")){
    			tuition=164.22;
    		}

    		if(residency.equals("OOS")){
    			tuition=315.79;
    		}

			return tuition;
		}

	}

and
<pre>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 argResidency){
		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.size();i++){
		//grabs next pizza on list
		Course c=courses.get(i);

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

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

	}
	return creditHours;
}

public double calculateTuition(){
	double tuition=0;

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

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

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

	}


	return tuition;

}

}


What I have tried:

i've tried making sure there were no logic errors and making sure i didn't have any typos
Posted
Updated 28-Mar-20 20:09pm
Comments
gggustafson 28-Mar-20 17:20pm    
Within calculateTuition method in the class Courses, where is residency defined? I'd also suggest looking at getters/setters for part of your solution.

1 solution

residency isn't part of the Course class, it's part of the Student class:
Java
public class Student{
   private String name;
   private String studentnumber;
   private String residency;
   ...

So you cannot access it inside the Course class unless you have an instance of the Student class to work with.

Think about it: when you calculate the the tuition cost for a course in the real world, you apply discounts according to the student's situation. Without knowing which student you are calculating for, you can't apply any discounts!

What you need to do is pass the Student instance to the calculateTuition method so it have use that to apply discounts.

Your other problems are because you are using the wrong method names: courses.tuition instead of courses.calculateTuition and such like.
 
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