0% found this document useful (0 votes)
10 views5 pages

OOP Case Study

The document describes a Java program that models a mall using object-oriented programming concepts. The Mall class defines attributes like name, location, capacity and current visitors. Methods like addVisitors(), removeVisitors() and displayMallInfo() demonstrate method overloading and returning objects. The main method creates a Mall object, adds and removes visitors, and displays the updated information.

Uploaded by

nikbhamare2225
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)
10 views5 pages

OOP Case Study

The document describes a Java program that models a mall using object-oriented programming concepts. The Mall class defines attributes like name, location, capacity and current visitors. Methods like addVisitors(), removeVisitors() and displayMallInfo() demonstrate method overloading and returning objects. The main method creates a Mall object, adds and removes visitors, and displays the updated information.

Uploaded by

nikbhamare2225
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
You are on page 1/ 5

Department of Information Technology

Name of Student: Nikhil Bhamare Enrolment no. 22510007


Class: Information Technology Subject: OOP

Title of Case study:

Mall-Name,Location,VisitorCapacity,Visitor Count methods


List OOP concepts used:
1. Class
2. Object
3. Array of object
4. This keyword
5. Static data
6. Static function
7. Method overloading
8. Object as argument
9. Object as return type and constructor

Program :

package javaassignment;

import java.util.*;

public class Mall {


// Class variables
private static int mallCount = 0;

// Object variables
private String name;
private String location;
private int capacity;
private int currentVisitors;
// Constructor
public Mall(String name, String location, int capacity) {
this.name = name;
this.location = location;
this.capacity = capacity;
this.currentVisitors = 0;
mallCount++;
}

// Static method to get the total count of malls


public static int getMallCount() {
return mallCount;
}

// Method to add visitors to the mall


public void addVisitors(int visitors) {
if (currentVisitors + visitors <= capacity) {
currentVisitors += visitors;
System.out.println(visitors + " visitors entered " + name);
} else {
System.out.println("Capacity exceeded! Cannot add more visitors to " +
name);
}
}

// Method to remove visitors from the mall


public void removeVisitors(int visitors) {
if (currentVisitors - visitors >= 0) {
currentVisitors -= visitors;
System.out.println(visitors + " visitors left " + name);
} else {
System.out.println("There are not enough visitors in " + name + " to
remove.");
}
}

// Method to display mall information


public void displayMallInfo() {
System.out.println("Mall Name: " + name);
System.out.println("Location: " + location);
System.out.println("Capacity: " + capacity);
System.out.println("Current Visitors: " + currentVisitors);
}
// Method overloading example: method with object as argument
public void displayMallInfo(Mall mall) {
System.out.println("Mall Name: " + mall.name);
System.out.println("Location: " + mall.location);
System.out.println("Capacity: " + mall.capacity);
System.out.println("Current Visitors: " + mall.currentVisitors);
}

// Method to return object as return type


public static Mall createMall(String name, String location, int capacity) {
return new Mall(name, location, capacity);
}

// Static data example


public static final String openingTime = "9:00 AM";

public static void main(String[] args) {


Scanner scanner = new Scanner(System.in);

// User input for mall details


System.out.println("Enter Mall Name:");
String mallName = scanner.nextLine();

System.out.println("Enter Mall Location:");


String mallLocation = scanner.nextLine();

System.out.println("Enter Mall Capacity:");


int mallCapacity = scanner.nextInt();

// Create mall object


Mall mall = new Mall(mallName, mallLocation, mallCapacity);

// Display mall information


System.out.println("Mall created successfully!");
mall.displayMallInfo();

// Add visitors
System.out.println("Enter the number of visitors to add:");
int visitorsToAdd = scanner.nextInt();
mall.addVisitors(visitorsToAdd);

// Remove visitors
System.out.println("Enter the number of visitors to remove:");
int visitorsToRemove = scanner.nextInt();
mall.removeVisitors(visitorsToRemove);
// Display mall information again
System.out.println("Updated Mall Information:");
mall.displayMallInfo();

// Close scanner
scanner.close();
}
}
H

Output

Enter Mall Name:


Phoenix
Enter Mall Location:
Wagholi
Enter Mall Capacity:
5000
Mall created successfully!
Mall Name: Phoenix
Location: Wagholi
Capacity: 5000
Current Visitors: 0
Enter the number of visitors to add:
500
500 visitors entered Phoenix
Enter the number of visitors to remove:
200
200 visitors left Phoenix
Updated Mall Information:
Mall Name: Phoenix
Location: Wagholi
Capacity: 5000
Current Visitors: 300

You might also like