Published using Google Docs
ParkedCar Project
Updated automatically every 5 minutes

ParkedCar Class Design:

Class ParkedCar

+make: string

+model: string

+color: string

+licenseNumber: string

+minutesParked: int

+constructor()

+UpdateMinsParked()

+Park()

ParkedCar Attribute Descriptions:

ParkedCar Method Descriptions:

ParkingMeter Class Design:

Class ParkingMeter

+minutesBought: int

+parkingSpace: int

+car: ParkedCar

+constructor()

ParkingMeter Attribute Descriptions:

ParkingMeter Method Descriptions:

ParkingTicket Class Design:

Class ParkingTicket

+car: ParkedCar

+overage: int

+violationFee: decimal

+reportingOfficer: PoliceOfficer

+constructor()

+GenerateReport()

ParkingTicket Attribute Descriptions:

ParkingTicket Method Descriptions:

PoliceOfficer Class Design:

Class PoliceOfficer

+officerName: string

+officerBadge: string

+constructor()

+CheckSpace()

PoliceOfficer Attribute Descriptions:

PoliceOfficer Method Descriptions:

Overview and General implementation:

The plan is to start off the main function by creating a vector, array, or list of some kind, then populate it with 10 car objects that are already parked and assigned to a meter. This way we will have a good testing sample to work with.

After the cars and meters are set up, we will then create the police officer that will be patrolling. The method of simulation will be a while loop that indefinitely iterates forwards and backwards through the list, checking the spaces as it passes them. The program should provide feedback for every space visited. For example, “Populated Space, no violation”, or “Populated Space, violation”. If a violation is found, the program will output the ticket report, then continue the officer’s patrol.

There should be sleep time between every space check in order to give the user time to read the output. Once the officer reaches each end of the parking lot, there will be a prompt asking if the user would like to continue running the simulation.

Responsibilities:

Output:

The general output should go something like as follows:

 

 

Between each space check, we want the console to wait a few seconds to give you time to process the information. Also, if a violation is found, we want the console to wait a few seconds to give the impression that it has to generate the report before outputting the report below. The parking spaces should display as numbers rather than letters.

Github Link:

https://github.com/TheBajaBust/Chad-Team-Project-Repo

Code

using System;

using System.Collections.Generic;

using System.Linq;

using System.Management.Instrumentation;

using System.Reflection.Emit;

using System.Runtime.CompilerServices;

using System.Text;

using System.Threading.Tasks;

using System.Threading;

using System.Linq.Expressions;

using System.Runtime.InteropServices;

namespace Team_Project_1

{

    internal class Program

    {

        static void Main(string[] args)

        {

            //Creates a list for us to put the objects into

            List<ParkedCar> parkedCars= new List<ParkedCar>();

            //creates test objects

            ParkedCar Chevy = new ParkedCar("Chevy", "Cruze", "Silver", "HEV 123");

            ParkedCar Kia = new ParkedCar("Kia", "Sorento", "Silver", "HAY 889");

            ParkedCar Mazda = new ParkedCar("Mazda", "626", "Green", "HNU H7A");

            ParkedCar Ford = new ParkedCar("Ford", "Fusion", "Black", "GTGFST");

            ParkedCar Dodge = new ParkedCar("Dodge", "Challenger", "Yellow", "BMBL BE");

            ParkedCar Volkswagen = new ParkedCar("Volkswagen", "Beetle", "Pink", "78I HI2");

            ParkedCar Toyota = new ParkedCar("Toyota", "Camry", "Red", "HAR MNY");

            ParkedCar Honda = new ParkedCar("Honda", "Civic", "Blue", "NAR DWR");

            ParkedCar Lincoln = new ParkedCar("Lincoln", "Towncar", "Gold", "HNK HIL");

            ParkedCar Audi = new ParkedCar("Audi", "Etron - S", "White", "TOMNJRY");

            //adds test objects into the list

            parkedCars.Add(Chevy);

            parkedCars.Add(Kia);

            parkedCars.Add(Mazda);

            parkedCars.Add(Ford);

            parkedCars.Add(Dodge);

            parkedCars.Add(Volkswagen);

            parkedCars.Add(Toyota);

            parkedCars.Add(Honda);

            parkedCars.Add(Lincoln);

            parkedCars.Add(Audi);

            //parking all of the cars and buying time (creating parkingmeter objects)

            Chevy.Park(220, parkedCars.IndexOf(Chevy)); //1

            Kia.Park(165, parkedCars.IndexOf(Kia)); //2

            Mazda.Park(180, parkedCars.IndexOf(Mazda)); //3

            Ford.Park(115, parkedCars.IndexOf(Ford)); //4

            Dodge.Park(30, parkedCars.IndexOf(Dodge)); //5

            Volkswagen.Park(145, parkedCars.IndexOf(Volkswagen)); //6

            Toyota.Park(280, parkedCars.IndexOf(Toyota)); //7

            Honda.Park(130, parkedCars.IndexOf(Honda)); //8

            Lincoln.Park(110, parkedCars.IndexOf(Lincoln)); //9

            Audi.Park(139, parkedCars.IndexOf(Audi)); //10

            Console.WriteLine("What is the officer's name?");

            string name = Console.ReadLine();

            Console.WriteLine("What is the officer's badge number?");

            int num = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine();

            PoliceOfficer officer = new PoliceOfficer(name, num);

            bool loop = true;

            while (loop == true)

            {

                //for loop doing the main simulation.

                for (int i = 0; i < parkedCars.Count; i++)

                {

                    //for loop adding updating the minutesParked for each car for each iteration or round of the while loop

                    for (int j = 0; j < parkedCars.Count; j++)

                    {

                        parkedCars[j].updateMinutesParked();

                    }

                    officer.CheckForViolation(parkedCars[i]);

                    Console.WriteLine();

                    Thread.Sleep(3000);

                }

                Console.WriteLine("Do you want to continue patrolling? y/n");

                string userInput = Console.ReadLine();

                if(userInput == "n")

                {

                    loop = false;

                }

                for (int k = parkedCars.Count - 1; k >= 0; k--)

                {

                    for (int j = 0; j < parkedCars.Count; j++)

                    {

                        parkedCars[j].updateMinutesParked();

                    }

                    officer.CheckForViolation(parkedCars[k]);

                    Console.WriteLine();

                    Thread.Sleep(3000);

                }

                Console.WriteLine("Do you want to continue patrolling? y/n");

                userInput = Console.ReadLine();

                if (userInput == "n")

                {

                    loop = false;

                }

            }

            Console.WriteLine("Patrol Finished!");

            Console.ReadKey();

           

            //Test comment. If you see this, your github probably synced properly

        }

