Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6375955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:40:57+00:00 2026-05-25T01:40:57+00:00

My program will not find the ticket class i created . Cant seem to

  • 0

My program will not find the ticket class i created . Cant seem to work out what i have done wrong? Thank you

package javacw;

/*
 *
 * @Author Christopher Kempster;
 *
 */
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;


public class Main extends JFrame implements ActionListener {


    public JButton buyButton, viewSeatsButton, clearSeatsButton;
    String[] showTimes = {"1pm", "3pm", "5pm", "7pm", "9pm"};
    String[] ageCategories = {"Adult", "Child", "OAP"};
    String[] seatingSections = {"Left", "Middle", "Right"};
    public JComboBox times, categories, sections;
    public JTextField numberOfTickets;
    public Ticket ticket;
    public int price;


    public static void main(String args[]) {

        Main dashboard = new Main();

        dashboard.setVisible(true);



    }

    public void actionPerformed(ActionEvent e) {
        Object item = times.getSelectedItem();
        String stringTimes = (String)item;

        Object item1 = categories.getSelectedItem();
        String stringCategories = (String)item1;

        Object item2 = sections.getSelectedItem();
        String stringSections = (String)item2;

        String text = numberOfTickets.getText();

        int ii = Integer.parseInt(text);

        if(e.getSource() == buyButton) {
            buyTickets(stringTimes, stringSections, ii, stringCategories);
        }
        else if(e.getSource() == viewSeatsButton) {
            showSeats(stringTimes, stringSections);
        }
        else if(e.getSource() == clearSeatsButton) {
            clearSection(stringTimes, stringSections);
        }

    }

    public Main() {
        ticket = new Ticket();
        JPanel panel = new JPanel();



        FlowLayout flow = new FlowLayout();

        panel.setLayout(flow);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        setSize(300, 500);

        buyButton = new JButton("Buy tickets");
        viewSeatsButton = new JButton("View seats");
        clearSeatsButton = new JButton("Clear seats");

        times = new JComboBox(showTimes);
        categories = new JComboBox(ageCategories);
        sections = new JComboBox(seatingSections);

        JLabel label = new JLabel("Number of tickets:");

        numberOfTickets = new JTextField(5);

        buyButton.addActionListener(this);
        viewSeatsButton.addActionListener(this);
        clearSeatsButton.addActionListener(this);

        panel.add(times);
        panel.add(categories);
        panel.add(sections);

        panel.add(label);

        panel.add(numberOfTickets);

        panel.add(buyButton);
        panel.add(viewSeatsButton);
        panel.add(clearSeatsButton);



        Container cp = getContentPane();
        cp.add(panel, BorderLayout.CENTER);
        cp.setBackground(Color.red);

    }

    public void showSeats(String a, String b) {
        JOptionPane.showMessageDialog(this, "There are " + ticket.seatsLeft(a, b) + " seats left in the " + b + " at " + a + ".");
    }

    public void clearSection(String a, String b) {
        ticket.clearSeats(a, b);
        JOptionPane.showMessageDialog(this, "There are now " + ticket.seatsLeft(a, b) + " tickets left for this section.");
    }

    public void buyTickets(String a, String b, int i, String c) {
        if(c.equals("Adult")) {
            price = 5;
        }
        else if(c.equals("Child")) {
            price = 2;
        }
        else if(c.equals("OAP")) {
            price = 2;
        }

        price = price * i;

        if(ticket.buyTix(a, b, i)) {

            JOptionPane.showMessageDialog(this, "Tickets have been bought!\nThere are " + ticket.seatsLeft(a, b) + " seats left in this section.\nPrice of tickets bought: £" + price + ".");

        }
        else {

            JOptionPane.showMessageDialog(this, "Sorry, there are just " + ticket.seatsLeft(a, b) + " tickets left for this section.");

        }
    }

}


Ticket.java

package javacw;
/*
 *
 * @Author Christopher Kempster;
 *
 */

public class Ticket {

    int c, seatsLeft;
    public int[] seating = {12, 40, 12, 12, 40, 12, 12, 40, 12, 12, 40, 12, 12, 40, 12};
    public int[] seating2 = {12, 40, 12, 12, 40, 12, 12, 40, 12, 12, 40, 12, 12, 40, 12};
    public Ticket() {

    }

    public void clearSeats(String a, String b) {
        seating[convertArrayPointer(a, b)] = seating2[convertArrayPointer(a, b)];
    }

    public boolean buyTix(String a, String b, int i) {

        if(seatsLeft(a, b) >= i) {
            seating[convertArrayPointer(a, b)] -= i;
            return true;
        }
        else {
            return false;
        }

    }

    public int seatsLeft(String a, String b) {

        seatsLeft = seating[convertArrayPointer(a, b)];

        return seatsLeft;
    }

    public int convertArrayPointer(String a, String b) {

        if(a.equals("1pm") && b.equals("Left")) {
            c = 0;
        }
        else if(a.equals("1pm") && b.equals("Middle")) {
            c = 1;
        }
        else if(a.equals("1pm") && b.equals("Right")) {
            c = 2;
        }

        else if(a.equals("3pm") && b.equals("Left")) {
            c = 3;
        }
        else if(a.equals("3pm") && b.equals("Middle")) {
            c = 4;
        }
        else if(a.equals("3pm") && b.equals("Right")) {
            c = 5;
        }

        else if(a.equals("5pm") && b.equals("Left")) {
            c = 6;
        }
        else if(a.equals("5pm") && b.equals("Middle")) {
            c = 7;
        }
        else if(a.equals("5pm") && b.equals("Right")) {
            c = 8;
        }

        else if(a.equals("7pm") && b.equals("Left")) {
            c = 9;
        }
        else if(a.equals("7pm") && b.equals("Middle")) {
            c = 10;
        }
        else if(a.equals("7pm") && b.equals("Right")) {
            c = 11;
        }

        else if(a.equals("9pm") && b.equals("Left")) {
            c = 12;
        }
        else if(a.equals("9pm") && b.equals("Middle")) {
            c = 13;
        }
        else if(a.equals("9pm") && b.equals("Right")) {
            c = 14;
        }
        return c;
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T01:40:57+00:00Added an answer on May 25, 2026 at 1:40 am

    This compiles properly when I try under Eclipse.

    The problem doesn’t come from your code. I think it comes from your environment settings. Either the source path is not correct or your Ticket.java is not located in the proper directory (which should be [src path]/javacw here).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting Java: Could not find the main class. Program will exit when
I have an executable that is started by a windows service, this program will
I decided to teach myself assembly language. I have realized that my program will
I have a program that will calculate the minimal area taken by fitting rectangles
I have a program that will let me manage users on our terminal server
I have a Java program with code: public class Test1 { public static void
I am currently learning objective c on my pc and my program will not
Can anyone help me with this? I have not been able to find anything
My program will take arbitrary strings from the internet and use them for file
As we all know Java program will start executing from the public static void

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.