Skip to content
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
**/*.class
**/*.class
/mod4/FirstMavenProject/target/
1 change: 1 addition & 0 deletions console.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
select * from Book
Binary file added mod2/Class roster/Class roster.jar
Binary file not shown.
11 changes: 11 additions & 0 deletions mod2/Class roster/audit.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
2022-05-09T20:00:54.681710 : Student 1111 CREATED.
2022-05-10T08:32:30.927770 : ||||||||||||||| Sucesfull: start runing program |||||||||||||||
2022-05-10T08:32:54.832127 : Student 1111 REMOVED.
2022-05-10T08:47:44.467095 : ||||||||||||||| Sucesfull: start runing program |||||||||||||||
2022-05-10T08:48:25.732196 : Student 1111 REMOVED.
2022-05-10T08:49:19.643601 : Student 1112 CREATED.
2022-05-10T08:49:26.906286 : Student 1111 REMOVED.
2022-05-10T08:49:37.850037 : ||||||||||||||| Sucesfull: stop program |||||||||||||||
2022-05-11T10:36:21.716903 : ||||||||||||||| Sucesfull: start runing program |||||||||||||||
2022-05-11T10:36:34.449032 : Student 1111 REMOVED.
2022-05-11T10:36:43.859600 : ||||||||||||||| Sucesfull: stop program |||||||||||||||
1 change: 1 addition & 0 deletions mod2/Class roster/roster.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1112::bhima::raisz::java 2021-2025
29 changes: 29 additions & 0 deletions mod2/Class roster/src/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import IO.ClassRosterView;
import IO.Console;
import audit.ClassRosterAuditDaoFileImpl;
import controller.ClassRosterControl;
import dao.ClassRosterDaoFileImpl;
import interfaces.ClassRosterAuditDao;
import interfaces.ClassRosterDao;
import interfaces.ClassRosterServiceLayer;
import interfaces.ConsoleIo;
import serviceLayer.ClassRosterServiceLayerFileImpl;

public class App {
public static void main(String[] args) throws Exception {
// Instantiate the UserIO implementation
ConsoleIo myIo = new Console();
// Instantiate the View and wire the UserIO implementation into it
ClassRosterView myView = new ClassRosterView(myIo);
// Instantiate the DAO
ClassRosterDao myDao = new ClassRosterDaoFileImpl();
// Instantiate the Audit DAO
ClassRosterAuditDao myAuditDao = new ClassRosterAuditDaoFileImpl();
// Instantiate the Service Layer and wire the DAO and Audit DAO into it
ClassRosterServiceLayer myService = new ClassRosterServiceLayerFileImpl(myDao, myAuditDao);
// Instantiate the Controller and wire the Service Layer into it
ClassRosterControl controller = new ClassRosterControl(myService, myView);
// Kick off the Controller
controller.run();
}
}
100 changes: 100 additions & 0 deletions mod2/Class roster/src/IO/ClassRosterView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package IO;

import java.util.List;

import interfaces.ConsoleIo;
import model.Student;

public class ClassRosterView {
ConsoleIo io;

public ClassRosterView(ConsoleIo io) {
this.io = io;
}

public int printMenuAndGetSelection() {
io.print("Main Menu");
io.print("1. List Student IDs");
io.print("2. Create New Student");
io.print("3. View a Student");
io.print("4. Remove a Student");
io.print("5. Exit");

return io.readInt("Please select from the above choices.", 1, 5);
}

public Student getNewStudentInfo() {
String studentId = io.readString("Please enter Student ID");
String firstName = io.readString("Please enter First Name");
String lastName = io.readString("Please enter Last Name");
String cohort = io.readString("Please enter Cohort");
Student currentStudent = new Student(studentId);
currentStudent.setFirstName(firstName);
currentStudent.setLastName(lastName);
currentStudent.setCohort(cohort);
return currentStudent;
}

public void displayCreateStudentBanner() {
io.print("=== Create Student ===");
}

public void displayCreateSuccessBanner() {
io.readString(
"Student successfully created. Please hit enter to continue");
}

public void displayStudentList(List<Student> studentList) {
for (Student currentStudent : studentList) {
io.print(currentStudent.getStudentId() + ": "
+ currentStudent.getFirstName() + " "
+ currentStudent.getLastName());
}
io.readString("Please hit enter to continue.");
}

public void displayDisplayAllBanner() {
io.print("=== Display All Students ===");
}

public void displayDisplayStudentBanner() {
io.print("=== Display Student ===");
}

public String getStudentIdChoice() {
return io.readString("Please enter the Student ID.");
}

public void displayStudent(Student student) {
if (student != null) {
io.print(student.getStudentId());
io.print(student.getFirstName() + " " + student.getLastName());
io.print(student.getCohort());
io.print("");
} else {
io.print("No such student.");
}
io.readString("Please hit enter to continue.");
}

public void displayRemoveStudentBanner() {
io.print("=== Remove Student ===");
}

public void displayRemoveSuccessBanner() {
io.readString("Student successfully removed. Please hit enter to continue.");
}

public void displayExitBanner() {
io.print("Good Bye!!!");
}

public void displayUnknownCommandBanner() {
io.print("Unknown Command!!!");
}

public void displayErrorMessage(String errorMsg) {
io.print("=== ERROR ===");
io.print(errorMsg);
}
}
173 changes: 173 additions & 0 deletions mod2/Class roster/src/IO/Console.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
package IO;

