Click here to Skip to main content
14,695,499 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I can't figure out why i'm getting these errors. Everything seems to be right. Any help would be much appreciated.

UnitTest.java:14: error: cannot find symbol
		System.out.println("Cost to renew:" + j2.getStuPrice());
		                                        ^
  symbol:   method getStuPrice()
  location: variable j2 of type Subscriber
UnitTest.java:19: error: cannot find symbol
		System.out.println("Cost to renew:" + j3.getPrePrice());
		                                        ^
  symbol:   method getPrePrice()
  location: variable j3 of type Subscriber



The code:

public class Subscriber{
	protected int subID;
	protected String name;
        protected String Address;

	public Subscriber(int argSubID,
										String argName,
										String argAddress){
		subID=argSubID;
		name=argName;
		address=argAddress
	}


	public void setID(int arg){
		subID=arg;
	}

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

	public void setAddress(String arg){
		address=arg;
	}


	public int getID(){
		return subID;
	}

	public String getName(){
		return name;
	}

	public String getAddress(){
		return address;
	}

	public double getRegPrice(){
		return 20;
	}

}



public class StudentSub
	extends Subscriber{


	public StudentSub(int argSubID, String argName, String argAddress){
		super(argSubID, argName, argAddress);

	}

	public double getStuPrice(){
		return 15;

	}



}



public class PreSub
	extends Subscriber{

	public PreSub(int argSubID, String argName, String argAddress){
		super(argSubID, argName, argAddress);

	}

	public double getPrePrice(){
		return 50;

	}


}


Test cases i'm using
public class UnitTest{


	public static void main(String[] args){

		// test case 1
		Subscriber j1=new Subscriber(1234,"Isbelle Tzu", "45 Horizon");
		System.out.println("Name: " + j1.getName());
		System.out.println("Cost to renew:" + j1.getRegPrice());
		System.out.println("------------------------------------------------------------");

		Subscriber j2=new Subscriber(2334,"Timmy Nook", "56 Leaf");
		System.out.println("Name: " + j2.getName());
		System.out.println("Cost to renew:" + j2.getStuPrice());
		System.out.println("------------------------------------------------------------");

		Subscriber j3=new Subscriber(5465,"Tom Nook", "343 Horizon");
		System.out.println("Name: " + j3.getName());
		System.out.println("Cost to renew:" + j3.getPrePrice());
		System.out.println("------------------------------------------------------------");


	}

}


What I have tried:

Looking over my code to make sure i wasn't missing anything
Posted
Updated 6-Apr-20 21:16pm
v2

1 solution

getStuPrice does not belong to Subscriber class but to StudentSub class which inherits from Subscriber.
So...
StudentSub j2=new StudentSub(2334,"Timmy Nook", "56 Leaf");
System.out.println("Name: " + j2.getName());
System.out.println("Cost to renew:" + j2.getStuPrice());
System.out.println("------------------------------------------------------------");


For further details, please see: Extending classes | Think Java | Trinket[^]
   

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