        class ParkedCar

        {

            public string make;

            public string model;

            public string color;

            public string licenseNumber;

            public int minutesParked;

            public ParkingMeter meter;

            public ParkedCar(string parkedMake, string parkedModel, string parkedColor, string parkedLicenseNumber)

            {

                make = parkedMake;

                model = parkedModel;

                color = parkedColor;

                licenseNumber = parkedLicenseNumber;

                minutesParked = 0;

            }

            public void Park(int buy, int space)

            {

                 meter  = new ParkingMeter(buy, space, this);

            }

            public void updateMinutesParked()

            {

                minutesParked = minutesParked + 10;

            }

        }

        class ParkingMeter

        {

            public int minutesBought;

            public int parkingSpace;

            public ParkedCar car;

            public ParkingMeter(int MeterMinutes, int MeterSpace, ParkedCar car)

            {

                minutesBought = MeterMinutes;

                parkingSpace = MeterSpace;

                this.car = car;

            }

        }

        class ParkingTicket

        {

            public ParkedCar car;

            public int minutesOver;

            public decimal violationFee;

            public PoliceOfficer issuingOfficer;

            public ParkingTicket(ParkedCar car, int minutesOver, PoliceOfficer issuingOfficer)

            {

                this.car = car;

                this.minutesOver = minutesOver;

                this.issuingOfficer = issuingOfficer;

                CalculateViolationFee();

            }

            private void CalculateViolationFee()

            {

                decimal baseFee = 25.00m;

                decimal perMinuteFee = 0.16m;

                violationFee = baseFee + (perMinuteFee * minutesOver);

            }

            public void GenerateReport()

            {

                Console.WriteLine("Violation at space: " + car.meter.parkingSpace);

                Console.WriteLine("");

                Console.WriteLine("--Generating Report--");

                Thread.Sleep(3000);

                Console.WriteLine("     CAR DETAILS:");

                Console.WriteLine("      Make: " + car.make);

                Console.WriteLine("      Model: " + car.model);

                Console.WriteLine("      Color: " + car.color);

                Console.WriteLine("      License Number: " + car.licenseNumber);

                Console.WriteLine("");

                Console.WriteLine("     VIOLATION DETAILS:");

                Console.WriteLine("      Minutes Over: " + minutesOver);

                Console.WriteLine("      Violation Fee: $" + violationFee);

                Console.WriteLine("");

                Console.WriteLine("     ISSUING OFFICER:");

                Console.WriteLine("      Name: " + issuingOfficer.name);

                Console.WriteLine("      Badge Number: " + issuingOfficer.badgeNumber);

                Console.WriteLine("");

            }

        }

        class PoliceOfficer

        {

            public string name;

            public int badgeNumber;

            public PoliceOfficer(string name, int badgeNumber)

            {

                this.name = name;

                this.badgeNumber = badgeNumber;

            }

            public bool CheckForViolation(ParkedCar car)

            {

                int minutesOver = car.minutesParked - car.meter.minutesBought;

                if (minutesOver > 0)

                {

                    IssueParkingTicket(car, minutesOver);

                    return true;

                }

                Console.WriteLine("No Violation at parking space " + car.meter.parkingSpace);

                return false;

            }

            private void IssueParkingTicket(ParkedCar car, int minutesOver)

            {

                ParkingTicket ticket = new ParkingTicket(car, minutesOver, this);

                ticket.GenerateReport();

            }

        }

    }

}