Why Does Java Show Cannot Find Symbol Error Despite Correct Constructors?

  • Comp Sci
  • Thread starter iamjon.smith
  • Start date
  • Tags
    Java Method
In summary: Subclass (Printed)/* * Use Ticket as the superclass. WillCall, eDelivered, and Printed are subclasses Ticket. * All tickets have event name, date, time, event location, and ticket cost. * WillCall tickets have booth location attribute. * eDelivered has an email address attribute. * Printed has a mailing address. * * Write a test application that instantiates at least one of each subclass type and prints the contents. * Use an overridden toString() method to provide a readable string representation of each subclass instantiated. */package ph1ipticket;public class Printed extends Tickets { private int streetNumber; private String streetName; private String city; private String state; private int zip
  • #1
iamjon.smith
117
3
/*
* Use Ticket as the superclass. WillCall, eDelivered, and Printed are subclasses Ticket.
* All tickets have event name, date, time, event location, and ticket cost.
* WillCall tickets have booth location attribute.
* eDelivered has an email address attribute.
* Printed has a mailing address.
*
* Write a test application that instantiates at least one of each subclass type and prints the contents.
* Use an overridden toString() method to provide a readable string representation of each subclass instantiated.
*/


When I try to call the methods (Printed, eDelivered, and WillCall) I get the error:

cannot find symbol
symbol: constructor Printed(paramaters)
location: projectname.Printed

and this same error appears in all 3 method calls. the code is as follows:

Main Class
Code:
/*
 * Use Ticket as the superclass. WillCall, eDelivered, and Printed are subclasses Ticket.
 * All tickets have event name, date, time, event location, and ticket cost.
 * WillCall tickets have booth location attribute.
 * eDelivered has an email address attribute.
 * Printed has a mailing address.
 *
 * Write a test application that instantiates at least one of each subclass type and prints the contents.
 * Use an overridden toString() method to provide a readable string representation of each subclass instantiated.
 */

package ph1ipticket;

/**
 *
 * @author Jon and Jessica
 *
 * Instantiate all 3 classes, Printed, eDelivered, and willCall
 * Be sure to call toString() on all 3 object
 */
public class ticketTest {

    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

       Printed printed = new Printed("Learning Java Techniques Seminar", "January 17, 2011", "12:00:00 a.m.", "Colorado Technical University Online",
               1,500.00, 1800, "Grant Street", "Denver", "CO", 80203);

               System.out.println(printed.toString());

       eDelivered edelivered = new eDelivered("Learning Java Techniques Seminar", "January 17, 2011", "12:00:00 a.m.", "Colorado Technical University Online",
               1,500.00, "javaSeminar@CTUonline.edu" );

               System.out.println(edelivered.toString());

        WillCall willCall = new WillCall ("Learning Java Techniques Seminar", "January 17, 2011", "12:00:00 a.m.", "Colorado Technical University Online",
               1,500.00, "Main Entrance, Suite 800");

               System.out.println(willCall.toString());
         
    }

   }

Super Class (Tickets)

Code:
 /*
 * Use Ticket as the superclass. WillCall, eDelivered, and Printed are subclasses Ticket.
 * All tickets have event name, date, time, event location, and ticket cost.
 * WillCall tickets have booth location attribute.
 * eDelivered has an email address attribute.
 * Printed has a mailing address.
 *
 * Write a test application that instantiates at least one of each subclass type and prints the contents.
 * Use an overridden toString() method to provide a readable string representation of each subclass instantiated.
 */

package ph1ipticket;



public class Tickets {

    protected String eventName;
    protected String eventDate;
    protected String eventTime;
    protected String eventLocation;
    protected double ticketCost;

    public Tickets(String eventName, String eventDate, String eventTime, String eventLocation, double ticketCost) {
        this.eventName = eventName;
        this.eventDate = eventDate;
        this.eventTime = eventTime;
        this.eventLocation = eventLocation;
        this.ticketCost = ticketCost;
    }

    public Tickets () {
    }

    public String getEventDate () {
        return eventDate;
    }

    public void setEventDate (String val) {
        this.eventDate = val;
    }

    public String getEventLocation () {
        return eventLocation;
    }

    public void setEventLocation (String val) {
        this.eventLocation = val;
    }

    public String getEventName () {
        return eventName;
    }

    public void setEventName (String val) {
        this.eventName = val;
    }

    public String getEventTime () {
        return eventTime;
    }

    public void setEventTime (String val) {
        this.eventTime = val;
    }

    public double getTicketCost () {
        return ticketCost;
    }

    public void setTicketCost (double val) {
        this.ticketCost = val;
    }
    
    public String toString() {

            return ("eventName= " + eventName +
                   "eventDate= " + eventDate +
                   "eventTime= " + eventTime +
                   "eventLocation= " + eventLocation +
                   "ticketCost= " + ticketCost);
    }
}

Supporting subClasses (Printed, eDelivered, WillCall)

Printed

Code:
 /*
 * Use Ticket as the superclass. WillCall, eDelivered, and Printed are subclasses Ticket.
 * All tickets have event name, date, time, event location, and ticket cost.
 * WillCall tickets have booth location attribute.
 * eDelivered has an email address attribute.
 * Printed has a mailing address.
 *
 * Write a test application that instantiates at least one of each subclass type and prints the contents.
 * Use an overridden toString() method to provide a readable string representation of each subclass instantiated.
 */

package ph1ipticket;


public class Printed extends Tickets {

    private int streetNumber;
    private String streetName;
    private String City;
    private String State;
    private int zipCode;

    public Printed(String eventName, String eventDate, String eventTime, String eventLocation, double ticketCost, int streetNumber, String streetName, String City, String State, int zipCode) {
        super(eventName, eventDate, eventTime, eventLocation, ticketCost);
        this.streetNumber = streetNumber;
        this.streetName = streetName;
        this.City = City;
        this.State = State;
        this.zipCode = zipCode;
    }

     public String toString(){
        return (super.toString() +  "Address= "+ streetNumber + " "+ streetName + "\n " + City + ", " + State + "   " + zipCode + "\n");
    }
     public String getCity () {
        return City;
    }

    public void setCity (String val) {
        this.City = val;
    }

    public String getState () {
        return State;
    }

    public void setState (String val) {
        this.State = val;
    }

    public int getStreetNumber () {
        return streetNumber;
    }

    public void setStreetNumber (int val) {
        this.streetNumber = val;
    }

   public String getStreetName () {
        return streetName;
    }

   public void setStreetName (String val) {
        this.streetName = val;
    }

    public int getZipCode () {
        return zipCode;
    }

    public void setZipCode (int val) {
        this.zipCode = val;
    }

}

eDelivered

Code:
/*
 * Use Ticket as the superclass. WillCall, eDelivered, and Printed are subclasses Ticket.
 * All tickets have event name, date, time, event location, and ticket cost.
 * WillCall tickets have booth location attribute.
 * eDelivered has an email address attribute.
 * Printed has a mailing address.
 *
 * Write a test application that instantiates at least one of each subclass type and prints the contents.
 * Use an overridden toString() method to provide a readable string representation of each subclass instantiated.
 */

package ph1ipticket;


public class eDelivered extends Tickets {

    private String emailAddress;

    public eDelivered(String eventName, String eventDate, String eventTime, String eventLocation, double ticketCost, String emailAddress) {
        super(eventName, eventDate, eventTime, eventLocation, ticketCost);
        this.emailAddress = emailAddress;
    }

    public String toString(){
        return (super.toString() +  "emailAddress= "+ emailAddress);
    }

   
    public String getEmailAddress () {
        return emailAddress;
    }

    public void setEmailAddress (String val) {
        this.emailAddress = val;
    }

}

WillCall

Code:
/*
 * Use Ticket as the superclass. WillCall, eDelivered, and Printed are subclasses Ticket.
 * All tickets have event name, date, time, event location, and ticket cost.
 * WillCall tickets have booth location attribute.
 * eDelivered has an email address attribute.
 * Printed has a mailing address.
 *
 * Write a test application that instantiates at least one of each subclass type and prints the contents.
 * Use an overridden toString() method to provide a readable string representation of each subclass instantiated.
 */

package ph1ipticket;


public class WillCall extends Tickets {

    private String boothLocation;

    public WillCall(String eventName, String eventDate, String eventTime, String eventLocation, double ticketCost, String boothLocation) {
        super(eventName, eventDate, eventTime, eventLocation, ticketCost);
        this.boothLocation = boothLocation;
    }

    public String toString(){
        return (super.toString() +  "Booth Location= "+ boothLocation);
    }

    public String getBoothLocation () {
        return boothLocation;
    }

    public void setBoothLocation (String val) {
        this.boothLocation = val;
    }

}

Can someone please explain why my method calls are not working, I have the constructors in place, and everything seems right to me, but I must be overlooking something simple.
 
Physics news on Phys.org
  • #2


A parameter in each of the method calls was off just a bit. I went back through and rewrote the parameters to correctly match the method itself and now it works correctly. NO FURTHER ACTION REQUIRED. THIS THREAD MAY NOW BE CLOSED.
 

What is a Java method call?

A Java method call is a statement that invokes a specific method from a class or object. This allows the method to perform a specific task or return a value.

What are some common problems that can occur with Java method calls?

Some common problems with Java method calls include passing incorrect arguments, using incorrect method syntax, and not handling exceptions properly.

How can I troubleshoot Java method call problems?

To troubleshoot Java method call problems, you can check the method's syntax, verify that the correct arguments are being passed, and review any error messages or exception handling. Debugging tools such as a debugger or logging statements can also be helpful.

What are some best practices for Java method calls?

Some best practices for Java method calls include using meaningful method names, following proper naming conventions, documenting the method's purpose and parameters, and handling exceptions appropriately.

Can I call a Java method from another method?

Yes, you can call a Java method from another method within the same class or from a different class. This allows for modular and reusable code.

Back
Top