Skip to content
Share
Explore

Sunset Vacations

image.png

Object-Oriented Modeling in the Real World

Today, we’re diving into how object-oriented modeling—a way of designing programs using "objects" that act like real-world things—helps solve problems all around us. From timing traffic lights to predicting where to build new malls or housing developments, this approach is everywhere. In our Kotlin vacation app for Sunrise Resort, we’re using it to figure out how changing prices affects demand and profit. Let’s explore how this works broadly, then zoom into our app with some code examples!
What Is Object-Oriented Modeling?
Think of object-oriented modeling as building a digital version of the world. We create objects—like tiny building blocks—that have properties (data) and behaviors (actions). These objects team up to mimic real systems. Here’s how it’s used:
Timing Traffic Lights: Imagine a TrafficLight object with properties like color (red, green, yellow) and behaviors like switchColor(). A bunch of these objects could work together in a Intersection class, using timers to keep traffic flowing smoothly—say, turning green every 30 seconds based on traffic sensors.
Predicting Mall Locations: A Mall object might have properties like location, size, and expectedCustomers, with behaviors like calculateProfit(). Developers could pair it with a Population object tracking people’s locations and spending habits, then run simulations to find the best spot—maybe near a busy highway or growing suburb.
Housing Developments: A HousingDevelopment object could track lotSize, price, and demand, with a method like predictSales(). Combine it with City objects holding data on jobs and schools, and you can model where people want to live—like near a new tech hub.

This method breaks big problems into manageable pieces, making it easier to test ideas and predict outcomes!

Our Vacation App: A Simplified Example

In our app, we’re modeling vacation activities at Sunrise Resort—fishing tours, scuba excursions, and eco wilderness hikes. We use objects to represent these activities, tweak their prices, and see how demand and profit change.
We’re using the factory method pattern to create these objects and random numbers to simulate price changes. In real jobs, though, you’d dig into empirical business records—actual sales data—to set prices that make more money with fewer bookings. Let’s see how!
Code Example: Factory Method Constructor
Here’s how we create our vacation objects using the factory method pattern in the Vacation class:
abstract class Vacation(var price: Double) {
abstract val type: String
abstract fun demand(): Int

companion object {
fun createVacation(type: String, price: Double): Vacation {
return when (type) {
"FishingTour" -> FishingTour(price)
"ScubaExcursion" -> ScubaExcursion(price)
"EcoWildernessHike" -> EcoWildernessHike(price)
else -> throw IllegalArgumentException("Invalid vacation type")
} } } }

class FishingTour(price: Double) : Vacation(price) {
override val type = "FishingTour"
override fun demand() = max(0.0, 100 - 0.45 * price).roundToInt()
}

// Usage in main()
fun main() {
val vacations = mutableListOf<Vacation>()
vacations.add(Vacation.createVacation("FishingTour", 200.0))
vacations.add(Vacation.createVacation("ScubaExcursion", 300.0))
vacations.add(Vacation.createVacation("EcoWildernessHike", 250.0))
// ... more code follows
}

What’s Happening: The createVacation() method in the companion object acts like a factory—it builds the right vacation object based on the type we ask for. We don’t call FishingTour(200.0) directly; the factory handles it, keeping creation neat and flexible (like adding new vacation types later).

Why It’s Cool: This pattern is like a blueprint for making objects, used in traffic light systems or mall models too—think a LightFactory or MallFactory!

Code Example: Random Numbers vs. Empirical Data

Now, here’s where we generate random prices in our loop:
import java.util.Random
fun main() {
val vacations = mutableListOf<Vacation>()
vacations.add(Vacation.createVacation("FishingTour", 200.0))
vacations.add(Vacation.createVacation("ScubaExcursion", 300.0))
vacations.add(Vacation.createVacation("EcoWildernessHike", 250.0))

val random = Random(42) // Fixed seed for consistent results
for (i in 1..10) {
val fishingTourPrice = random.nextDouble(100.0, 300.0)
val scubaExcursionPrice = random.nextDouble(200.0, 400.0)
val ecoWildernessHikePrice = random.nextDouble(200.0, 350.0)

vacations[0].price = fishingTourPrice
vacations[1].price = scubaExcursionPrice
vacations[2].price = ecoWildernessHikePrice
// ... demand and profit calculated next
}

}
Random Numbers: We use random.nextDouble(min, max) to pick prices—like $150 or $280—testing 10 different scenarios. The demand functions (e.g., 100 - 0.45 * price) guess how many people sign up.

Real Work Difference: At a job, you’d review empirical business records—say, last year’s sales showing 50 people paid $150 for fishing tours, but only 30 paid $200. You’d analyze this to charge more (like $200) for fewer bookings (30) if it makes more profit than $150 for 50. No random guessing—just data-driven decisions!

Simplified Here: We’re not factoring in service delivery costs (like staff or equipment)—in reality, that’s key. If a fishing tour costs $80 per person to run, profit drops, and the best price changes. We skipped this to keep it simple, but it’s a big deal in real optimization.

What’s Quantitative Analysis?

