0% found this document useful (0 votes)
26 views8 pages

Java OOP Assignment: Ticket & Account Systems

The document outlines multiple Java programming assignments focusing on object-oriented programming concepts. It includes the design and implementation of a Movie Ticket System, a Bank Account Management program, a Library Book Management system, and a Fitness Tracker App simulation, each with specified class structures, constructor overloading, and methods. Each section provides example code and main methods to demonstrate functionality.

Uploaded by

Harshad SS
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)
26 views8 pages

Java OOP Assignment: Ticket & Account Systems

The document outlines multiple Java programming assignments focusing on object-oriented programming concepts. It includes the design and implementation of a Movie Ticket System, a Bank Account Management program, a Library Book Management system, and a Fitness Tracker App simulation, each with specified class structures, constructor overloading, and methods. Each section provides example code and main methods to demonstrate functionality.

Uploaded by

Harshad SS
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

STEP JAVA BOOTCAMP

Harshad Sathish Kumar Sheetal


RA2411003010492
OOP FUNDAMENTALS ASSINGMENT
PROBLEMS 2
Design a Movie Ticket System.

● Class MovieTicket with fields: String movieName, String theatreName, int

seatNumber, double price.

● Implement constructor overloading:

1. Default constructor → assigns "Unknown" movie.

2. Constructor with movie name → assigns default price = 200.

3. Constructor with movie name and seat number → assigns default theatre "PVR".

4. Full constructor → sets all details.

● Add method: printTicket() → displays ticket details.

● In main(): Create and print multiple tickets.

class MovieTicket {

String movieName;

String theatreName;

int seatNumber;

double price;

MovieTicket() {

[Link] = "Unknown";

[Link] = "Not Assigned";

[Link] = 0;

[Link] = 0.0;

MovieTicket(String movieName) {

[Link] = movieName;

[Link] = "Not Assigned";


[Link] = 0;

[Link] = 200.0;

MovieTicket(String movieName, int seatNumber) {

[Link] = movieName;

[Link] = "PVR";

[Link] = seatNumber;

[Link] = 250.0;

MovieTicket(String movieName, String theatreName, int seatNumber, double price) {

[Link] = movieName;

[Link] = theatreName;

[Link] = seatNumber;

[Link] = price;

void printTicket() {

[Link]("---- Movie Ticket ----");

[Link]("Movie: " + movieName);

[Link]("Theatre: " + theatreName);

[Link]("Seat No: " + seatNumber);

[Link]("Price: Rs. " + price);

[Link]("----------------------");

public static void main(String[] args) {

MovieTicket t1 = new MovieTicket();

MovieTicket t2 = new MovieTicket("Inception");

MovieTicket t3 = new MovieTicket("Avatar", 12);

MovieTicket t4 = new MovieTicket("Interstellar", "IMAX", 25, 500.0);

[Link]();

[Link]();

[Link]();

[Link]();

}
}

Create a Bank Account management program.

● Class BankAccount with fields: String accountHolder, int accountNumber,

double balance.

● Implement constructor overloading:

○ Default constructor → balance = 0.

○ Constructor with name → assigns random account number.

○ Constructor with name and initial balance → assigns both.

● Add methods:

○ deposit(double amount)

○ withdraw(double amount)

○ displayAccount()

● In main(): Create accounts, deposit/withdraw, and display balance.

import [Link];

class BankAccount {

String accountHolder;

int accountNumber;

double balance;

BankAccount() {
[Link] = "Unknown";

[Link] = new Random().nextInt(100000);

[Link] = 0.0;

BankAccount(String accountHolder) {

[Link] = accountHolder;

[Link] = new Random().nextInt(100000);

[Link] = 0.0;

BankAccount(String accountHolder, double balance) {

[Link] = accountHolder;

[Link] = new Random().nextInt(100000);

[Link] = balance;

void deposit(double amount) {

if (amount > 0) {

balance += amount;

[Link]("Deposited: Rs. " + amount);

} else {

[Link]("Invalid deposit amount!");

void withdraw(double amount) {

if (amount > 0 && amount <= balance) {

balance -= amount;

[Link]("Withdrawn: Rs. " + amount);

} else {

[Link]("Insufficient balance or invalid amount!");

void displayAccount() {

[Link]("---- Account Details ----");

[Link]("Holder: " + accountHolder);


[Link]("Account No: " + accountNumber);

[Link]("Balance: Rs. " + balance);

[Link]("-------------------------");

public static void main(String[] args) {

BankAccount acc1 = new BankAccount();

BankAccount acc2 = new BankAccount("Alice");

BankAccount acc3 = new BankAccount("Bob", 5000.0);

[Link](1000);

[Link](200);

[Link]();

[Link](3000);

[Link](1000);

[Link]();

[Link](2000);

[Link](10000);

[Link]();

Problem 3: Library Book Management 📚

Design a system for managing Library Books.

● Class Book with fields: String title, String author, String isbn, boolean

isAvailable.

● Constructor overloading:

○ Default constructor → empty book.


○ Constructor with title and author.

○ Constructor with all details.

● Methods:

○ borrowBook() → sets available = false.

○ returnBook() → sets available = true.

○ displayBookInfo().

● In main(): Create books, borrow/return them, display info.

class Book {

String title, author, isbn;

boolean isAvailable;

Book() { this("Unknown", "Unknown", "N/A", true); }

Book(String title, String author) { this(title, author, "N/A", true); }

Book(String title, String author, String isbn, boolean isAvailable) {

[Link] = title; [Link] = author; [Link] = isbn; [Link] = isAvailable;

void borrowBook() {

if(isAvailable) { isAvailable=false; [Link](title+" borrowed."); }

else [Link](title+" not available.");

void returnBook() {

if(!isAvailable) { isAvailable=true; [Link](title+" returned."); }

else [Link](title+" was not borrowed.");

void displayBookInfo() {

[Link](title+" | "+author+" | "+isbn+" | Available: "+isAvailable);

public static void main(String[] args) {

Book b1=new Book();

Book b2=new Book("1984","George Orwell");

[Link](); [Link](); [Link]();

[Link](); [Link](); [Link](); [Link]();

}
Problem 5: Fitness Tracker 🏃

Design a Fitness Tracker App simulation.

● Class Workout with fields: String activityName, int durationInMinutes, int

caloriesBurned.

● Constructor overloading:

1. Default constructor → "Walking", 30 mins, 100 calories.

2. Constructor with activity name → assigns default duration.

3. Constructor with activity and duration → calculate caloriesBurned = duration × 5.

● Method: displayWorkout() → prints activity details.

● In main(): Create different workouts and display details.

class Workout {

String activityName;

int durationInMinutes, caloriesBurned;

Workout() { this("Walking", 30); [Link] = 100; }

Workout(String activityName) { this(activityName, 30); }

Workout(String activityName, int durationInMinutes) {

[Link] = activityName;

[Link] = durationInMinutes;

[Link] = durationInMinutes * 5;

void displayWorkout() {

[Link](activityName+" | "+durationInMinutes+" mins |


"+caloriesBurned+" cal");

public static void main(String[] args) {

Workout w1 = new Workout();

Workout w2 = new Workout("Running");

[Link]();
[Link]();

You might also like