-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudents.java
More file actions
117 lines (95 loc) · 3.33 KB
/
Copy pathStudents.java
File metadata and controls
117 lines (95 loc) · 3.33 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import java.util.Scanner;
public class students {
Scanner input = new Scanner(System.in);
student theStudents[] = new student[50];
public static int count = 0;
public void addStudent(student s)
{
for (int i = 0; i < count; i++) {
if (s.regNum.equalsIgnoreCase(theStudents[i].regNum)) {
System.out.println("Student of Reg Num " + s.regNum + " is Already Registered.");
return;
}
}
if (count <= 50) {
theStudents[count] = s;
count++;
}
}
public void showAllStudents()
{
System.out.println("Student Name\t\tReg Number");
for (int i = 0; i < count; i++) {
System.out.println(theStudents[i].studentName+ "\t\t"+ theStudents[i].regNum);
}
}
public int isStudent()
{
System.out.println("Enter Reg Number:");
String regNum = input.nextLine();
for (int i = 0; i < count; i++) {
if (theStudents[i].regNum.equalsIgnoreCase(regNum)) {
return i;
}
}
System.out.println("Student is not Registered.");
System.out.println("Get Registered First.");
return -1;
}
public void checkOutBook(books book)
{
int studentIndex = this.isStudent();
if (studentIndex != -1) {
System.out.println("checking out");
book.showAllBooks();
book b = book.checkOutBook();
System.out.println("checking out");
if (b != null) {
if (theStudents[studentIndex].booksCount
<= 3) {
System.out.println("adding book");
theStudents[studentIndex].borrowedBooks
[theStudents[studentIndex]
.booksCount]
= b;
theStudents[studentIndex].booksCount++;
return;
}
else {
System.out.println(
"Student Can not Borrow more than 3 Books.");
return;
}
}
System.out.println("Book is not Available.");
}
}
public void checkInBook(books book)
{
int studentIndex = this.isStudent();
if (studentIndex != -1) {
// Printing credentials corresponding to student
System.out.println(
"S.No\t\t\tBook Name\t\t\tAuthor Name");
student s = theStudents[studentIndex];
for (int i = 0; i < s.booksCount; i++) {
System.out.println(
s.borrowedBooks[i].sNo + "\t\t\t"
+ s.borrowedBooks[i].bookName + "\t\t\t"
+ s.borrowedBooks[i].authorName);
}
System.out.println(
"Enter Serial Number of Book to be Checked In:");
int sNo = input.nextInt();
for (int i = 0; i < s.booksCount; i++) {
if (sNo == s.borrowedBooks[i].sNo) {
book.checkInBook(s.borrowedBooks[i]);
s.borrowedBooks[i] = null;
return;
}
}
System.out.println("Book of Serial No " + sNo
+ "not Found");
}
}
}