import java.util.Scanner;

import interfaces.ConsoleIo;

public class Console implements ConsoleIo {
private Scanner sc = new Scanner(System.in);

@Override
public int readInt(String prompt) {
boolean isCorrect = false;
int value = 0;
String userInput;
while (!isCorrect) {
userInput = this.readString(prompt);
try {
value = Integer.parseInt(userInput);
isCorrect = true;
} catch (Exception e) {
this.print("that was not a number please try again");
}
}
return value;
}

@Override
public int readInt(String prompt, int min, int max) {
boolean isCorrect = false;
int value;
do {
value = this.readInt(prompt);
if (value > max) {
this.print("that number was to high");
} else if (value < min) {
this.print("that number was to low");
} else {
isCorrect = true;
}
} while (!isCorrect);
return value;
}

@Override
public float readFloat(String prompt) {
boolean isCorrect = false;
float value = 0;
String userInput;
while (!isCorrect) {
userInput = this.readString(prompt);
try {
value = Float.parseFloat(userInput);
isCorrect = true;
} catch (Exception e) {
this.print("that was not a number please try again");
}
}
return value;
}

@Override
public float readFloat(String prompt, float min, float max) {
boolean isCorrect = false;
float value;
do {
value = this.readFloat(prompt);
if (value > max) {
this.print("that number was to high");
} else if (value < min) {
this.print("that number was to low");
} else {
isCorrect = true;
}
} while (!isCorrect);
return value;
}

@Override
public double readDouble(String prompt) {
boolean isCorrect = false;
double value = 0;
String userInput;
while (!isCorrect) {
userInput = this.readString(prompt);
try {
value = Double.parseDouble(userInput);
isCorrect = true;
} catch (Exception e) {
this.print("That was not a double. Please try again");
}
}
return value;
}

@Override
public double readDouble(String prompt, Double min, Double max) {
boolean isCorrect = false;
double value;
do {
value = this.readDouble(prompt);
if (value > max) {
this.print("that number was to high");
} else if (value < min) {
this.print("that number was to low");
} else {
isCorrect = true;
}
} while (!isCorrect);
return value;
}

@Override
public boolean readboolean(String prompt) {
boolean isCorrect = false;
boolean value = false;
String userInput;
while (!isCorrect) {
userInput = this.readString(prompt);
try {
value = Boolean.parseBoolean(userInput);
isCorrect = true;
} catch (Exception e) {
this.print("That was not a boolean. Please try again");
}
}
return value;
}

@Override
public long readLong(String prompt) {
boolean isCorrect = false;
String userInput;
long value = 0;
while (!isCorrect) {
userInput = this.readString(prompt);
try {
value = Long.parseLong(userInput);
isCorrect = true;
} catch (Exception e) {
this.print("That was not a double. Please try again");
}
}
return value;
}

public long readLong(String prompt, long min, long max) {
boolean isCorrect = false;
long value;
do {
value = this.readLong(prompt);
if (value > max) {
this.print("that number was to high");
} else if (value < min) {
this.print("that number was to low");
} else {
isCorrect = true;
}
} while (!isCorrect);
return value;
}

@Override
public String readString(String prompt) {
this.print(prompt);
return this.sc.nextLine();
}

@Override
public void print(String msg) {
System.out.println(msg);

}
}
30 changes: 30 additions & 0 deletions mod2/Class roster/src/audit/ClassRosterAuditDaoFileImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package audit;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.time.LocalDateTime;

import exceptions.ClassRosterPersistenceException;
import interfaces.ClassRosterAuditDao;

public class ClassRosterAuditDaoFileImpl implements ClassRosterAuditDao {

public static final String AUDIT_FILE = "audit.txt";

@Override
public void writeAuditEntry(String entry) throws ClassRosterPersistenceException {
PrintWriter out;

try {
out = new PrintWriter(new FileWriter(AUDIT_FILE, true));
} catch (IOException e) {
throw new ClassRosterPersistenceException("Could not persist audit information.", e);
}

LocalDateTime timestamp = LocalDateTime.now();
out.println(timestamp.toString() + " : " + entry);
out.flush();
}

}
Loading