Quantitative analysis is using numbers and math to make smart choices. In our app, it’s tweaking prices to maximize profit based on demand guesses. In traffic lights, it’s timing lights to reduce wait times using car counts. For malls, it’s predicting sales from population data. At work, it’s crunching sales numbers to find the sweet spot—more revenue with less product—using stats like regression to model demand from real records. It’s about turning data into decisions!

Why This Matters

image.png
Object-oriented modeling lets us build digital twins of anything—traffic systems, retail plans, or resorts. Our app’s random prices are a starting point, teaching you how to simulate and analyze. In practice, you’ll swap random for real data, adding costs for true quantitative optimization. Run our code, graph the CSV, and imagine using sales records next time—you’re on your way to solving real problems like a pro!
This introduction ties object-oriented modeling to diverse applications, uses code to show the factory method and random generation, contrasts it with empirical work practices, simplifies by omitting service costs, and defines quantitative analysis

Understanding Price Modulation in the Kotlin Vacation Application
Table of Contents 1. Abstract 2. Introduction: Setting the Scene 3. The Application: Modeling Vacations at Sunrise Resort 4. Modulating Prices: Where and How It Happens - 4.1 Random Price Generation in the Exercise - 4.2 Updating Prices in the Code 5. Demand Dynamics: Linking Price to Sign-Ups - 5.1 Demand Functions Explained - 5.2 Calculating Demand in the Loop 6. Revenue Impact: From Demand to Profit - 6.1 Profit Calculation Mechanics - 6.2 Aggregating Total Profit 7. Learning with Random vs. Real-World Empirical Data - 7.1 Why Random for This Exercise? - 7.2 Empirical Analysis in Practice 8. Putting It All Together: The CSV Output 9. Educational Takeaways and Next Steps 10. Conclusion: Bridging Learning to Reality
---
1. Abstract This narrative guides students through a Kotlin-based learning exercise designed to explore how modulating prices for vacation activities—like fishing tours, scuba excursions, and eco wilderness hikes at Sunrise Resort—affects demand and overall revenue generation. The application uses the factory method pattern to create vacation objects, stored in a mutable list, and runs 10 iterations with randomly generated prices to simulate pricing experiments. Demand is calculated via predefined functions, and profits are computed and saved to a CSV file for graphing in Excel. While prices and demand are randomly generated for simplicity, the exercise contrasts this with real-world practice, where empirical business data drives such decisions, preparing students to connect programming concepts to practical economic analysis.
---
2. Introduction: Setting the Scene Imagine you’re running Sunrise Resort, a place offering fishing tours, scuba excursions, and eco wilderness hikes. Your job is to figure out the best prices to charge to make the most profit. Do you set prices high and hope a few people pay more, or keep them low to attract a crowd? In this Kotlin application, we’re building a tool to test that out—not with real sales data yet, but with a fun simulation. This exercise lets us play with prices, see how they affect how many people sign up (demand), and check the profit (revenue) we’d make, all while learning some cool coding tricks!
image.png

3. The Application: Modeling Vacations at Sunrise Resort

