Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New changes #28

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions NHW2.1/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
3 changes: 3 additions & 0 deletions NHW2.1/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions NHW2.1/.idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions NHW2.1/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions NHW2.1/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions NHW2.1/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>Ironhack.schl</groupId>
<artifactId>NHW2.1</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>

<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.10.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
77 changes: 77 additions & 0 deletions NHW2.1/src/main/java/Ironhack/schl/Course.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package Ironhack.schl;

import java.util.UUID;

public class Course {
private String courseId;
private String name;
private double price;
private double moneyEarned;
private Teacher teacher;


// New constructor
public Course(String courseId, String name, double price) {
this.courseId = courseId;
this.name = name;
this.price = price;
this.moneyEarned = 0.0; // Initialize moneyEarned to 0
}

public Course(String name, double price) {
this.courseId = UUID.randomUUID().toString();
this.price = price;
this.name = name;
}

public String getCourseId() {
return courseId;
}

public void setCourseId(String courseId) {
this.courseId = courseId;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public double getPrice() {
return price;
}

public void setPrice(double price) {
this.price = price;
}

public double getMoneyEarned() {
return moneyEarned;
}

public void setMoneyEarned(double moneyEarned) {
this.moneyEarned = moneyEarned;
}

public Teacher getTeacher() {
return teacher;
}

public void setTeacher(Teacher teacher) {
this.teacher = teacher;
}

@Override
public String toString() {
return "Course{" +
"courseID='" + courseId + '\'' +
", name='" + name + '\'' +
", price=" + price +
", moneyEarned=" + moneyEarned +
", teacher=" + teacher +
'}';
}
}
105 changes: 105 additions & 0 deletions NHW2.1/src/main/java/Ironhack/schl/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package Ironhack.schl;

import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);

// Prompt the user for the name of the school
System.out.print("Enter the name of the school: ");
String schoolName = scanner.nextLine();

// Create the SchoolManagementSystem instance
SchoolManagementSystem sms = new SchoolManagementSystem();

// Prompt the user for the number of teachers, courses, and students
System.out.print("Enter the number of teachers: ");
int numTeachers = scanner.nextInt();
scanner.nextLine(); // Consume the newline character

System.out.print("Enter the number of courses: ");
int numCourses = scanner.nextInt();
scanner.nextLine();

System.out.print("Enter the number of students: ");
int numStudents = scanner.nextInt();
scanner.nextLine();

// Collect and store teacher details
for (int i = 0; i < numTeachers; i++) {
System.out.println("Enter teacher details for Teacher " + (i + 1));
System.out.print("Name: ");
String teacherName = scanner.nextLine();

Teacher teacher = new Teacher(teacherName, 60000);
sms.teachers.put(Integer.toString(i + 1), teacher);
}

// Collect and store course details
for (int i = 0; i < numCourses; i++) {
System.out.println("Enter course details for Course " + (i + 1));
System.out.print("Name: ");
String courseName = scanner.nextLine();

Course course = new Course(courseName, 1000);
sms.courses.put(Integer.toString(i + 1), course);
}

// Collect and store student details
for (int i = 0; i < numStudents; i++) {
System.out.println("Enter student details for Student " + (i + 1));
System.out.print("Name: ");
String studentName = scanner.nextLine();
System.out.print("Address: ");
String studentAddress = scanner.nextLine();
System.out.print("Email: ");
String studentEmail = scanner.nextLine();

Student student = new Student(studentName, studentAddress, studentEmail);
sms.students.put(Integer.toString(i + 1), student);
}

// Main loop to handle commands
while (true) {
System.out.println("Enter command:");
String command = scanner.nextLine();
String[] parts = command.split(" ");

try {
switch (parts[0]) {
case "ENROLL":
sms.enrollStudent(parts[1], parts[2]);
break;
case "ASSIGN":
sms.assignTeacher(parts[1], parts[2]);
break;
case "SHOW":
if (parts[1].equals("COURSES")) {
sms.showCourses();
} else if (parts[1].equals("STUDENTS")) {
sms.showStudents();
} else if (parts[1].equals("TEACHERS")) {
sms.showTeachers();
} else if (parts[1].equals("PROFIT")) {
sms.showProfit();
}
break;
case "LOOKUP":
if (parts[1].equals("COURSE")) {
sms.lookupCourse(parts[2]);
} else if (parts[1].equals("STUDENT")) {
sms.lookupStudent(parts[2]);
} else if (parts[1].equals("TEACHER")) {
sms.lookupTeacher(parts[2]);
}
break;
default:
System.out.println("Unknown command");
}
} catch (Exception e) {
System.out.println("Error executing command: " + e.getMessage());
}
}
}
}
Loading