0% found this document useful (0 votes)
12 views9 pages

Golfer Ticket Pricing System in Java

The mini-project report presents a ticketing system for a golfing event, where ticket prices vary based on golfer types (amateur, junior, professional). The application, developed in Java, features a graphical user interface for input and utilizes object-oriented programming concepts such as inheritance and polymorphism. It calculates total ticket revenue based on user inputs for golfer types and viewing durations, ensuring an interactive and responsive experience.

Uploaded by

Rahul V
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views9 pages

Golfer Ticket Pricing System in Java

The mini-project report presents a ticketing system for a golfing event, where ticket prices vary based on golfer types (amateur, junior, professional). The application, developed in Java, features a graphical user interface for input and utilizes object-oriented programming concepts such as inheritance and polymorphism. It calculates total ticket revenue based on user inputs for golfer types and viewing durations, ensuring an interactive and responsive experience.

Uploaded by

Rahul V
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

AMRITA SCHOOL OF COMPUTING, MYSURU CAMPUS

22CSA504: Object-Oriented Programming Using Java

" Golfer Classes and Visitor Ticket Pricing in Java"


A MINI-PROJECT REPORT

Submitted by
Rahul V ([Link].P2MCA24137)
Krishna Priya KP ([Link].P2MCA24123)
Vaishnavi Baiju ([Link].P2MCA24153)

Submitted to
Dr. Akshatha Prabhu
Assistant Professor,
Department of Computer Science,
School of Computing,
Amrita Vishwa Vidyapeetham, Mysuru-570026
December – 2024
Problem Statement
This project aims to simulate a ticketing system for a golfing event where the ticket prices vary
depending on the type of golfer (amateur, junior, or professional). The program should calculate the
total ticket revenue for visitors based on the duration they spend watching each golfer type.

Objectives
 Develop an application that calculates ticket prices for different golfer types.
 Allow user inputs for golfer types and viewing durations through a graphical interface.
 Ensure the system is interactive, responsive, and user-friendly.
 Use Java features like inheritance, threads, and GUI frameworks effectively.

Key Features
 Abstract Class: The golfer is a blueprint for all golfer types, encapsulating their behavior.
 Polymorphism: Derived classes (AmateurGolfer, JuniorGolfer, ProfessionalGolfer) override
the method to define hourly rates.
 GUI Integration: Utilizes AWT and Swing for user input and displaying results.
 Threading: Ensures calculations are performed in a background thread to maintain GUI
responsiveness.
 Error Handling: Includes validation for user inputs, with error messages for invalid data.

Tools and Technologies Used


 Programming Language: Java
 Frameworks:
 Swing and AWT for GUI components.
 Java Threads for asynchronous processing.
 Development Environment: IDE such as IntelliJ IDEA, Eclipse, or any suitable Java editor.
 Object-Oriented Concepts: Abstract classes, inheritance, and polymorphism.

Explanation of the Program


 Abstract Class and Subclasses:
- The golfer is the abstract class with an abstract method getHourlyRate.
- AmateurGolfer, JuniorGolfer, and ProfessionalGolfer inherit from Golfer and define their
specific hourly rates.

 Input and Calculation:


- The user is prompted to enter the golfer type (A, J, or P) and the number of hours for each of
the 10 entries.
- Each golfer type corresponds to a subclass object, and the program calculates the total price
for all visitors.

Create a golfer class with abstract methods, and define these methods to amateur, junior, and
professional golfer classes. The ticket to watch the games of these 3 types of players for visitors is
different. The visitor price for a professional golfer per hr= Rs 1000, while for the junior player is Rs
500/hr, and for the amateur is Rs 250/hr. Create an array of objects of size 10, objects and calculate
the total price for the visitors on various types of golfers.

Program:
import [Link].*;
import [Link].*;
import [Link].*;

// Abstract class for Golfer


abstract class Golfer {
abstract int getHourlyRate();
}

// Derived class for Amateur Golfer


class AmateurGolfer extends Golfer {
@Override
int getHourlyRate() {
return 250;
}
}

// Derived class for Junior Golfer


class JuniorGolfer extends Golfer {
@Override
int getHourlyRate() {
return 500;
}
}

// Derived class for Professional Golfer


class ProfessionalGolfer extends Golfer {
@Override
int getHourlyRate() {
return 1000;
}
}

// Main class
public class GolferTicketSystem {

public static void main(String[] args) {


[Link](() -> {
GolferFrame frame = new GolferFrame();
[Link](true);
});
}
}

// GUI Frame
class GolferFrame extends JFrame {
private JTextField[] golferTypes = new JTextField[10];
private JTextField[] hours = new JTextField[10];
private JButton calculateButton;
private JLabel resultLabel;

public GolferFrame() {
setTitle("Golfer Ticket System");
setSize(600, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());

// Panel for input


JPanel inputPanel = new JPanel(new GridLayout(11, 3));
[Link](new JLabel("Golfer Type (A/J/P)"));
[Link](new JLabel("Hours"));
[Link](new JLabel(""));

for (int i = 0; i < 10; i++) {


golferTypes[i] = new JTextField();
hours[i] = new JTextField();
[Link](golferTypes[i]);
[Link](hours[i]);
}

add(inputPanel, [Link]);

// Panel for buttons and result


JPanel actionPanel = new JPanel(new GridLayout(2, 1));
calculateButton = new JButton("Calculate Total Price");
resultLabel = new JLabel("Total Price: Rs 0", [Link]);

[Link](calculateButton);
[Link](resultLabel);
add(actionPanel, [Link]);

[Link](new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
calculateTotalPrice();
}
});
}

private void calculateTotalPrice() {


Thread calculationThread = new Thread(() -> {
int totalPrice = 0;
for (int i = 0; i < 10; i++) {
String type = golferTypes[i].getText().trim().toUpperCase();
String hourText = hours[i].getText().trim();

if ([Link]() || [Link]()) continue;

int hours = 0;
try {
hours = [Link](hourText);
} catch (NumberFormatException ex) {
final int row = i + 1;
[Link](() -> {
[Link]([Link], "Invalid input for hours at row "
+ row, "Error", JOptionPane.ERROR_MESSAGE);
});
return;
}

Golfer golfer;
switch (type) {
case "A":
golfer = new AmateurGolfer();
break;
case "J":
golfer = new JuniorGolfer();
break;
case "P":
golfer = new ProfessionalGolfer();
break;
default:
final int row = i + 1;
[Link](() -> {
[Link]([Link], "Invalid golfer type at row " +
row, "Error", JOptionPane.ERROR_MESSAGE);
});
return;
}

totalPrice += [Link]() * hours;


}

final int result = totalPrice;


[Link](() -> [Link]("Total Price: Rs " + result));
});

[Link]();
}
}

Output:

GUI Interface:

Amateur Golfer:
Junior Golfer:
Professional Golfer:

 Summary and Output:


- The program displays the details of each entry, including golfer type, hours, and price.
- Finally, the total price is calculated and displayed.

 Appendix and Conclusion:


- The appendix lists the hourly rates for each golfer type.
- The conclusion provides an overview of the program's functionality and its implementation.

You might also like