QUESTION 1
Company Creative Solutions has installed a pre-paid electricity meter. They have bought500 electricity units from Checkers for R908. They load the units on the pre-paid electricity meter exactly at 08:00 on the day of installation (See picture). They took the reading every hour from 09:00 till 17:00. They want to determine how many units they have used from 08:00 till 17:00. They also want to know the average consumption of electricity per day and which time during the day was the highest consumption.
Make use of the following main method and output screen to create a complete C# project.
static void Main(string[] args)
{
int[] units = new int[10];
int highest;
MyDetails();
PopulateArray(units);
PrintUnitArray(units);
Calculations(units);
highest = HighestConsumption (units);
Console.WriteLine (“The highest consumption was from {0:D2}:00
till {1:D2}:00.”,highest+8, highest+9);
Console.ReadKey();
}
Do the following: (See rubrics for mark allocation)
1. Create a method MyDetails that will display your (i) name and surname, (ii) student number, (iii) the date, and (iv) a short description of the project.
2. Create a method PopulateArray that will do the following:
- The company has bought 500 electricity units. Assign these units to the first element inside the array.
- Read from the user the value that is displayed on the prepaid meter every hour. Make use of for a statement to read in the values. (See output screen)
- Validate the entries from the user in order to make sure that the readings of each hour are lesser or equal to the previous hour’s reading (The readings decrease because electricity units are used during the day).
- Remember that the units cannot be negative. Make use of a do-while statement to do the validation.
- Make sure that there are no unhandled exceptions. Include the try statement and only two catch blocks (Format Exception and General Exception). It is not necessary to include the final block. Inspect the output screen for hints.
3. Create a method PrintUnitArray that will display the content of the array to the user. See output screen.
4. Create a method Calculations that will do the following:
- Display how many units were used from 08:00 till 17:00.
- Display the average usage per hour. See output screen.
5. Create a method HighestConsumption that will locate which time during the day was the highest electricity consumption. (See output screen and Main method for hints).
Assume that there will only be ONE time during the day that was the highest electricity consumption. Therefore, the usage of electricity units per hour will be UNIQUE for
the day.
QUESTION 2
A local Higher Education Institution has restricted the number of students who may enter a venue due to Covid-19. They ask you to implement an object-orientated system for them to keep track of how many students already entered a venue and how many seats are still
available inside the venue. The below C# Main method ONLY demonstrates the functionality of the class. The below output screen ONLY demonstrates the execution of the below Main method.
static void Main(string[] args)
{
int spacesAvailable;
string message;
Corona venue1 = new Corona();
Corona venue2 = new Corona(100);
Corona venue3 = new Corona(70,40);
Console.WriteLine(“Information for Venue 1 – {0}”, venue1.PrintInfo());
Console.WriteLine(“Information for Venue 2 – {0}”, venue2.PrintInfo());
Console.WriteLine(“Information for Venue 3 – {0}”, venue3.PrintInfo());
spacesAvailable = venue3.Available();
Console.WriteLine(“\nVenue 3 – {0} places are available.”, spacesAvailable);
Console.WriteLine(“15 Students entered the venue”);
message = venue3.Entered(15);
Console.WriteLine(“Venue 3 – {0}”, message);
Console.WriteLine(“\n55 Students left the venue”);
message = venue3.LeftVenue(55);
Console.WriteLine(“Venue 3 – {0}”, message);
Console.ReadKey();
}
Do the following:
1 Create a class Corona from which objects can be instantiated. Each object of the class contains two integer instance variables, namely size, and students. The instance variable size indicates the maximum number of students who are allowed in the venue and it defaults to 50 because the smallest venue can accommodate 50 students. The instance variable students indicate the number of students that have already entered the venue and it defaults to zero (0). You are only allowed to address the instance variables inside the properties.
2. Implement the following constructors: The constructor with no parameters uses the default values for the instance variables. The constructor that receives one parameter uses it to indicate the size (number of seats) of the venue and it uses the default value for the other instance variable. The constructor that receives two parameters uses the first parameter to indicate the size (number of seats) of the
venue and it uses the second parameter for the number of students that have already entered the venue. Make use of a constructor initializer.
3. Create the necessary properties namely MySize and MyStudents. The maximum size (number of seats) of any venue is 100. Use the default values for any invalid entries received in the properties. Remember to validate.
4. Implement a method Available that returns the number of seats that are available inside the venue.
5. Implement a method Entered that received one (1) parameter, namely the number of students who want to enter the venue. If there are enough seats for all the students, update the instance variables. The method should return one of the following messages:
- If there were enough seats available, return a message (“Information
recorded”) - If there were not enough seats available for the students, return a message (“Too many students for the venue”). See output screen.
6. Implement a method LeftVenue that received one (1) parameter, namely the number of students who want to leave the venue. If there is at least this number of students inside the venue, update the instance variables. The method should return one of the following messages:
- If there were still enough students inside the venue, return a message
(“Information recorded”). - If there were not so many students still inside the venue, return a message (“Not that many students in the venue”). See output screen.
7. Implement a method PrintInfo that will return a string indicating the size of the venue and also how many students are already inside the venue. See output screen.
8. Improve the main method to be more user friendly. You can use any initiative inside the Main method.