Hey guys! I have this program I'm working on, but I keep getting an error in my main class. Here's what I have:

import java.util.Scanner;
public class TicketingSystem {


    public static void main(String[] args) {
        Game game = new Game();
        Scanner input = new Scanner (System.in);
        String teamName;

        game.addTeam(new Team(teamName));
    }
}




public class Team {

    private Game teamName;

    public Team (Game teamName){
        this.teamName = teamName;
    }

}



public class Seat {
    private String seatType, seatLocation;
    private double ticketPrice;
    private boolean reserved = false;

    public Seat(String seatType, double ticketPrice, String seatLocation) {
    this.seatType = seatType; 
    this.seatLocation = seatLocation;
    this.ticketPrice = ticketPrice;
    }

    public boolean isReserved() {
        return reserved;
    }

    public void setReserved(boolean reserved) {
        this.reserved = reserved;
    }

    public String getSeatLocation() {
        return seatLocation;
    }

    public void setSeatLocation(String seatLocation) {
        this.seatLocation = seatLocation;
    }

    public String getSeatType() {
        return seatType;
    }

    public void setSeatType(String seatType) {
        this.seatType = seatType;
    }

    public double getTicketPrice() {
        return ticketPrice;
    }

    public void setTicketPrice(double ticketPrice) {
        this.ticketPrice = ticketPrice;
    }



}






public class Game {
     ArrayList <Seat> seats = new ArrayList<>();
     ArrayList <Team> teams =  new ArrayList<>();
     ArrayList <Ticket> tickets = new ArrayList<>();

     public void addTeam (Team team){
         teams.add(team);
     }

}

Thanks guys!

Recommended Answers

All 2 Replies

You don't have any value for teamName - it's declared but never initialised. Presumably you intend at some stage to read it from the scanner, but for step-by-step testing (which, by the way is a VERY good thing to do) you could simply give it some temporary sensible value.

Once you've fixed that you need to look at why you pass teamName as a String, but the Team class thinks it should be an instance of Game.

ps: next time please post the complete text of the error message so we don't have to guess

to add to what James had already mentioned , you have defined your Team class' constructor to take an argument of type game , but in game.addTeam(new Team(teamName)); your passing a string to the constructor.
Also , your trying to use ArrayList , but you have to import them first in order to do so.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.