Results 1 to 4 of 4
  1. #1
    deantmcg is offline Member
    Join Date
    Dec 2016
    Posts
    8
    Rep Power
    0

    Default Array / Object Orientated Programming Problem

    This may well belong in the New to Java section but I keep getting logged out every time I enter that forum.

    I am creating code to issue tickets to passengers on 4 different bus routes, I am going to contain them in an array.
    Although, I have hit a wall in writing this code and I am stumped. I will post the 3 classes I have so far and the error I am getting.

    Also I would welcome any sort of guidance or recommendations.

    TicketHandler class
    Java Code:
    public class TicketHandler
    {
    	private double price;
    	private int availableTickets;
    	private String routeName;
    	
    	public void Route ()
    	{
    		this.price = 0;
    		this.availableTickets = 0;
    		this.routeName = "";
    	}
    	
    	public void Person (double price, int availableTickets, String routeName)
    	{
    		this.price = price;
    		this.availableTickets = availableTickets;
    		this.routeName = routeName;
    	}
    	
    	//
    	//
    	
    	public void setPrice (double price)
    	{
    		this.price = price;
    	}
    	
    	public void setAvailableTickets (int availableTickets)
    	{
    		this.availableTickets = availableTickets;
    	}
    	
    	public void setRouteName (String routeName)
    	{
    		this.routeName = routeName;
    	}
    	
    	//
    	//
    	
    	public double getPrice ()
    	{
    		return price;
    	}
    	
    	public int getAvailableTickets ()
    	{
    		return availableTickets;
    	}
    	
    	public String getRouteName ()
    	{
    		return routeName;
    	}
    	
    	//
    	//
    	
    	public void updateTickets (int ticketsPurchased)
    	{
    		availableTickets = availableTickets - ticketsPurchased;
    	}
    }

    CashHandler class
    Java Code:
    public class CashHandler
    {
    	private double moneyIN;
    	
    	public void Cash ()
    	{
    		this.moneyIN = 0;
    	}
    	
    	public void Cash (double moneyIN)
    	{
    		this.moneyIN = moneyIN;
    	}
    	
    	//
    	//
    	
    	public void setMoneyIN (double moneyIN)
    	{
    		this.moneyIN = moneyIN;
    	}
    	
    	public double getMoneyIN ()
    	{
    		return moneyIN;
    	}
    	
    	//
    	//
    	
    	
    }

    BusTickets class (application)
    Java Code:
    import java.util.Scanner;
    public class BusTickets
    
    {
    	public static void main(String [] args)
    	{
    		Scanner keyboard = new Scanner(System.in);
    		
    		Route [] route = new Route[4];
    	}
    }
    the error I am getting is on the BusTickets class "cannot find symbol class Route"

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,423
    Blog Entries
    7
    Rep Power
    27

    Default Re: Array / Object Orientated Programming Problem

    The compiler is right: it can't find a type (class or interface) Route ...

    kind regards,

    Jos
    Build a wall around Donald Trump; I'll pay for it.

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    19,966
    Rep Power
    31

    Default Re: Array / Object Orientated Programming Problem

    "cannot find symbol class Route"
    What source line had that error?
    That looks like the compiler can not find a definition for the class Route?
    Is there a Route class?
    Can you put it on the classpath so the compiler can find it?
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,983
    Rep Power
    8

    Default Re: Array / Object Orientated Programming Problem

    There is a Route method in your TicketHandler class which looks suspiciously like a constructor for TicketHandler, but it is actually a method called Route which returns nothing (void):
    Java Code:
    public void Route () {
            this.price = 0;
            this.availableTickets = 0;
            this.routeName = "";
        }
    My guess is you copied the constructor of Route to the TicketHandler class and added "void" to prevent a compiler error. The same goes for the public void Person below that.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

Similar Threads

  1. Java Array Programming Problem
    By jjfstar2009 in forum New To Java
    Replies: 3
    Last Post: 04-16-2014, 02:05 AM
  2. Simple Problem with Object-Oriented Programming...
    By CuppaCoffee in forum New To Java
    Replies: 12
    Last Post: 01-04-2012, 10:12 PM
  3. Object orientated problem
    By alacn in forum New To Java
    Replies: 13
    Last Post: 08-14-2010, 01:30 PM
  4. Simple Programming problem loop in array
    By katon in forum New To Java
    Replies: 1
    Last Post: 12-20-2009, 03:14 PM
  5. Replies: 2
    Last Post: 12-10-2008, 04:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •