<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Kayode Shobalaje on Medium]]></title>
        <description><![CDATA[Stories by Kayode Shobalaje on Medium]]></description>
        <link>https://medium.com/@shobbykay.oo?source=rss-ad90dfd18f6a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*dENeBP1Yk-Bxs4JSjx8k6w@2x.jpeg</url>
            <title>Stories by Kayode Shobalaje on Medium</title>
            <link>https://medium.com/@shobbykay.oo?source=rss-ad90dfd18f6a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 06:23:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shobbykay.oo/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Restaurant Sales, Inventory Control, and Profit Analysis Using Database Systems]]></title>
            <link>https://medium.com/@shobbykay.oo/restaurant-sales-inventory-control-and-profit-analysis-using-database-systems-ba671eec24ed?source=rss-ad90dfd18f6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba671eec24ed</guid>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[dbms]]></category>
            <dc:creator><![CDATA[Kayode Shobalaje]]></dc:creator>
            <pubDate>Mon, 01 Jun 2026 04:15:05 GMT</pubDate>
            <atom:updated>2026-06-01T04:15:05.522Z</atom:updated>
            <content:encoded><![CDATA[<p>A practical guide to database modeling, normalization (2NF), and SQL reporting for restaurant business management.</p><h3>Question:</h3><p>a) Madam Kofo, owns a thriving restaurant which sells both local and foreign delicacies in the heart of her town. For some time now, she observed her business has been having very high sales but the profits don’t seem to be commensurate with the sales. She suspects some fraudulent activities and has consulted you as a Computer guru if you could help her in any way. Essentially,she wants to have the following summary at the end of each business day:</p><p>i. Total sales per day <br>ii. Total sales per day for each type of food <br>iii. Total quantity of each type of food available before any sale and after the last sale per day. <br>iv. Total amount (price) of each type of food available before any sale and after the last sale per day. <br>v. Total profit at the end of each day’s sale</p><p>b) Help Madam Kofo design a simple but properly modeled database information.(6 marks)</p><p>c) Ensure that your database is normalized, at least, to 2NF (7 marks)</p><p>d) Write appropriate SQL queries that will help answer her six requests.(7 marks)</p><h3>Solution</h3><p>a) There are entities needed from Madam Kofo’s needs.</p><ul><li>List of foods she sells (Entity — FOOD)</li><li>Sales Transactions (Entity — SALES)</li><li>Food inventory (Entity — INVENTORY)</li></ul><p>i. Total sales per day <strong>(SUM of all sales for day GROUPED BY day)</strong></p><pre>-- This is a pseudocode, not a real SQL query<br><br>GROUP sales BY sale_date<br>CALCULATE SUM(total_amount)<br>DISPLAY total sales per day</pre><p>ii. Total sales per day for each type of food <strong>(SUM of sales for day GROUPED BY day and food type)</strong></p><pre>-- This is a pseudocode, not a real SQL query<br><br>JOIN sales WITH food<br>GROUP records BY sale_date, food_type<br>CALCULATE SUM(total_amount)<br>DISPLAY total sales for each food type per day</pre><p>iii. Total quantity of each type of food available before any sale and after the last sale per day <strong>(Retrieve opening and closing quantities for each food item per day)</strong></p><pre>-- This is a pseudocode, not a real SQL query<br><br>JOIN inventory WITH food<br>GROUP records BY stock_date, food_name<br>RETRIEVE opening_qty, closing_qty<br>DISPLAY quantity before first sale and after last sale</pre><p>iv. Total amount (price) of each type of food available before any sale and after the last sale per day <strong>(Retrieve opening and closing quantities MULTIPLIED by the unit price of each food item)</strong></p><pre>-- This is a pseudocode, not a real SQL query<br><br>JOIN inventory WITH food<br>CALCULATE opening_qty × selling_price<br>CALCULATE closing_qty × selling_price<br>DISPLAY opening value and closing value of each food item</pre><p>v. Total profit at the end of each day’s sale <strong>(total sales for each day minus total cost of each food item)</strong></p><pre>-- This is a pseudocode, not a real SQL query<br><br>JOIN sales WITH food<br>CALCULATE revenue = quantity_sold × selling_price<br>CALCULATE cost = quantity_sold × cost_price<br>CALCULATE profit = revenue - cost<br>GROUP records BY sale_date<br>CALCULATE SUM(profit)<br>DISPLAY total daily profit</pre><blockquote>Please note, for assessment or exam’s sake, the pseudocodes are not exactly needed but they could give extra marks. 😄</blockquote><p>b) <strong>Database Design</strong></p><p>1. FOOD — food_id (PK), food_name, food_type, cost_price, selling_price<br><strong><em>Master list of all dishes with cost and selling price</em></strong></p><p>2. SALES — sales_id (PK), food_id (FK), category_id (FK), quantity_sold, amount_paid, sales_datetime<br><strong><em>Every sale event with time, quantity, and amount</em></strong></p><p>3. INVENTORY — inventory_id (PK), food_id (FK), opening quantity, closing_quantity, inventory_date<br><strong><em>Opening and closing stock per food per day</em></strong></p><p>4. FOOD_CATEGORY — category_id (PK), category_name<br><strong><em>Classifies food (e.g. soups, grills, beverages)</em></strong></p><figure><img alt="Crow’s foot ER diagram showing the database design" src="https://cdn-images-1.medium.com/max/1024/1*C2b8bLIv4xY1JoSC_hxa1g.png" /><figcaption>Crow’s foot ER diagram showing the database design</figcaption></figure><h4>Cardinality or Relationships</h4><ul><li><strong>FOOD → SALES</strong> (food_id FK): one food item can appear in many sales records.</li><li><strong>FOOD_CATEGORY → SALES</strong> (category_id FK): one category classifies many sales, allowing sales to be grouped and reported by food type/category.</li><li><strong>FOOD → INVENTORY</strong> (food_id FK): one food item has many daily inventory records tracking its opening and closing stock.</li></ul><blockquote>Note that <strong>FOOD_CATEGORY is linked directly to the SALES table, not the FOOD table</strong> as defined in the schema. This means the category is recorded at the exact time each sale is made.</blockquote><p>This design is important because it helps detect errors or fraud, such as when an item is wrongly recorded under a different category during a sale.</p><p>c) Normalization to 2NF</p><p><strong>First Normal Form (1NF)</strong> is satisfied because every table has a primary key, all columns are atomic (single-valued), and there are no repeating groups.</p><p><strong>Second Normal Form (2NF)</strong> requires 1NF plus no partial dependencies and every non-key attribute must depend on the <em>whole</em> primary key, not just part of it. This is most relevant to composite keys.</p><p><strong>Sales</strong> table will change,</p><p>From:</p><ul><li><strong>SALES</strong> — Sales_id, food_id, category_id, quantity_sold, amount_paid, sales_datetime</li><li><strong>FOOD</strong> — food_id (PK), food_name, food_type, cost_price, selling_price</li></ul><p>To:</p><ul><li><strong>SALES</strong> — sales_id (PK), food_id (FK), quantity_sold, amount_paid, sales_datetime</li><li><strong>FOOD</strong> — food_id (PK), food_name, category_id (FK), food_type, cost_price, selling_price</li></ul><blockquote>Now every non-key attribute depends entirely on the primary key. And database is in 2NF.</blockquote><blockquote>You can draw tables for question c which is expected but i was unable to draw a table because of the tools available inside Medium.</blockquote><p>d) Queries for a1–5</p><p>i. Total sales per day</p><pre>SELECT<br>    sale_date,<br>    SUM(amount_paid) AS total_daily_sales<br>FROM sales<br>GROUP BY sale_date<br>ORDER BY sale_date DESC;</pre><p>ii. Total sales per day for each type of food (local vs foreign)</p><pre>SELECT<br>    st.sale_date,<br>    fi.food_type,<br>    SUM(st.amount_paid) AS total_sales_by_type<br>FROM sales st<br>JOIN food fi ON st.food_id = fi.food_id<br>GROUP BY st.sale_date, fi.food_type<br>ORDER BY st.sale_date DESC, fi.food_type;</pre><p>iii. Total quantity of each food before and after sales per day</p><pre>SELECT<br>    di.inventory_date,<br>    fi.food_name,<br>    fi.food_type,<br>    di.opening_quantity  AS quantity_before_sales,<br>    di.closing_quantity  AS quantity_after_sales<br>FROM inventory di<br>JOIN food fi ON di.food_id = fi.food_id<br>ORDER BY di.inventory_date DESC, fi.food_name;</pre><p>iv. Total amount (value) of each food in stock before and after sales per day</p><pre>SELECT<br>    di.inventory_date,<br>    fi.food_name,<br>    fi.food_type,<br>    (di.opening_quantity * fi.unit_selling_price) AS stock_value_before_sales,<br>    (di.closing_quantity * fi.unit_selling_price) AS stock_value_after_sales<br>FROM inventory di<br>JOIN food fi ON di.food_id = fi.food_id<br>ORDER BY di.inventory_date DESC, fi.food_name;</pre><p>v. Total profit at the end of each day</p><p>Profit = (selling price × quantity sold) − (cost price × quantity sold)</p><pre>SELECT<br>    st.sale_date,<br>    SUM((fi.unit_selling_price - fi.unit_cost_price) * st.quantity_sold) AS total_daily_profit<br>FROM sales st<br>JOIN food fi ON st.food_id = fi.food_id<br>GROUP BY st.sale_date<br>ORDER BY st.sale_date DESC;</pre><h3><strong>Conclusion</strong></h3><blockquote>This design gives Madam Kofo a complete audit trail. If total sales are high but profits are low, she can compare amount_paid in SALES against the expected unit_selling_price × quantity_sold per transaction making any under-reporting or theft immediately visible.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba671eec24ed" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Entity-Relationship Modeling for an Online Flight Reservation System]]></title>
            <link>https://medium.com/@shobbykay.oo/entity-relationship-modeling-for-an-online-flight-reservation-system-4ac41ef5e91a?source=rss-ad90dfd18f6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ac41ef5e91a</guid>
            <category><![CDATA[entity-relationship-model]]></category>
            <category><![CDATA[database-design]]></category>
            <category><![CDATA[dbms]]></category>
            <category><![CDATA[entity-relationship]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[Kayode Shobalaje]]></dc:creator>
            <pubDate>Mon, 01 Jun 2026 00:06:05 GMT</pubDate>
            <atom:updated>2026-06-01T00:06:05.669Z</atom:updated>
            <content:encoded><![CDATA[<p>Designing a Flight Reservation System: A Complete ER Model with Cardinalities, Relationships, and Business Rules</p><h3>Question</h3><p>Consider a flight reservation system which allows passengers to book their flight online. Create an ER model for the system with clearly shown connectivity, cardinalities and relationships given the following assumptions. You can use either the Crow’s foot or Chen model and you can state any reasonable assumptions made outside the ones provided. (10 marks)</p><p>a. A passenger is entitled to only one seat per flight.</p><p>b. A passenger is required to register his/her luggage (if heavier than 70kg) during reservation.</p><p>c. A passenger can book for more than one flight if and only if the following condition holds; the take- off time for each flight in the flight-sequence is greater than or equal to the arrival time of the immediate previous flight AND the take-off airport of each flight is the destination airport of the immediate previous flight in the sequence.</p><p>d. A flight is attached to one and only one air route.</p><p>e. A flight is attached to only one airplane, but a route can be navigated by more than one airplanes.</p><p>f. Every flight has a take-off airport, an optional stopover airport and a destination airport</p><p>g. Every flight has a take-off time, a landing time and a flight duration.</p><p>h. Every passenger is entitled to:</p><p>(i). one meal on each flight if flight duration is less than 4 hours</p><p>(ii). two meals if flight duration is greater than or equal to 4 hours</p><h3>Solution</h3><p>Let’s draw out the entities and attributes from the question.</p><h4>Entities and Attributes for this model</h4><ol><li>Passenger<br>- passenger_id (PK)<br>- first_name<br>- last_name<br>- gender<br>- phone_number<br>- email_address<br>- country<br>- address<br>- date_time_created</li><li>Reservation (or Booking)<br>- reservation_id (PK)<br>- flight_id (FK)<br>- luggage_size<br>- price<br>- status<br>- reservation_date_time<br>- passenger_id (FK)</li><li>Flight<br>- flight_id (PK)<br>- flight_no <br>- takeoff_date_time<br>- landing_date_time<br>- flight_duration<br>- route_id (FK)<br>- airplane_id (FK)<br>- takeoff_airport_id (FK)<br>- destination_airport_id (FK)<br>- stopover_aiport_id</li><li>Air_Route<br>- route_id (PK)<br>- route_name<br>- distance</li><li>Airport<br>- airport_id (PK)<br>- airport_name<br>- city<br>- state<br>- country</li><li>Airplane<br>- airplane_id (PK)<br>- registration_number<br>- capacity<br>- model<br>- description</li><li>Seat<br>- seat_id (PK)<br>- seat_number<br>- class<br>- airplane_id (FK)<br><strong><em>Assumption:</em></strong><em> class here is for ECONOMY or BUSINESS.</em></li><li>Luggage<br>- luggage_id (PK)<br>- weight<br>- reservation_id (FK)</li><li>Meal<br>- meal_id (PK)<br>- meal_type<br>- meal_description<br><strong><em>#Assumption</em></strong><em>: meal_type can be standard meal, special meal, etc. The description of the meal is the content of the meal e.g for a standard meal: bread and tea, chocolate or coffee, etc.</em></li><li>Flight_Seat_Reservation<br>- reservation_id (PK, FK)<br>- flight_id (PK, FK)<br>- seat_id (FK)<br>- meal_id (FK)<br>- meal_collected<br>- number_of_meals</li></ol><blockquote><strong>Assumption</strong>: If flight duration ≥ 4hours = 2 meals for passenger, else 1 meal (flight duration &lt; 4hours)</blockquote><blockquote>Assumption: The meal_collected attribute is a Boolean field that accepts only two values: 0 (False) or 1 (True). It is defined as NOT NULL and has a default value of 0. This attribute indicates whether the passenger assigned to a particular seat was present on the flight and collected the meal provided during the journey. A value of 1 signifies that the meal was collected, while a value of 0 indicates that it was not collected.</blockquote><blockquote><strong>Assumption</strong>: Although <strong>Reservation_id</strong> alone is sufficient as the primary key for the <strong>Flight_Seat_Reservation</strong> table, combining it with <strong>Flight_id</strong> to form a <strong>composite primary key</strong> enhances data uniqueness and integrity by ensuring that each reservation is uniquely associated with a specific flight.</blockquote><h4>Cardinalities or Relationships between the entities</h4><p>a) PASSENGER — RESERVATION -&gt; 1:M or 1:N (makes)<br>- A passenger can make one or more reservations/bookings, and one/each booking belongs to a passenger</p><p>b) RESERVATION — FLIGHT -&gt; M:N or M:N (books)<br>- A reservation is same with an order in a market. So a reservation can contain one or more flights, a flight can appear in one or more reservations.</p><p>c) RESERVATION/FLIGHT — SEAT -&gt; 1:1 and 1:M<br>- A passenger is entitled to only one seat per flight.<br>- A flight has many seats</p><p>d) RESERVATION — LUGGAGE -&gt; 1:0..M (registers/owns)<br>- A passenger who makes a reservation can have none, one or many luggages registered with his reservation.<br>This is also called, an <strong>optional relationship</strong>.</p><p>e) FLIGHT — AIRPLANE -&gt; M:1 (assigns)<br>- An airplane is assigned to many flights, one or many flight(s) belongs to one airplane.</p><p>f) FLIGHT — AIR_ROUTE -&gt; M:1 (has)<br>- A flight has or can only have a route, and a route has many flights.</p><p>g) FLIGHT — AIRPORT</p><ul><li>Take-Off Airport -&gt; M:1 (A flight takes off from one airport and many flights can take off from one airport)</li><li>Destination Airport -&gt; M:1 (A flight lands at one airport and many flights can land at one airport)</li><li>Stop-Over Airport -&gt; M:1 (A flight can stopover at one airport and many flights can stopover one airport).<em> This is an </em><strong><em>optional relationship</em></strong><em> because flights may decide to not have a stopover at all in the journey of their flight.</em></li></ul><p>h) MEAL — FLIGHT -&gt;M:M or M:N (provides)<br>- Meals are offered in many flights. <strong>If flight duration ≥ 4hours = 2 meals for passenger, else 1 meal (flight duration &lt; 4hours)</strong></p><h3><strong>Crow’s Foot ER Diagram</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JUS3qXoU_lf9oU4AdIneOw.png" /><figcaption>Crow Foot ER Diagram of the airline reservation system</figcaption></figure><p><strong>Download/View Large Image:</strong> <a href="https://drive.google.com/file/d/1TjtnUvEdoWbQEcwwn2jWqunvnnudJBZp/view?usp=sharing">https://drive.google.com/file/d/1TjtnUvEdoWbQEcwwn2jWqunvnnudJBZp/view?usp=sharing</a></p><h3>Chen’s ER Diagram</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LMSyzhtPPd_mxz0DCcKq5A.png" /><figcaption>Chen ERDiagram of the airline reservation system</figcaption></figure><p><strong>Download/View Large Image:</strong><br><a href="https://drive.google.com/file/d/1Xp-p-nZbPnj8HP73V4kbhgNq88tyiFeK/view?usp=drive_link">https://drive.google.com/file/d/1Xp-p-nZbPnj8HP73V4kbhgNq88tyiFeK/view?usp=drive_link</a></p><h3>Extra</h3><blockquote>Re-writing the relationships in a better understandable way. Please note that this section is just to buttress what has been written above for a clearer understanding.</blockquote><h4>1. Passenger → Reservation</h4><ul><li><strong>Relationship:</strong> Passenger makes Reservation</li><li><strong>Type:</strong> One-to-Many</li></ul><pre>Passenger (1) -----------&lt; (0..*) Reservation</pre><ul><li>A passenger can have many reservations</li><li>Each reservation belongs to exactly one passenger</li></ul><h4>2. Flight → Reservation</h4><ul><li><strong>Relationship:</strong> Flight is booked in Reservation</li><li><strong>Type:</strong> One-to-Many</li></ul><pre>Flight (1) -----------&lt; (0..*) Reservation</pre><ul><li>A flight can have many reservations</li><li>Each reservation refers to one flight</li></ul><h4>3. Air_Route → Flight</h4><pre>Air_Route (1) -----------&lt; (0..*) Flight</pre><ul><li>One route can have many flights</li><li>Each flight belongs to one route</li></ul><h4>4. Airplane → Flight</h4><pre>Airplane (1) -----------&lt; (0..*) Flight</pre><ul><li>One airplane can operate many flights</li><li>Each flight uses one airplane</li></ul><h4>5. Airport → Flight (Takeoff)</h4><pre>Airport (1) -----------&lt; (0..*) Flight</pre><p><strong>Role: Takeoff Airport</strong></p><ul><li>One airport can be takeoff point for many flights</li><li>Each flight has exactly one takeoff airport</li></ul><h4>6. Airport → Flight (Destination)</h4><pre>Airport (1) -----------&lt; (0..*) Flight</pre><p><strong>Role: Destination Airport</strong></p><ul><li>One airport can receive many flights</li><li>Each flight has one destination airport</li></ul><h4>7. Airport → Flight (Stopover)</h4><pre>Airport (0..1) -----------&lt; (0..*) Flight</pre><ul><li>Stopover airport is optional for a flight</li><li>A flight may or may not have a stopover</li></ul><h4>8. Airplane → Seat</h4><pre>Airplane (1) -----------&lt; (1..*) Seat</pre><ul><li>Each airplane has many seats</li><li>Each seat belongs to one airplane</li></ul><h4>9. Reservation → Luggage</h4><pre>Reservation (1) -----------&lt; (0..*) Luggage</pre><ul><li>A reservation may have luggage</li><li>Luggage belongs to one reservation</li></ul><h4>10. Meal → Flight_Seat_Reservation</h4><pre>Meal (1) -----------&lt; (0..*) Flight_Seat_Reservation</pre><ul><li>A meal type can be used in many seat reservations</li><li>Each record references one meal</li></ul><h4>11. Reservation + Flight + Seat (Junction Table)</h4><h4>Flight_Seat_Reservation</h4><p>Represents:</p><ul><li>A passenger (via reservation)</li><li>On a specific flight</li><li>Assigned a seat</li><li>Gets meal tracking</li></ul><h3>Re-identifying Relationships:</h3><h4>Reservation → Flight_Seat_Reservation</h4><pre>Reservation (1) -----------&lt; (1..*) Flight_Seat_Reservation</pre><h4>Flight → Flight_Seat_Reservation</h4><pre>Flight (1) -----------&lt; (1..*) Flight_Seat_Reservation</pre><h4>Seat → Flight_Seat_Reservation</h4><pre>Seat (1) -----------&lt; (0..1) Flight_Seat_Reservation</pre><ul><li>A seat can be assigned to only one reservation per flight</li></ul><h3>Conclusion</h3><p>Diagrams may vary in structure and notation; however, the fundamental relationships must remain consistent across all representations. Additionally, not all entities are required to be explicitly displayed in a Chen diagram, but all essential relationships are expected to be accurately represented.</p><p>Please feel free to drop your comments and/or questions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ac41ef5e91a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Designing an Election Management Database System (ERD & SQL Solutions)]]></title>
            <link>https://medium.com/@shobbykay.oo/designing-an-election-management-database-system-erd-sql-solutions-ad850b4667d0?source=rss-ad90dfd18f6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad850b4667d0</guid>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Kayode Shobalaje]]></dc:creator>
            <pubDate>Fri, 29 May 2026 18:38:32 GMT</pubDate>
            <atom:updated>2026-05-29T22:08:28.365Z</atom:updated>
            <content:encoded><![CDATA[<h3>Question:</h3><p>In preparation for the next general election of the Federal Republic of Gege, you as a computer science expert have been called upon by the independent National Electoral Commission of Gege (INECG) to assist them in the design of an ERD which they would se for the electoral process of the general election. Find below the business rule. The Federal Republic of Gege is made up of 37 federal states. Each state is comprised of Local Government Areas which is made up of the smallest political unit called Wards. The local government based on their geographical distribution makes up. the states constituencies, federal constituencies and also senatorial districts. At the beginning of the election process, eligible voters (citizens) whose age are 18 and above are called upon to register with the INECG which in turn register eligible voters at different polling units that makes up a ward. This therefore means that the polling unit where a voter registers is the polling unit where they vote except they request for a change of polling unit from INECG.</p><p>Each registered voter votes for each position as it relates to them. Also, political parties are called upon to register. After their registration, they are expected to forward their candidate for respective positions to INECG so as to populate the voting system with the details of the candidate for each post. Various positions that can be contested for includes, at the federal level (president, senators for each senatorial district, federal house of representative members for each federal constituency) while at the state level (governors and state of representative members for each state constituency). For the position of the president each party is expected to forward just a candidate to INECG while for the governor, each party provides the details of their candidate from each state. Also for senators, they provide the candidates for each senatorial district from each state. Same applies to other positions.</p><p>During elections, INECG staffs who are either full time or contract staff are assigned to different polling units to conduct the voting process. At the end of the election, the votes cast are collated and winners with their runner-ups are announced. Furthermore, political parties that fail to win at least a sit in the electoral process would be deregistered.</p><p>From the information provided above,</p><p>i. Identify the various entities and their attributes. (8 marks)</p><p>ii. Draw an ERD for the scenario above showing cardinalities and connectives. (10 marks)</p><p>Write out the appropriate SQL queries for the scenarios given below</p><p>iii. Determine the total number of votes casted by voters per local government grouped by their states. (3 marks)</p><p>iv. Determine the party that wins for each position per state and the number of votes they got. (this excludes governorship) (3 marks)</p><p>v. Determine parties that are to be deregistered (2 marks)</p><p>vi. Determine states where there is a party that won the governorship election by 2/3 majority of the votes casted during the election. (4 marks)</p><p>(Max allotted time to this question is 1-hr)</p><h3><strong>Solution:</strong></h3><p><strong><em>i. Entities and their attributes</em></strong></p><p><strong>a) State</strong></p><p><strong>state_id</strong> (PK), state_name</p><p><strong>b) Local_Government</strong></p><p><strong>lga_id</strong> (PK), lga_name, state_id (FK)</p><p><strong>c) Ward</strong></p><p><strong>ward_id</strong> (PK), ward_name, lga_id (FK)</p><p>d) Polling_Unit</p><p><strong>polling_unit_id</strong> (PK), polling_unit_name, ward_id (FK)</p><p>e) Constituency</p><p><strong>constituency_id</strong> (PK), constituency_name, constituency_type (Federal / State), state_id (FK)</p><blockquote>Note: constituency_type can have either of the values: (Federal / State)</blockquote><p>f) Senatorial_District</p><p><strong>district_id</strong> (PK), district_name, state_id (FK)</p><p><strong>g) Voter</strong></p><p><strong>voter_id</strong> (PK), voter_name, dob, age, gender, address, polling_unit_id (FK)</p><p>h) Political_Party</p><p><strong>party_id</strong> (PK), party_name, acronym, registration_date, status</p><blockquote>Note: acronym (e.g PDP, ADP, LDP, etc)</blockquote><p>i) Candidate</p><p><strong>candidate_id</strong> (PK), candidate_name, position, party_id (FK), state_id (FK), constituency_id (FK), district_id (FK)</p><p>j) Election_Position</p><p><strong>position_id</strong> (PK), position_name</p><blockquote>Note: position name (e.g President, Governor, Senator, House_of_Rep, State_Assembly)</blockquote><p>k) Staff (for INECG Staff)</p><p><strong>staff_id</strong> (PK), staff_name, staff_type, polling_unit_id (FK)</p><p>l) Vote</p><p><strong>vote_id</strong> (PK), voter_id (FK), candidate_id (FK), position_id (FK), polling_unit_id (FK), vote_date</p><p>ii. ERD for the above (using Crow’s Foot Notation)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J-XI1aIh6Wqrlrt-pl-9NQ.jpeg" /><figcaption>Crow’s Foot Diagram (Entity Relationship)</figcaption></figure><p><em>Let me describe the cardinality from the entities drawn above:</em></p><p>a) State → Local Government (One State has many LGAs) — 1:M</p><p>b) Local Government → Ward (One LGA has many Wards) — 1:M</p><p>c) Ward → Polling Unit (One Ward has many Polling Units) — 1:M</p><p>d) Polling Unit → Voter (One Polling Unit registers many Voters) — 1:M</p><p>e) Political Party → Candidate (One Political Party can sponsor many Candidates) — 1:M</p><p>f) Candidate → Vote (One Candidate can receives many Votes from voters) — 1:M</p><p>g) Voter → Vote (One Voter casts many Votes (strictly one per position)) — 1:M</p><p>h) Polling Unit → Staff (One Polling Unit has many Staffs to conduct voting process) — 1:M</p><p>i) State → Senatorial District (One State has many Senatorial Districts) — 1:M</p><p>j) State → Constituency (One State has many Constituencies) — 1:M</p><p>iii. <strong>Determine the total number of votes casted by voters per local government grouped by their states.</strong></p><pre>SELECT <br>    s.state_name,<br>    l.lga_name,<br>    COUNT(v.vote_id) AS total_votes<br>FROM vote v<br>JOIN polling_unit pu <br>    ON v.polling_unit_id = pu.polling_unit_id<br>JOIN ward w <br>    ON pu.ward_id = w.ward_id<br>JOIN local_government l <br>    ON w.lga_id = l.lga_id<br>JOIN state s <br>    ON l.state_id = s.state_id<br>GROUP BY s.state_name<br>ORDER BY s.state_name;</pre><p>I can also choose to group by LGA after State since each LGA belongs to a particular State. Additionally, the result can be ordered by state_name and then by the highest number of votes in descending order (DESC), as shown in the modified query below:</p><pre>SELECT <br>    s.state_name,<br>    l.lga_name,<br>    COUNT(v.vote_id) AS total_votes<br>FROM Vote v<br>JOIN Polling_Unit pu <br>    ON v.polling_unit_id = pu.polling_unit_id<br>JOIN Ward w <br>    ON pu.ward_id = w.ward_id<br>JOIN Local_Government l <br>    ON w.lga_id = l.lga_id<br>JOIN State s <br>    ON l.state_id = s.state_id<br>GROUP BY s.state_name, l.lga_name<br>ORDER BY s.state_name, total_votes DESC;</pre><p>iv. <strong>Determine the party that wins for each position per state and the number of votes they got. (this excludes governorship)</strong></p><pre>SELECT <br>    s.state_name,<br>    ep.position_name,<br>    pp.party_name,<br>    COUNT(v.vote_id) AS total_votes<br>FROM Vote v<br>JOIN Candidate c <br>    ON v.candidate_id = c.candidate_id<br>JOIN Political_Party pp <br>    ON c.party_id = pp.party_id<br>JOIN Election_Position ep <br>    ON v.position_id = ep.position_id<br>JOIN State s <br>    ON c.state_id = s.state_id<br>WHERE ep.position_name &lt;&gt; &#39;Governor&#39;<br>GROUP BY <br>    s.state_name,<br>    ep.position_name,<br>    pp.party_name<br>ORDER BY <br>    s.state_name,<br>    ep.position_name,<br>    total_votes DESC;</pre><p>In any case, you can also achieve it with a sub group:</p><pre>SELECT <br>    s.state_name,<br>    ep.position_name,<br>    pp.party_name,<br>    COUNT(v.vote_id) AS total_votes<br>FROM Vote v<br>JOIN Candidate c <br>    ON v.candidate_id = c.candidate_id<br>JOIN Political_Party pp <br>    ON c.party_id = pp.party_id<br>JOIN Election_Position ep <br>    ON v.position_id = ep.position_id<br>JOIN State s <br>    ON c.state_id = s.state_id<br>WHERE ep.position_name &lt;&gt; &#39;Governor&#39;<br>GROUP BY s.state_name, ep.position_name, pp.party_name<br>HAVING COUNT(v.vote_id) = (<br>    SELECT MAX(vote_count)<br>    FROM (<br>        SELECT COUNT(v2.vote_id) AS vote_count<br>        FROM Vote v2<br>        JOIN Candidate c2 <br>            ON v2.candidate_id = c2.candidate_id<br>        JOIN Political_Party pp2 <br>            ON c2.party_id = pp2.party_id<br>        JOIN Election_Position ep2 <br>            ON v2.position_id = ep2.position_id<br>        WHERE ep2.position_name = ep.position_name<br>        GROUP BY pp2.party_name<br>    ) AS temp<br>);</pre><p>OR</p><pre>-- parties that win excluding governorship<br><br>SELECT <br>    s.state_name,<br>    p.position_name AS position,<br>    pp.party_name AS winning_party,<br>    vote_counts.total_votes<br>FROM (<br>    SELECT <br>        c.state_id,<br>        c.position_id,<br>        c.party_id,<br>        COUNT(v.vote_id) AS total_votes,<br>        RANK() OVER (<br>            PARTITION BY c.state_id, c.position_id <br>            ORDER BY COUNT(v.vote_id) DESC<br>        ) AS rnk<br>    FROM vote v<br>    JOIN candidate c ON v.candidate_id = c.candidate_id<br>    JOIN election_position p ON c.position_id = p.position_id<br>    WHERE p.position_name != &#39;Governor&#39;<br>    GROUP BY c.state_id, c.position_id, c.party_id<br>) AS vote_counts<br>JOIN state s ON vote_counts.state_id = s.state_id<br>JOIN election_position p ON vote_counts.position_id = p.position_id<br>JOIN political_party pp ON vote_counts.party_id = pp.party_id<br>WHERE vote_counts.rnk = 1;</pre><p>v. <strong>Determine parties that are to be deregistered</strong></p><blockquote>Note: These are Parties that failed to win at least one seat</blockquote><pre>SELECT pp.party_id, pp.party_name<br>FROM political_party pp<br>WHERE pp.party_id NOT IN (<br>    SELECT c.party_id<br>    FROM candidate c<br>    JOIN vote v <br>        ON c.candidate_id = v.candidate_id<br>    GROUP BY c.candidate_id, c.party_id, c.state_id, c.position_id<br>    HAVING COUNT(v.vote_id) = (<br>        SELECT MAX(vote_count)<br>        FROM (<br>            SELECT <br>                c2.state_id,<br>                c2.position_id,<br>                c2.candidate_id,<br>                COUNT(v2.vote_id) AS vote_count<br>            FROM candidate c2<br>            JOIN vote v2 <br>                ON c2.candidate_id = v2.candidate_id<br>            GROUP BY c2.state_id, c2.position_id, c2.candidate_id<br>        ) AS sub<br>        WHERE sub.state_id = c.state_id<br>          AND sub.position_id = c.position_id<br>    )<br>);</pre><p>And it can be rewritten with subquery as:</p><pre>SELECT pp.party_id, pp.party_name<br>FROM political_party pp<br>WHERE pp.party_id NOT IN (<br>    SELECT DISTINCT c.party_id<br>    FROM (<br>        SELECT <br>            c.candidate_id,<br>            c.party_id,<br>            c.state_id,<br>            c.position_id,<br>            COUNT(v.vote_id) AS total_votes,<br>            RANK() OVER (<br>                PARTITION BY c.state_id, c.position_id <br>                ORDER BY COUNT(v.vote_id) DESC<br>            ) AS rnk<br>        FROM vote v<br>        JOIN candidate c ON v.candidate_id = c.candidate_id<br>        GROUP BY c.candidate_id, c.party_id, c.state_id, c.position_id<br>    ) AS ranked<br>    JOIN candidate c ON ranked.candidate_id = c.candidate_id<br>    WHERE ranked.rnk = 1<br>);</pre><p>OR</p><pre>-- parties to be deregistered<br><br>SELECT <br>    pp.party_name<br>FROM Political_Party pp<br>WHERE pp.party_id NOT IN (<br>    SELECT DISTINCT c.party_id<br>    FROM Candidate c<br>    JOIN Vote v <br>        ON c.candidate_id = v.candidate_id<br>);</pre><p>vi. Determine states where a party won governorship by 2/3 majority</p><pre>SELECT <br>    s.state_name,<br>    pp.party_name,<br>    COUNT(v.vote_id) AS total_votes<br>FROM Vote v<br>JOIN Candidate c <br>    ON v.candidate_id = c.candidate_id<br>JOIN Political_Party pp <br>    ON c.party_id = pp.party_id<br>JOIN Election_Position ep <br>    ON v.position_id = ep.position_id<br>JOIN State s <br>    ON c.state_id = s.state_id<br>WHERE ep.position_name = &#39;Governor&#39;<br>GROUP BY s.state_name, pp.party_name<br>HAVING COUNT(v.vote_id) &gt;= (<br>    COUNT(v.vote_id) * 2 / 3<br>)<br>ORDER BY total_votes DESC;</pre><p>And it can be rewritten as:</p><pre>SELECT <br>    s.state_name,<br>    pp.party_name,<br>    COUNT(v.vote_id) AS governor_votes,<br>    total.total_votes<br>FROM Vote v<br>JOIN Candidate c <br>    ON v.candidate_id = c.candidate_id<br>JOIN Political_Party pp <br>    ON c.party_id = pp.party_id<br>JOIN Election_Position ep <br>    ON v.position_id = ep.position_id<br>JOIN State s <br>    ON c.state_id = s.state_id<br>JOIN (<br>    SELECT <br>        c2.state_id,<br>        COUNT(v2.vote_id) AS total_votes<br>    FROM Vote v2<br>    JOIN Candidate c2 <br>        ON v2.candidate_id = c2.candidate_id<br>    JOIN Election_Position ep2 <br>        ON v2.position_id = ep2.position_id<br>    WHERE ep2.position_name = &#39;Governor&#39;<br>    GROUP BY c2.state_id<br>) total<br>ON s.state_id = total.state_id<br>WHERE ep.position_name = &#39;Governor&#39;<br>GROUP BY s.state_name, pp.party_name, total.total_votes<br>HAVING COUNT(v.vote_id) &gt;= (2 * total.total_votes / 3);</pre><p>To test run this whole scenerio properly, click to download below:</p><blockquote>Download my sample dataset<br><a href="https://drive.google.com/file/d/1HEAU0uB4c4HucfLyyHkdhOB36lmFNB0L/view?usp=sharing">https://drive.google.com/file/d/1HEAU0uB4c4HucfLyyHkdhOB36lmFNB0L/view?usp=sharing</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad850b4667d0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Create a Java Menu-Driven Math Application Using Switch Statements]]></title>
            <link>https://medium.com/@shobbykay.oo/question-73d533873461?source=rss-ad90dfd18f6a------2</link>
            <guid isPermaLink="false">https://medium.com/p/73d533873461</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Kayode Shobalaje]]></dc:creator>
            <pubDate>Wed, 20 May 2026 18:04:26 GMT</pubDate>
            <atom:updated>2026-05-29T18:50:24.167Z</atom:updated>
            <content:encoded><![CDATA[<p>Build a Java menu-driven math app using switch statements, covering equations, interest calculation, and a number guessing game.</p><h4>Question:</h4><p>A menu driven mathematics program has the following five options:</p><p>Option I: A simultaneous equation is solved</p><p>Option 2: A quadratic equation is solved</p><p>Option 3: The user is asked to guess a number from 1 to 5. Then a random number from 1 to 5 is generated. If the random number generated matches the user’s guessed number, the program congratulates the user. If not, it says, “Sorry you missed it”</p><p>Option 4: The interest on an amount invested for a number of years at certain rate is computed</p><p>Option 5: The program says “Thanks for using this program, Bye ….“ and then exit.</p><p>Implement the menu-driven program using the concept of switch. else-if statements and random number generator. You may use the past programs on random number generator, simultaneous and quadratic equations in this program in Java programming language.</p><p>Record the challenges you had and your observations in this exercise.</p><h2>Introduction</h2><p>In this project, I built a menu-driven mathematics program in Java that allows users to solve simultaneous equations, quadratic equations, calculate interest, and play a random number guessing game. The project demonstrates the use of switch statements, conditional statements, methods, and Java’s random number generator.</p><h3><strong>Objectives of the Program</strong></h3><p>•	Understand menu-driven programming</p><p>•	Learn how switch statements work</p><p>•	Practice solving mathematical problems in Java</p><p>•	Implement random number generation</p><p>•	Improve user interaction in console applications.</p><h3>Technologies / Concepts Used</h3><p>•	Java</p><p>•	Switch statements</p><p>•	If-else statements</p><p>•	Methods</p><p>•	Scanner class</p><p>•	Random number generation</p><p>•	Loops</p><h3>Program Features</h3><p>Break down each menu option clearly.</p><p>Option 1 — Simultaneous Equation Solver</p><p>Explain briefly what it does.</p><p>Option 2 — Quadratic Equation Solver</p><p>Mention discriminant and roots.</p><p>Option 3 — Random Number Guessing Game</p><p>Explain the guessing logic.</p><p>Option 4 — Interest Calculator</p><p>Explain the simple interest formula.</p><p>Option 5 — Exit Program</p><p>Explain graceful program termination.</p><h3>Source Code</h3><p>This is the code that implements the question (function based).</p><pre>import java.util.Random;<br>import java.util.Scanner;<br>import java.lang.Math;<br><br>class Main {<br>    public static void main(String[] args) {<br>        System.out.print(&quot;-- Enter a menu from 1-5: --&quot;);<br>        <br>        Scanner input = new Scanner(System.in);<br>        int choice = input.nextInt();<br>        <br>        switch (choice) {<br>            case 1:<br>                simultaneous_equation(input);<br>                break;<br>            case 2:<br>                quadratic_equation(input);<br>                break;<br>            case 3:<br>                random_guess(input);<br>                break;<br>            case 4:<br>                simple_interest(input);<br>                break;<br>            case 5:<br>                System.out.println(&quot;Thanks for using this program, Bye.&quot;);<br>                break;<br>            default:<br>                System.out.println(&quot;Invalid Choice entered&quot;);<br>        }<br>    }<br>    <br>    static void simultaneous_equation(Scanner input){<br>        // Equation format:<br>        // a1x + b1y = c1<br>        // a2x + b2y = c2<br><br>        System.out.println(&quot;Enter coefficients for first equation:&quot;);<br>        System.out.print(&quot;a1: &quot;);<br>        double a1 = input.nextDouble();<br><br>        System.out.print(&quot;b1: &quot;);<br>        double b1 = input.nextDouble();<br><br>        System.out.print(&quot;c1: &quot;);<br>        double c1 = input.nextDouble();<br><br>        System.out.println(&quot;\nEnter coefficients for second equation:&quot;);<br>        System.out.print(&quot;a2: &quot;);<br>        double a2 = input.nextDouble();<br><br>        System.out.print(&quot;b2: &quot;);<br>        double b2 = input.nextDouble();<br><br>        System.out.print(&quot;c2: &quot;);<br>        double c2 = input.nextDouble();<br><br>        // Determinant<br>        double determinant = (a1 * b2) - (a2 * b1);<br><br>        // Check if solution exists<br>        if (determinant == 0) {<br>            System.out.println(&quot;\nThe equations have no unique solution.&quot;);<br>        } else {<br><br>            // Cramer&#39;s Rule<br>            double x = ((c1 * b2) - (c2 * b1)) / determinant;<br>            double y = ((a1 * c2) - (a2 * c1)) / determinant;<br><br>            System.out.println(&quot;\nSolution:&quot;);<br>            System.out.println(&quot;x = &quot; + String.format(&quot;%.2f&quot;, x));<br>            System.out.println(&quot;y = &quot; + String.format(&quot;%.2f&quot;, y));<br>        }<br>    }<br>    <br>    static void quadratic_equation(Scanner input){<br>        // a, b, c<br>        System.out.print(&quot;\nEnter number a: &quot;);<br>        int a = input.nextInt();<br>        <br>        System.out.print(&quot;\nEnter number b: &quot;);<br>        int b = input.nextInt();<br>        <br>        System.out.print(&quot;\nEnter number c: &quot;);<br>        int c = input.nextInt();<br>        <br>        Double x1 = ( (-1 * b) + Math.sqrt (Math.pow(b, 2) - 4 * a * c) ) / (2 * a);<br>        Double x2 = ( (-1 * b) - Math.sqrt (Math.pow(b, 2) - 4 * a * c) ) / (2 * a);<br>        <br>        System.out.println(<br>            &quot;\nThis quadratic equation has two values: &quot; +<br>            String.format(&quot;%.2f&quot;, x1) +<br>            &quot; and &quot; +<br>            String.format(&quot;%.2f&quot;, x2)<br>        );<br>        <br>        // formula ==&gt; ( -b + Math.sqrt (Math.pow(b, 2) - 4 * a * c) ) / (2 * a)<br>    }<br>    <br>    static void random_guess(Scanner input){<br>        System.out.print(&quot;\nGuess a number from 1-5: &quot;);<br>        int guessed_number = input.nextInt();<br>        <br>        if (guessed_number &gt;= 1 &amp;&amp; guessed_number &lt;= 5){<br>            int randomNum = (int)(Math.random() * (5 - 1) + 1);<br>            <br>            if (guessed_number == 2){<br>                System.out.println(&quot;\nCongratulations, you guessed correctly.&quot;);<br>            } else{<br>                System.out.println(&quot;\nSorry you missed it!&quot;);<br>            }<br>            <br>        } else{<br>            System.out.println(&quot;\nYour guessed number is out of range.&quot;);<br>        }<br>    }<br>    <br>    static void simple_interest(Scanner input){<br>        // Principal, rate, time<br>        System.out.print(&quot;\nEnter the principal amount: &quot;);<br>        Double principal = input.nextDouble();<br>        <br>        System.out.print(&quot;\nEnter the rate: &quot;);<br>        Double rate = input.nextDouble();<br>        <br>        System.out.print(&quot;\nEnter the time: &quot;);<br>        Double time = input.nextDouble();<br>        <br>        Double simple_interest = (principal * rate * time) / 100;<br>        <br>        System.out.println(&quot;\nYour simple interest is &quot; + String.valueOf(simple_interest));<br>    }<br>}<br><br><br>// <br>// accept input 1-5 (switch)<br>// 1 -simultaneous<br>// 2- quadratic<br>// 3 - random guess<br>// 4 - simple interest<br>// 5 - say a greeting<br><br>// catch errors</pre><h3>Challenges Faced</h3><p>•	Handling invalid user input</p><p>•	Understanding switch-case flow</p><p>•	Generating random numbers within a range</p><p>•	Avoiding program crashes from division by zero</p><h3>Observations</h3><ul><li>Switch statements make menu programs easier to manage.</li><li>Methods improve code organization</li><li>Random number generation adds interactivity</li><li>Java mathematical functions simplify calculations</li></ul><h3>Conclusion</h3><p>This project improved my understanding of Java programming concepts such as switch statements, conditional logic, mathematical computation, and user interaction. It also demonstrated how multiple programming concepts can be combined into one practical application.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=73d533873461" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>