Skip to content

Commit 120a632

Browse files
author
thaycacac
committed
💃 add: passed & docs
1 parent b29db04 commit 120a632

256 files changed

Lines changed: 15989 additions & 1 deletion

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎README.md‎

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,42 @@
1-
Java
1+
# Java FPT
2+
3+
This repo include all source code java when I learned in university.
4+
5+
### PRO192 - Java Core
6+
7+
- Code in class
8+
- Project in class (DuyDT)
9+
10+
### PRJ311 - Desktop Java Applications
11+
12+
- Bank for Practical Exam
13+
- Example Practical Exam
14+
15+
### CSD201 - Data Structures and Algorithms
16+
17+
- My Linked List
18+
- My Stack
19+
- Recursion
20+
- My Tree
21+
- My Graph
22+
- My Hash Table
23+
- My Sorting
24+
- Bank for Practical Exam
25+
- Example Practical Exam
26+
27+
### LAB211 - OOP with Java Lab
28+
29+
- Included three lesson that I passed (TuanVM)
30+
31+
### LAB221 - Desktop Java Lab
32+
33+
- Included two lesson that I passed (TuanVM)
34+
35+
### PRJ321 - Web-based Java Applications
36+
37+
- Code in class
38+
- Example Practical Exam
39+
40+
### LAB231 - Web Java Lab
41+
42+
Just included two lesson that I passed (TuanVM)
18.7 KB
Binary file not shown.

