import 'dart:io'; import 'module.dart'; List modules = []; void main() { int? choice = 1; while (choice != 5) { choice = menu(); if (choice != null && choice >= 1 && choice <= 5) { switch (choice) { case 1: createFromExisting(); break; case 2: printModuleData(); break; case 3: changeWeights(); break; case 4: printAverageOfClass(); break; } } else { print('Invalid choice, please choose again'); choice = -1; } } print('Good bye!'); } void createFromExisting() { //30 marks //This method retrieves the data from the TPG316C.csv file to create a new Module // //Steps: //1. Ask the user to enter a name for the new module //2. Read the name //3. Ask the user to enter the name of the file to read module data from (we will use TPG316C.csv) //4. Read the name of the file //5. Read the lines from the file into a List //6. Create a new Module instance with empty fields, except for the name of the Module //7. Use the first element in the List created in step 5 to extract the heading (use split method) // The first 2 values is the FirstName and LastName headers. Everything after that will be the names of marks. // The names for this file is Sem1Mark and Sem2Mark. Make provision for any number of marks. Save the mark name // into the markNames (List) field of the new Module instance. //8. Remove the first element of the List created in step 5 to remove the header. You are then left with only // student data. //9. Run a loop through the data of the List created in step 5: // - Add a Student object to the students field (List) in the new Module instance. // - Create an empty Map map to represent the specific student's marks // - Add the student's marks in the map as follows: // { Sem1Mark : 100, Sem2Mark : 100 } // - Add the map to the marks field (List>) in the new Module instance. //10. Run a loop through the markNames, created in step 7, and ask the user for the weight of every mark // Add those weights to the weights field (List) of the new Module instance. //11. Add the new Module to the modules field (List) declared above the main method. } void printModuleData() { //30 marks //This method will print all info of the Module chosen // //Steps: //1. List the available modules to choose from and ask the user to choose a module //2. Print a column heading (Name, Surname ---> Sem1Mark--Sem2Mark--) // Note that the heading could be different depending on the file you read from //3. Run a loop through the students field of the Module chosen: // - Print the student name and surname // - Create a running total variable to sum the marks of the specific student after weights applied // - e.g. mark = (sem1Mark * sem1Weight) / 100 // - Create a loop inside point 3's loop to run through the markNames field of the Module chosen: // - get the marks from the map using the markName(s) as key // - get the weight of the marks from the weights field of the Module chosen // - work out the marks after the weights has been applied and add to the running total // - print out the mark // - Print the value of the running total (the average of the student's marks) } void changeWeights() { //10 marks //This method will change all weights of Marks to new weights //Steps: //1. Ask the user to choose a module to change the weights for //2. Run a loop through the markNames field of the chosen Module // - Ask the user to enter the weight of every mark // - Change the weight in the weights field of the chosen Module } void printAverageOfClass() { //10 marks //This method will print the average mark for the class //Steps: //1. Ask the user for the Module to print the average //2. Create a running total initialized to 0 //3. Run a loop through the students field of the Module chosen: // - Create a running total variable to sum the marks of the specific student after weights applied // - e.g. mark = (sem1Mark * sem1Weight) / 100 // - Run a loop through the markNames field of the Module chosen: // - get the marks from the map using the markName(s) // - get the weight of the marks from the weights field of the Module chosen // - work out the marks after the weights has been applied and add to the running total // - Add the running total to the running total of step 2 } // code reuse - 10 marks // defensive programming techniques - 10 marks int? menu() { print('\n\nWelcome to our application!'); print('Menu: '); print('1. Create new modules from existing data'); print('2. Print a module\'s marks'); print('3. Change weights'); print('4. Work out the average of the class'); print('5. Exit'); print('Please enter your choice: '); return int.tryParse(stdin.readLineSync()!); } //place this class in its own file called module.dart import 'student.dart'; class Module { List students; String moduleName; List markNames; List weights; List> marks; Module({ required this.students, required this.moduleName, required this.markNames, required this.marks, required this.weights, }); }
import 'dart:io';
import 'module.dart';
List<Module> modules = [];
void main() {
int? choice = 1;
while (choice != 5) {
choice = menu();
if (choice != null && choice >= 1 && choice <= 5) {
switch (choice) {
case 1:
createFromExisting();
break;
case 2:
printModuleData();
break;
case 3:
changeWeights();
break;
case 4:
printAverageOfClass();
break;
}
} else {
print('Invalid choice, please choose again');
choice = -1;
}
}
print('Good bye!');
}
void createFromExisting() {
//30 marks
//This method retrieves the data from the TPG316C.csv file to create a new Module
//
//Steps:
//1. Ask the user to enter a name for the new module
//2. Read the name
//3. Ask the user to enter the name of the file to read module data from (we will use TPG316C.csv)
//4. Read the name of the file
//5. Read the lines from the file into a List<String>
//6. Create a new Module instance with empty fields, except for the name of the Module
//7. Use the first element in the List<String> created in step 5 to extract the heading (use split method)
// The first 2 values is the FirstName and LastName headers. Everything after that will be the names of marks.
// The names for this file is Sem1Mark and Sem2Mark. Make provision for any number of marks. Save the mark name
// into the markNames (List<String>) field of the new Module instance.
//8. Remove the first element of the List created in step 5 to remove the header. You are then left with only
// student data.
//9. Run a loop through the data of the List created in step 5:
// - Add a Student object to the students field (List<Student>) in the new Module instance.
// - Create an empty Map<String, double> map to represent the specific student's marks
// - Add the student's marks in the map as follows:
// { Sem1Mark : 100, Sem2Mark : 100 }
// - Add the map to the marks field (List<Map<String, double>>) in the new Module instance.
//10. Run a loop through the markNames, created in step 7, and ask the user for the weight of every mark
// Add those weights to the weights field (List<double>) of the new Module instance.
//11. Add the new Module to the modules field (List<Module>) declared above the main method.
}
void printModuleData() {
//30 marks
//This method will print all info of the Module chosen
//
//Steps:
//1. List the available modules to choose from and ask the user to choose a module
//2. Print a column heading (Name, Surname ---> Sem1Mark--Sem2Mark--)
// Note that the heading could be different depending on the file you read from
//3. Run a loop through the students field of the Module chosen:
// - Print the student name and surname
// - Create a running total variable to sum the marks of the specific student after weights applied
// - e.g. mark = (sem1Mark * sem1Weight) / 100
// - Create a loop inside point 3's loop to run through the markNames field of the Module chosen:
// - get the marks from the map using the markName(s) as key
// - get the weight of the marks from the weights field of the Module chosen
// - work out the marks after the weights has been applied and add to the running total
// - print out the mark
// - Print the value of the running total (the average of the student's marks)
}
void changeWeights() {
//10 marks
//This method will change all weights of Marks to new weights
//Steps:
//1. Ask the user to choose a module to change the weights for
//2. Run a loop through the markNames field of the chosen Module
// - Ask the user to enter the weight of every mark
// - Change the weight in the weights field of the chosen Module
}
void printAverageOfClass() {
//10 marks
//This method will print the average mark for the class
//Steps:
//1. Ask the user for the Module to print the average
//2. Create a running total initialized to 0
//3. Run a loop through the students field of the Module chosen:
// - Create a running total variable to sum the marks of the specific student after weights applied
// - e.g. mark = (sem1Mark * sem1Weight) / 100
// - Run a loop through the markNames field of the Module chosen:
// - get the marks from the map using the markName(s)
// - get the weight of the marks
from the weights field of the Module chosen
// - work out the marks after the weights has been applied and add to the running total
// - Add the running total to the running total of step 2
}
// code reuse - 10 marks
// defensive programming techniques - 10 marks
int? menu() {
print('\n\nWelcome to our application!');
print('Menu: ');
print('1. Create new modules from existing data');
print('2. Print a module\'s marks');
print('3. Change weights');
print('4. Work out the average of the class');
print('5. Exit');
print('Please enter your choice: ');
return int.tryParse(stdin.readLineSync()!);
}
//place this class in its own file called module.dart
import 'student.dart';
class Module {
List<Student> students;
String moduleName;
List<String> markNames;
List<double> weights;
List<Map<String, double>> marks;
Module({
required this.students,
required this.moduleName,
required this.markNames,
required this.marks,
required this.weights,
});
}


Step by step
Solved in 3 steps