Our app models three vacation activities using Kotlin’s factory method pattern. We’ve got an abstract class `Vacation` with a `price` property, and three subclasses—`FishingTour`, `ScubaExcursion`, and `EcoWildernessHike`—each with its own rules for how price affects demand. These objects live in a mutable list called `vacations`, so we can tweak their prices easily. The app runs 10 “experiments” (iterations), changing prices each time, calculating demand and profit, and saving everything to a CSV file called "profit_data.csv" for graphing later. It’s like a mini business simulator!
---
4. Modulating Prices: Where and How It Happens Learing Topic: 4.1 Random Price Generation in the Exercise To test different pricing scenarios, we don’t just pick one price and stick with it—we change them 10 times using a loop in the `main()` function. Each time, we pick random prices within set ranges: - Fishing tours: $100 to $300 - Scuba excursions: $200 to $400 - Eco wilderness hikes: $200 to $350
Here’s the code where it happens:
```kotlin for (i in 1..10) { val fishingTourPrice = random.nextDouble(100.0, 300.0) val scubaExcursionPrice = random.nextDouble(200.0, 400.0) val ecoWildernessHikePrice = random.nextDouble(200.0, 350.0) // ... prices get set next } ```
We use `Random(42)` to generate these numbers, with `42` ensuring we get the same “random” prices every time we run it—great for learning consistency!
Learing Topic: 4.2 Updating Prices in the Code Once we’ve got our random prices, we update the `price` property of each vacation object in the `vacations` list:
```kotlin vacations[0].price = fishingTourPrice vacations[1].price = scubaExcursionPrice vacations[2].price = ecoWildernessHikePrice ```
Since `price` is a mutable property (defined with `var` in the `Vacation` class), we can change it directly. This is where the modulation happens—each iteration tests a new price combo, setting the stage to see how it affects demand and profit.
---
5. Demand Dynamics: Linking Price to Sign-Ups Learing Topic: 5.1 Demand Functions Explained How do we know how many people sign up at these prices? Each vacation type has a demand function—a rule that says, “If the price is this, here’s how many people join.” They’re built into the classes: - FishingTour: `demand() = max(0.0, 100 - 0.45 * price).roundToInt()` - Example: $100 → 55 people; $300 → 0 people (too pricey!). - ScubaExcursion: `demand() = max(0.0, 200 - 0.6167 * price).roundToInt()` - Example: $200 → 77 people; $400 → 0 people. - EcoWildernessHike: `demand() = max(0.0, 150 - 0.52 * price).roundToInt()` - Example: $200 → 46 people; $350 → 0 people.
These are simple guesses for now—higher prices mean fewer sign-ups, and if it’s too high, no one comes!
Learing Topic: 5.2 Calculating Demand in the Loop After setting new prices, we calculate demand in the `getVacationData()` function:
```kotlin fun getVacationData(vacations: List<Vacation>, costs: Map<String, Double>): List<VacationData> { return vacations.map { vacation -> val cost = costs[vacation.type] ?: 0.0 val numberSold = vacation.demand() // Demand reacts to the new price! val profit = (vacation.price - cost) * numberSold VacationData(vacation.type, vacation.price, numberSold, profit) } } ```
Every time the loop sets a price, `vacation.demand()` uses it to figure out `numberSold`. This ties price changes directly to how many people we expect to join each activity.
---
6. Revenue Impact: From Demand to Profit Learing Topic: 6.1 Profit Calculation Mechanics Revenue—or profit—comes from how much we make after costs. Each activity has a fixed cost ($100 for fishing, $150 for scuba, $200 for hikes), and profit is:
- Profit = (Price - Cost) * Number Sold
In `getVacationData()`, we calculate this for each vacation: - Example: FishingTour at $150, 32 people sign up → Profit = (150 - 100) * 32 = $1600.
Learing Topic: 6.2 Aggregating Total Profit The total profit for each iteration is the sum of profits from all three activities:
```kotlin val vacationData = getVacationData(vacations, costs) val totalProfit = vacationData.sumOf { it.profit } ```
This happens inside the loop, so every price change leads to a new total profit, showing how our pricing experiment affects overall revenue.
---
7. Learning with Random vs. Real-World Empirical Data Learing Topic: 7.1 Why Random for This Exercise? We’re using random prices and made-up demand functions because it’s a learning exercise: - Easy Start: No real data needed—just code and imagination! - Quick Testing: We can try tons of prices fast (10 times in one run). - Core Idea: It shows how price, demand, and profit connect without complications.
Think of it like a sandbox—safe to mess around in while we learn the basics.
Learing Topic: 7.2 Empirical Analysis in Practice In the real world, Sunrise Resort wouldn’t guess. They’d use empirical data—real numbers from their business: - Prices: Past prices they’ve charged, like $150 last year for fishing tours. - Demand: Actual sign-ups, like 50 people at $150, 30 at $200, from sales records or surveys. - How It’d Work: Load data from a file or database, not `Random`:
```kotlin val realData = listOf(mapOf("FishingTour" to 150.0, "NumberSold" to 50)) for (data in realData) { vacations[0].price = data["FishingTour"] ?: 0.0 val numberSold = data["NumberSold"] ?: 0 val profit = (vacations[0].price - costs["FishingTour"]!!) * numberSold } ```
Analysts would study this data to find the best prices, not randomly test. Our demand functions are a toy version of what they’d build from real stats.
---
8. Putting It All Together: The CSV Output The loop ties everything into a neat package: 1. Picks random prices and sets them. 2. Calculates demand with those prices. 3. Computes profit for each activity and the total. 4. Saves it all to "profit_data.csv":
```kotlin out.println("${data.iteration},${String.format("%.2f", data.fishingTourPrice)},..." + "${String.format("%.2f", data.totalProfit)}") ```
This CSV has columns like “FishingTour Price,” “Number Sold,” and “Total Profit,” so you can graph trends in Excel—like how profit changes with price.
---
9. Educational Takeaways and Next Steps This exercise teaches you: - How to tweak object properties (prices) in a loop. - How demand reacts to price changes in code. - How to turn numbers into profit and save them for analysis.
It’s a stepping stone! In real life, you’d swap random prices for real sales data. Try running the app, graphing the CSV, and imagining how you’d get actual numbers from Sunrise Resort to make it real. Maybe lower prices pack the tours, or higher ones boost profit per person—what do you think?
---
10. Conclusion: Bridging Learning to Reality Our app modulates prices in a loop, using random numbers to test how they affect demand and profit at Sunrise Resort. It’s a simplified version of what businesses do with real data—analyzing sales to set prices that maximize revenue. By mastering this, you’re ready to move from random experiments to real-world empirical analysis. Run it, graph it, and think about how you’d use actual business data next time—pretty exciting stuff!
---
This narrative weaves all the explanations into a cohesive story, keeping it student-friendly while covering the technical details and real-world context!
image.png
Want to print your doc?
This is not the way.
Try clicking the ··· in the right corner or using a keyboard shortcut (
CtrlP
) instead.