‎[LAB211] OOP with Java Lab/PASSED/J1.L.P0021/J1.L.P0021.txt‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
LAB211 AssignmentType:Long AssignmentCode:J1.L.P0021LOC:350Slot(s):5
3+
Title
4+
Create a Java console program to manage students.
5+
Background Context
6+
Write a program to manage information of student. The program implements terminology of Object Oriented Programming (OOP) paradigm. OOP is one of the best choosing ways to design software program.
7+
In this assignment, we will use ArrayList to store list of student. In fact, ArrayList is popular used to manipulate with data. ArrayList provides some useful methods, such as: add(), remove(), sort() ., etc.
8+
9+
10+
Program Specifications
11+
A student information consists of ID, Student Name, Semester, Course Name (There are only three courses: Java, .Net, C/C++). The program allows use to create list of student, update/delete student information. On the other hand, use can search student(s) and sort result by student name
12+
13+
1. Main Screen as below:
14+
15+
WELCOME TO STUDENT MANAGEMENT
16+
1. Create
17+
2. Find and Sort
18+
3. Update/Delete
19+
4. Report
20+
5. Exit
21+
(Please choose 1 to Create, 2 to Find and Sort, 3 to Update/Delete, 4 to Report and 5 to Exit program).
22+
2. Function details:
23+
There are 4 functions in Student Management Screen, as bellow:
24+
1. Create: user creates student by inputting information from keyboard. Use has to create at least 10 students, if number of students greater than 10, the program shows a message: Do you want to continue (Y/N)? Choose Y to continue, N to return main screen.
25+
2. Find/Sort: Find and list student (by name) and sort by name, it should display: Student name, semester and Course Name. User inputs student name or a part of student name.
26+
3. Update/Delete: The program allows user find a student by ID. After finding a student by Id, a question is displayed (Do you want to update (U) or delete (D) student. If user chooses U, the program allows user updating. Choose D for deleting student.
27+
4. Report: write a function to display student(s) with total Courses of this student, as: Student name, Course and Total of Course, for example:
28+
29+
30+
31+
Student nameCourseNguyen Van AJavaNguyen Van AJavaNguyen Van B.NetNguyen Van BJava
32+
The report as below:
33+
Nguyen Van A | Java | 2
34+
Nguyen Van B | Java | 1
35+
Nguyen Van C | Java | 1
36+
Technical Requirements
37+
1. Using Object-Oriented programming style
38+
2. Use only core Java functions and classes.
39+
40+
Guidelines
41+
42+
SlotTaskDescription1- Code Design
43+
- Create studentStudent should create a Student class with attributes: id, studentName, semester and courseName2- Find and sort studentShould Collections.sort() and overwrite compare() method in Comparator interface3- Update/Delete student4- Report5- Review programMentor reviews student�s program.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
import java.util.ArrayList;
3+
4+
/**
5+
*
6+
* @author THAYCACAC
7+
*/
8+
public class Main {
9+
10+
public static void main(String[] args) {
11+
ArrayList<Student> ls = new ArrayList<>();
12+
Validation validation = new Validation();
13+
ls.add(new Student("1", "Pham Ngoc Hoa", "Spring", "java"));
14+
ls.add(new Student("2", "Do Quang Hiep", "Summer", ".net"));
15+
ls.add(new Student("3", "Nguyen Xuan Cuong", "Spring", "c/c++"));
16+
int count = 3;
17+
//loop until user want to exit program
18+
while (true) {
19+
//Show menu option
20+
Manager.menu();
21+
int choice = validation.checkInputIntLimit(1, 5);
22+
switch (choice) {
23+
case 1:
24+
Manager.createStudent(count, ls);
25+
break;
26+
case 2:
27+
Manager.findAndSort(ls);
28+
break;
29+
case 3:
30+
Manager.updateOrDelete(count, ls);
31+
break;
32+
case 4:
33+
Manager.report(ls);
34+
break;
35+
case 5:
36+
return;
37+
}
38+
39+
}
40+
}
41+
42+
}
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
2+
import java.util.ArrayList;
3+
import java.util.Collections;
4+
5+
/**
6+
*
7+
* @author THAYCACAC
8+
*/
9+
public class Manager {
10+
11+
//Show menu
12+
public static void menu() {
13+
System.out.println(" 1. Create");
14+
System.out.println(" 2. Find and Sort");
15+
System.out.println(" 3. Update/Delete");
16+
System.out.println(" 4. Report");
17+
System.out.println(" 5. Exit");
18+
System.out.print(" Enter your choice: ");
19+
}
20+
21+
//Allow user create new student
22+
public static void createStudent(int count, ArrayList<Student> ls) {
23+
//if number of students greater than 10 ask user continue or not
24+
if (count > 10) {
25+
System.out.print("Do you want to continue (Y/N): ");
26+
if (!Validation.checkInputYN()) {
27+
return;
28+
}
29+
}
30+
//loop until user input not duplicate
31+
while (true) {
32+
System.out.print("Enter id: ");
33+
String id = Validation.checkInputString();
34+
System.out.print("Enter name student: ");
35+
String name = Validation.checkInputString();
36+
if (!Validation.checkIdExist(ls, id, name)) {
37+
System.err.println("Id has exist student. Pleas re-input.");
38+
continue;
39+
}
40+
System.out.print("Enter semester: ");
41+
String semester = Validation.checkInputString();
42+
System.out.print("Enter name course: ");
43+
String course = Validation.checkInputCourse();
44+
//check student exist or not
45+
if (Validation.checkStudentExist(ls, id, name, semester, course)) {
46+
ls.add(new Student(id, name, semester, course));
47+
count++;
48+
System.out.println("Add student success.");
49+
return;
50+
}
51+
System.err.println("Duplicate.");
52+
53+
}
54+
}
55+
//Allow user create find and sort
56+
57+
public static void findAndSort(ArrayList<Student> ls) {
58+
//check list empty
59+
if (ls.isEmpty()) {
60+
System.err.println("List empty.");
61+
return;
62+
}
63+
ArrayList<Student> listStudentFindByName = listStudentFindByName(ls);
64+
if (listStudentFindByName.isEmpty()) {
65+
System.err.println("Not exist.");
66+
} else {
67+
Collections.sort(listStudentFindByName);
68+
System.out.printf("%-15s%-15s%-15s\n", "Student name", "semester", "Course Name");
69+
//loop from first to last element of list student
70+
for (Student student : listStudentFindByName) {
71+
student.print();
72+
}
73+
}
74+
}
75+
76+
//List student found by name
77+
public static ArrayList<Student> listStudentFindByName(ArrayList<Student> ls) {
78+
ArrayList<Student> listStudentFindByName = new ArrayList<>();
79+
System.out.print("Enter name to search: ");
80+
String name = Validation.checkInputString();
81+
for (Student student : ls) {
82+
//check student have name contains input
83+
if (student.getStudentName().contains(name)) {
84+
listStudentFindByName.add(student);
85+
}
86+
}
87+
return listStudentFindByName;
88+
}
89+
90+
//Allow user update and delete
91+
public static void updateOrDelete(int count, ArrayList<Student> ls) {
92+
//if list empty
93+
if (ls.isEmpty()) {
94+
System.err.println("List empty.");
95+
return;
96+
}
97+
System.out.print("Enter id: ");
98+
String id = Validation.checkInputString();
99+
ArrayList<Student> listStudentFindByName = getListStudentById(ls, id);
100+
//check list empty
101+
if (listStudentFindByName.isEmpty()) {
102+
System.err.println("Not found student.");
103+
return;
104+
} else {
105+
Student student = getStudentByListFound(listStudentFindByName);
106+
System.out.print("Do you want to update (U) or delete (D) student: ");
107+
//check user want to update or delete
108+
if (Validation.checkInputUD()) {
109+
System.out.print("Enter name student: ");
110+
String name = Validation.checkInputString();
111+
System.out.print("Enter semester: ");
112+
String semester = Validation.checkInputString();
113+
System.out.print("Enter name course: ");
114+
String course = Validation.checkInputCourse();
115+
//check student exist or not
116+
if (Validation.checkStudentExist(ls, id, name, semester, course)) {
117+
student.setStudentName(name);
118+
student.setSemester(semester);
119+
student.setCourseName(course);
120+
System.err.println("Update success.");
121+
}
122+
return;
123+
} else {
124+
ls.remove(student);
125+
count--;
126+
System.err.println("Delete success.");
127+
return;
128+
}
129+
}
130+
}
131+
132+
//Get student user want to update/delete in list found
133+
public static Student getStudentByListFound(ArrayList<Student> listStudentFindByName) {
134+
System.out.println("List student found: ");
135+
int count = 1;
136+
System.out.printf("%-10s%-15s%-15s%-15s\n", "Number", "Student name",
137+
"semester", "Course Name");
138+
//display list student found
139+
for (Student student : listStudentFindByName) {
140+
System.out.printf("%-10d%-15s%-15s%-15s\n", count,
141+
student.getStudentName(), student.getSemester(),
142+
student.getCourseName());
143+
count++;
144+
}
145+
System.out.print("Enter student: ");
146+
int choice = Validation.checkInputIntLimit(1, listStudentFindByName.size());
147+
return listStudentFindByName.get(choice - 1);
148+
}
149+
150+
//Get list student find by id
151+
public static ArrayList<Student> getListStudentById(ArrayList<Student> ls, String id) {
152+
ArrayList<Student> getListStudentById = new ArrayList<>();
153+
for (Student student : ls) {
154+
if (id.equalsIgnoreCase(student.getId())) {
155+
getListStudentById.add(student);
156+
}
157+
}
158+
return getListStudentById;
159+
}
160+
161+
//Print report
162+
public static void report(ArrayList<Student> ls) {
163+
if (ls.isEmpty()) {
164+
System.err.println("List empty.");
165+
return;
166+
}
167+
ArrayList<Report> lr = new ArrayList<>();
168+
int size = ls.size();
169+
for (int i = 0; i < size; i++) {
170+
int total = 0;
171+
for (Student student1 : ls) {
172+
for (Student student2 : ls) {
173+
if (student1.getId().equalsIgnoreCase(student2.getId())
174+
&& student1.getCourseName().equalsIgnoreCase(student2.getCourseName())) {
175+
total++;
176+
}
177+
}
178+
if (Validation.checkReportExist(lr, student1.getStudentName(),
179+
student1.getCourseName(), total)) {
180+
lr.add(new Report(student1.getStudentName(),
181+
student1.getCourseName(), total));
182+
}
183+
}
184+
}
185+
//print report
186+
for (int i = 0; i < lr.size(); i++) {
187+
System.out.printf("%-15s|%-10s|%-5d\n", lr.get(i).getStudentName(),
188+
lr.get(i).getCourseName(), lr.get(i).getTotalCourse());
189+
}
190+
}
191+
}

0 commit comments

Comments
 (0)