-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
83 lines (71 loc) · 2.4 KB
/
Copy pathmain.js
File metadata and controls
83 lines (71 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import promptSync from 'prompt-sync';
import { GradebookManager } from './gradebookManager.js';
// Initialize prompt and gradebook manager
const prompt = promptSync();
const manager = new GradebookManager();
const filename = 'students.txt';
let running = true;
// Main menu loop
while (running) {
console.log("\n--- Student Gradebook ---");
console.log("1. Add Student");
console.log("2. Add Grade to Student");
console.log("3. View Students and Grades");
console.log("4. Show All Averages");
console.log("5. Delete Student");
console.log("6. Save to File");
console.log("7. Load from File");
console.log("8. Exit");
const choice = prompt("Choose an option: ");
// Perform the action based on the user's choice
switch (choice) {
case '1':
const name = prompt("Enter student name: ");
manager.addStudent(name);
console.log("Student added.");
break;
case '2':
const studentName = prompt("Enter student name: ")
const s = manager.findStudent(studentName);
if (s) {
const gradeInput = prompt("Enter grade (integer): ");
const grade = parseInt(gradeInput);
if (!isNaN(grade)) {
s.addGrade(grade);
console.log("Grade added.");
} else {
console.log("Invalid grade.");
}
} else {
console.log("Student not found.");
}
break;
case '3':
manager.viewStudentsWithGrades();
break;
case '4':
manager.printAllAverages();
break;
case '5':
const nameToDelete = prompt("Enter student name to delete: ");
const deleted = manager.deleteStudent(nameToDelete);
if (deleted) {
console.log(`Student '${nameToDelete}' deleted.`);
} else {
console.log(`Student '${nameToDelete}' not found.`);
}
break;
case '6':
manager.saveToFile(filename);
break;
case '7':
manager.loadFromFile(filename);
break;
case '8':
running = false;
console.log("Goodbye!");
break;
default:
console.log("Invalid choice. Try again.");
}
}