workshop done
This commit is contained in:
+30
@@ -0,0 +1,30 @@
|
||||
### IntelliJ IDEA ###
|
||||
out/
|
||||
!**/src/main/**/out/
|
||||
!**/src/test/**/out/
|
||||
.kotlin
|
||||
|
||||
### Eclipse ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
.factorypath
|
||||
.project
|
||||
.settings
|
||||
.springBeans
|
||||
.sts4-cache
|
||||
bin/
|
||||
!**/src/main/**/bin/
|
||||
!**/src/test/**/bin/
|
||||
|
||||
### NetBeans ###
|
||||
/nbproject/private/
|
||||
/nbbuild/
|
||||
/dist/
|
||||
/nbdist/
|
||||
/.nb-gradle/
|
||||
|
||||
### VS Code ###
|
||||
.vscode/
|
||||
|
||||
### Mac OS ###
|
||||
.DS_Store
|
||||
Generated
+10
@@ -0,0 +1,10 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
||||
# Ignored default folder with query files
|
||||
/queries/
|
||||
# Datasource local storage ignored files
|
||||
/dataSources/
|
||||
/dataSources.local.xml
|
||||
# Editor-based HTTP Client requests
|
||||
/httpRequests/
|
||||
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" default="true" project-jdk-name="25" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
Generated
+8
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/Workshop 02 - IntroToOOP.iml" filepath="$PROJECT_DIR$/Workshop 02 - IntroToOOP.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -0,0 +1,43 @@
|
||||
|
||||
public class Course {
|
||||
private String courseName;
|
||||
private String courseCode;
|
||||
private int capacity;
|
||||
|
||||
public Course(String courseName, String courseCode, int capacity)
|
||||
{
|
||||
this.courseName = courseName;
|
||||
this.courseCode = courseCode;
|
||||
this.capacity = capacity;
|
||||
}
|
||||
|
||||
public String getCourseName()
|
||||
{
|
||||
return courseName;
|
||||
}
|
||||
|
||||
public String getCourseCode()
|
||||
{
|
||||
return courseCode;
|
||||
}
|
||||
|
||||
public int getCapacity()
|
||||
{
|
||||
return capacity;
|
||||
}
|
||||
|
||||
public boolean reduceCapacity()
|
||||
{
|
||||
if (capacity > 0)
|
||||
{
|
||||
capacity--;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void increaseCapacity()
|
||||
{
|
||||
capacity++;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import java.util.Scanner;
|
||||
|
||||
public class Main
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
|
||||
Scanner input = new Scanner(System.in);
|
||||
|
||||
// گرفتن اطلاعات دانشآموز از ورودی
|
||||
System.out.print("Enter student name: ");
|
||||
String name = input.nextLine();
|
||||
|
||||
System.out.print("Enter student ID: ");
|
||||
String studentId = input.nextLine();
|
||||
|
||||
Student s1 = new Student(name, studentId);
|
||||
|
||||
// ساخت 3 درس
|
||||
Course c1 = new Course("Advanced Programming", "AP1404", 2);
|
||||
Course c2 = new Course("Data Structures", "DS1404", 1);
|
||||
Course c3 = new Course("Database Systems", "DB1404", 3);
|
||||
|
||||
// ساخت سیستم ثبت نام
|
||||
RegistrationSystem sys = new RegistrationSystem();
|
||||
|
||||
// اضافه کردن درسها به سیستم
|
||||
sys.addCourseToSystem(c1);
|
||||
sys.addCourseToSystem(c2);
|
||||
sys.addCourseToSystem(c3);
|
||||
|
||||
// ثبتنام خودکار دانشآموز
|
||||
s1.addCourse(c1);
|
||||
s1.addCourse(c2);
|
||||
|
||||
// حذف یکی از درسها
|
||||
s1.dropCourse(c2);
|
||||
|
||||
// نمایش درسهای ثبتشده
|
||||
System.out.println("\nFinal registered courses:");
|
||||
s1.showRegisteredCourses();
|
||||
|
||||
// نمایش ظرفیت باقیماندهی همه درسها
|
||||
System.out.println("\nRemaining course capacities:");
|
||||
sys.showAllCourses();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class RegistrationSystem {
|
||||
private ArrayList<Course> courses;
|
||||
|
||||
public RegistrationSystem() {
|
||||
courses = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void addCourseToSystem(Course c) {
|
||||
// Add the course to the system
|
||||
courses.add(c);
|
||||
}
|
||||
|
||||
public Course findCourseByCode(String code) {
|
||||
// Search for a course by course code
|
||||
for (Course c : courses) {
|
||||
if (c.getCourseCode().equals(code)) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void showAllCourses() {
|
||||
// Print all courses in the system
|
||||
for (Course c : courses) {
|
||||
System.out.println(
|
||||
c.getCourseName() + " - " +
|
||||
c.getCourseCode() +
|
||||
" | Remaining capacity: " +
|
||||
c.getCapacity()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Student {
|
||||
private String name;
|
||||
private String studentId;
|
||||
private ArrayList<Course> registeredCourses;
|
||||
|
||||
public Student(String name, String studentId)
|
||||
{
|
||||
this.name = name;
|
||||
this.studentId = studentId;
|
||||
this.registeredCourses = new ArrayList<>();
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getStudentId()
|
||||
{
|
||||
return studentId;
|
||||
}
|
||||
|
||||
public boolean addCourse(Course c)
|
||||
{
|
||||
// Check capacity > 0
|
||||
if (c.getCapacity() > 0)
|
||||
{
|
||||
registeredCourses.add(c);
|
||||
c.reduceCapacity();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean dropCourse(Course c)
|
||||
{
|
||||
if (registeredCourses.remove(c))
|
||||
{
|
||||
c.increaseCapacity();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void showRegisteredCourses()
|
||||
{
|
||||
System.out.println("Registered Courses for " + name + ":");
|
||||
if (registeredCourses.isEmpty())
|
||||
{
|
||||
System.out.println("No courses registered.");
|
||||
}
|
||||
for (Course c : registeredCourses)
|
||||
{
|
||||
System.out.println(c.getCourseName() + " - " + c.getCourseCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user