Initial Commit

This commit is contained in:
2022-10-07 00:22:46 -03:00
commit bdcf6d3e1c
465 changed files with 15466 additions and 0 deletions

View File

@@ -0,0 +1,73 @@
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
/**
* Decodes encrypted text in a specific format
* @author Isaac Shoebottom (3429069)
*/
public class Decoder {
public static void main(String[] args) throws FileNotFoundException {
Scanner scanFile = new Scanner(new File(args[0]));
int cycleCount = 0;
scanFile.useDelimiter("\\A");
String in = scanFile.next();
String[] codes = in.split("\\r?\\n");
for (String i: codes) {
if (i.length() > 1) {
int columns = Integer.parseInt(codes[cycleCount * 2]);
int rows = codes[cycleCount * 2 + 1].length() / columns;
char[][] decode = new char[rows][columns];
char[] chars = i.toCharArray();
int charCounter = 0;
for (int k = 0; k < columns; k++) {
if (k % 2 != 0) {
for (int j = 0; j < rows; j++) {
decode[j][k] = chars[charCounter];
charCounter++;
}
}
else {
for (int j = rows - 1; j > -1; j--) {
decode[j][k] = chars[charCounter];
charCounter++;
}
}
}
charCounter = 0;
char[] decodedChar = new char[i.length()];
for (int j = 0; j < rows; j++) {
if (j % 2 == 0) {
for (int k = 0; k < columns; k++) {
decodedChar[charCounter] = decode[j][k];
charCounter++;
}
}
else {
for (int k = columns - 1; k > -1; k--) {
decodedChar[charCounter] = decode[j][k];
charCounter++;
}
}
}
cycleCount++;
String output = String.valueOf(decodedChar);
System.out.println(output);
}
else if (i.equals("0")) {
break;
}
}
}
}

View File

@@ -0,0 +1,6 @@
findthesecretdecoderringx
watchoutfordrevilheisplanninganattackxy
ourcshouseismeetingonteamsatnoontoworkonthepuzzleproblem
everyoneyoumeetknowssomethingyoudonotxxx
thecompanybidonemillionontheprojectx
yourinformantwillbewearingaredcoat

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

View File

@@ -0,0 +1,47 @@
/**
* This class holds info for the lent item
* @author Isaac Shoebottom (3429069)
*/
public class LendingItem {
private final String description;
private final double price;
private final boolean recommended;
/**
* Constructor for items
* @param description Description of item
* @param price The price of the item
* @param recommended If the item is recommended or not
*/
public LendingItem(String description, double price, boolean recommended) {
this.description = description;
this.price = price;
this.recommended = recommended;
}
/**
* Gets the description of item
* @return The item description
*/
public String getDescription() {
return description;
}
/**
* Gets the price of the item
* @return The price of the item
*/
public double getPrice() {
return price;
}
/**
* Gets if the item is recommended by the book club
* @return Boolean of if the item is recommended by the book club
*/
public boolean isBookClubRecommended() {
return recommended;
}
}

View File

@@ -0,0 +1,76 @@
*** Test case #1: Create a Tenant object & test accessors
Name: Maria Melani
Appt #: 152
Phone: 555-1234
Member #: 10000
Correct result: Maria has zero lending items.
*** Test case #2: Create a ShortTermResidentMember object & test accessors
Name: Tommy Black
Appt #: 302
Phone: 555-4321
Member #: 10001
Departs: Dec. 15, 2020
Correct result: Tommy has zero lending items.
*** Test case #3: Automatically generate a member number
Correct result: 10002 is the correct member number.
*** Test case #4: Create a LendingItem object & test accessors
Description: Lean In - Sheryl Sandberg - BOOK
Orig. Price: $10.00
Book Club Recommended: true
*** Test case #5: Change phone number for both Resident types
Correct result: Maria's phone number successfully changed.
Correct result: Tommy's phone number successfully changed.
*** Test case #6: Sign out one LendingItem
Correct result: Maria signed out an item successfully.
Correct result: Maria has one lending item.
*** Test case #7: Sign out multiple LendingItems
Correct result: Maria signed out two more items successfully.
Correct result: Maria has three lending items.
*** Test case #8: Intentionally exceed the sign out limit
Correct result: Maria was prevented from signing out more than 8 lending items.
*** Test case #9: A short-term resident tries to sign out a recommended item
>> ERROR: Tommy was able to sign out a book club recommended item.
>> ERROR: Tommy was prevented from signing out a non recommended item.
*** Test case #10: Returning the only item that was signed out
Correct result: Tommy's item was successfully returned.
Correct result: Tommy's list length changed appropriately.
*** Test case #11: Returning an item that was not signed out
Correct result: Unsuccessful attempt to return an item that was not signed out.
*** Test case #12: Returning the first item that was signed out
Correct result: Maria's first item was successfully returned.
Correct result: Maria's list length changed appropriately.
Confirm return: Lean In should be absent from the following list:
Yoga Journal - October 2020 - MAGAZINE
Maclean's - 23/11/2020 - MAGAZINE
Headstrong: 52 Women Who Changed Science and the World - Rachel Swaby - BOOK
The Time Machine - H.G. Wells - BOOK
The Confidence Code - Katty Kay & Claire Shipman - BOOK
The Immortal Life of Henrietta Lacks - Rebecca Skloot - BOOK
Grit - Angela Duckworth - BOOK
*** Test case #13: Returning a mid-list item
Correct result: The Time Machine was successfully returned.
Correct result: Maria's list length changed appropriately.
Confirm return: The Time Machine should be absent from the following list:
Yoga Journal - October 2020 - MAGAZINE
Maclean's - 23/11/2020 - MAGAZINE
Headstrong: 52 Women Who Changed Science and the World - Rachel Swaby - BOOK
Grit - Angela Duckworth - BOOK
The Confidence Code - Katty Kay & Claire Shipman - BOOK
The Immortal Life of Henrietta Lacks - Rebecca Skloot - BOOK
************* End of Test Cases ***************

View File

@@ -0,0 +1,113 @@
/**
* This class holds info for members
* @author Isaac Shoebottom (3429069)
*/
public class ResidentMember {
private static int membership = 9999;
private final String name;
private final int room;
private final LendingItem[] list;
private String phone;
private int bookCounter;
/**
* Constructor for members
* @param name Name of member
* @param room Room of member
* @param phone Phone of member
*/
public ResidentMember(String name, int room, String phone) {
this.name = name;
this.room = room;
this.phone = phone;
list = new LendingItem[8];
bookCounter = 0;
membership++;
}
/**
* Get the signed out items of a member
* @return The updated list item list
*/
public LendingItem[] getSignedOutItems() {
LendingItem[] updatedItemList = new LendingItem[bookCounter];
for (int i = 0; i < bookCounter; i++) {
updatedItemList[i] = list[i];
}
return updatedItemList;
}
/**
* Method to sign out items for members
* @param input The item to be lent
* @return Boolean for if the item was signed out or not
*/
public boolean signOut(LendingItem input) {
if (bookCounter < 8) {
list[bookCounter] = input;
bookCounter++;
return true;
}
return false;
}
/**
* Returns and item for members
* @param input The item to be returned
* @return Boolean if the item was returned
*/
public boolean returnItem(LendingItem input) {
boolean success = false;
for (int i = 0; i < bookCounter; i++) {
if (list[i] == input) {
list[i] = list[bookCounter - 1];
bookCounter--;
success = true;
}
}
return success;
}
/**
* Gets the name of member
* @return The name of member
*/
public String getName() {
return name;
}
/**
* Gets the room of member
* @return The room of member
*/
public int getRoomNumber() {
return room;
}
/**
* Gets the phone number of member
* @return The phone number of member
*/
public String getPhoneNumber() {
return phone;
}
/**
* Sets the phone of member
* @param phone
*/
public void setPhoneNumber(String phone) {
this.phone = phone;
}
/**
* Gets the membership number of member
* @return The membership number of member
*/
public int getMembershipNumber() {
return membership;
}
}

View File

@@ -0,0 +1,43 @@
/**
* This class holds info for short term members
* @author Isaac Shoebottom (3429069)
*/
public class ShortTermResidentMember extends ResidentMember {
private final String departureDate;
/**
* Constructor for short term members
* @param name Name of short term member
* @param room Room of short term member
* @param phone Phone of short term member
* @param departureDate The departure date of short term members
*/
public ShortTermResidentMember(String name, int room, String phone, String departureDate) {
super(name, room, phone);
this.departureDate = departureDate;
}
/**
* Method to sign out items for short term members
* @param input The item to be signed out
* @return Boolean for if the item was signed out or not
*/
public boolean signOut(LendingItem input) {
if (input.isBookClubRecommended()) {
super.signOut(input);
return true;
}
return false;
}
/**
* Gets the departure date for short term members
* @return The departure date
*/
public String getDepartureDate() {
return departureDate;
}
}

Binary file not shown.

View File

@@ -0,0 +1,298 @@
import java.text.NumberFormat;
/**
Test driver class to test the ResidentMember, ShortTermResidentMember
and LendingItem classes.
*/
public class LendingLibraryTestDriver {
public static void main(String[] args) {
NumberFormat formatter = NumberFormat.getCurrencyInstance();
//*********************************************************************************
System.out.println("\n*** Test case #1: Create a Tenant object & test accessors");
ResidentMember maria = new ResidentMember("Maria Melani", 152,"555-1234");
System.out.println("Name: " + maria.getName()
+ "\nAppt #: " + maria.getRoomNumber()
+ "\nPhone: " + maria.getPhoneNumber()
+ "\nMember #: " + maria.getMembershipNumber());
LendingItem[] mariasItemList = maria.getSignedOutItems();
if (mariasItemList.length == 0) {
System.out.println("Correct result: Maria has zero lending items.");
}
else {
System.out.println(">> ERROR: Maria has more than zero lending items.");
}
//*********************************************************************************
System.out.println
("\n*** Test case #2: Create a ShortTermResidentMember object & test accessors");
ShortTermResidentMember tommy = new ShortTermResidentMember("Tommy Black",
302,
"555-4321",
"Dec. 15, 2020");
System.out.println("Name: " + tommy.getName()
+ "\nAppt #: " + tommy.getRoomNumber()
+ "\nPhone: " + tommy.getPhoneNumber()
+ "\nMember #: " + tommy.getMembershipNumber()
+ "\nDeparts: " + tommy.getDepartureDate());
LendingItem[] tommysItemList = tommy.getSignedOutItems();
if (tommysItemList.length == 0) {
System.out.println("Correct result: Tommy has zero lending items.");
}
else {
System.out.println(">> ERROR: Tommy has more than zero lending items.");
}
//*********************************************************************************
System.out.println("\n*** Test case #3: Automatically generate a member number");
ResidentMember testMember = new ResidentMember("Test", 1, "455-1111");
if (testMember.getMembershipNumber() == 10002) {
System.out.println("Correct result: 10002 is the correct member number.");
}
else {
System.out.println(">> ERROR: Invalid member number: " +
testMember.getMembershipNumber());
}
//*********************************************************************************
System.out.println
("\n*** Test case #4: Create a LendingItem object & test accessors");
// Create several LendingItem objects and test the first one
final int MAXITEMS = 8;
LendingItem[] testItemList = new LendingItem[MAXITEMS + 1];
String[] testItemDescription = {"Lean In - Sheryl Sandberg - BOOK",
"Maclean's - 23/11/2020 - MAGAZINE",
"Headstrong: 52 Women Who Changed Science and the World - Rachel Swaby - BOOK",
"The Time Machine - H.G. Wells - BOOK",
"The Confidence Code - Katty Kay & Claire Shipman - BOOK",
"The Immortal Life of Henrietta Lacks - Rebecca Skloot - BOOK",
"Grit - Angela Duckworth - BOOK",
"Yoga Journal - October 2020 - MAGAZINE",
"Wild - Cheryl Strayed - BOOK"};
for (int i=0; i<=MAXITEMS; i++) {
testItemList[i] = new LendingItem(testItemDescription[i],
10.00 + (i * 0.25), // Made-up prices
(i%2) == 0); // Every 2nd item is recommended
} // end for loop
System.out.println("Description: " + testItemList[0].getDescription()
+ "\nOrig. Price: " + formatter.format(testItemList[0].getPrice())
+ "\nBook Club Recommended: " + testItemList[0].isBookClubRecommended());
//*********************************************************************************
System.out.println("\n*** Test case #5: Change phone number for both Resident types");
String testPhone1 = "555-5566";
String testPhone2 = "555-1212";
maria.setPhoneNumber(testPhone1);
tommy.setPhoneNumber(testPhone2);
if (maria.getPhoneNumber().equals(testPhone1)) {
System.out.println("Correct result: Maria's phone number successfully changed.");
}
else {
System.out.println(">> ERROR: Maria's phone number is incorrect: "
+ maria.getPhoneNumber());
}
if (tommy.getPhoneNumber().equals(testPhone2)) {
System.out.println("Correct result: Tommy's phone number successfully changed.");
}
else {
System.out.println(">> ERROR: Tommy's phone number is incorrect: "
+ tommy.getPhoneNumber());
}
//*********************************************************************************
System.out.println("\n*** Test case #6: Sign out one LendingItem");
if(maria.signOut(testItemList[0])) {
System.out.println("Correct result: Maria signed out an item successfully.");
mariasItemList = maria.getSignedOutItems();
if (mariasItemList.length == 1) {
System.out.println("Correct result: Maria has one lending item.");
}
else {
System.out.println(">> ERROR: Maria has other than one lending item.");
}
}
else {
System.out.println(">> ERROR: Maria was unable to sign out an item.");
}
//*********************************************************************************
System.out.println("\n*** Test case #7: Sign out multiple LendingItems");
boolean successfulSignOut = true;
for(int i=1; i<=2; i++) {
successfulSignOut = successfulSignOut && maria.signOut(testItemList[i]);
}
if (successfulSignOut) {
System.out.println("Correct result: Maria signed out two more items successfully.");
mariasItemList = maria.getSignedOutItems();
if (mariasItemList.length == 3) {
System.out.println("Correct result: Maria has three lending items.");
}
else {
System.out.println(">> ERROR: Maria has other than three lending items.");
}
}
else {
System.out.println(">> ERROR: Maria was unable to sign out two more items.");
}
//*********************************************************************************
System.out.println("\n*** Test case #8: Intentionally exceed the sign out limit");
for(int i=3; i<MAXITEMS; i++) {
maria.signOut(testItemList[i]);
}
if (!maria.signOut(testItemList[MAXITEMS])) {
System.out.println("Correct result: Maria was prevented from signing out more than "
+ MAXITEMS + " lending items.");
}
else {
System.out.println(">> ERROR: Maria was able to sign out more than "
+ MAXITEMS + " lending items.");
}
//*********************************************************************************
System.out.println
("\n*** Test case #9: A short-term resident tries to sign out a recommended item");
LendingItem tommysItem = null;
for(int i=0; i<2; i++) {
if(tommy.signOut(testItemList[i])) {
tommysItem = testItemList[i]; // Remember this for Test case #10
if (testItemList[i].isBookClubRecommended()) {
System.out.println
(">> ERROR: Tommy was able to sign out a book club recommended item.");
}
else {
System.out.println
("Correct result: Tommy was able to sign out a non recommended item.");
}
}
else {
if (testItemList[i].isBookClubRecommended()) {
System.out.println
("Correct result: Tommy was prevented from signing out a recommended item.");
}
else {
System.out.println
(">> ERROR: Tommy was prevented from signing out a non recommended item.");
}
}
}//end for
//*********************************************************************************
System.out.println
("\n*** Test case #10: Returning the only item that was signed out");
int tommyListLength = tommy.getSignedOutItems().length;
if(tommy.returnItem(tommysItem)) {
System.out.println("Correct result: Tommy's item was successfully returned.");
}
else {
System.out.println(">> ERROR: Tommy's item was not successfully returned.");
}
if(tommy.getSignedOutItems().length == tommyListLength - 1) {
System.out.println("Correct result: Tommy's list length changed appropriately.");
}
else {
System.out.println(">> ERROR: Tommy's list length did not change appropriately.");
}
//*********************************************************************************
System.out.println("\n*** Test case #11: Returning an item that was not signed out");
if(tommy.returnItem(testItemList[3])) {
System.out.println(">> ERROR: Returned an item that was not signed out.");
}
else {
System.out.println
("Correct result: Unsuccessful attempt to return an item that was not signed out.");
}
//*********************************************************************************
System.out.println
("\n*** Test case #12: Returning the first item that was signed out");
int mariaListLength = maria.getSignedOutItems().length;
if(maria.returnItem(testItemList[0])) {
System.out.println("Correct result: Maria's first item was successfully returned.");
}
else {
System.out.println(">> ERROR: Maria's first item was not successfully returned.");
}
if(maria.getSignedOutItems().length == mariaListLength - 1) {
System.out.println("Correct result: Maria's list length changed appropriately.");
}
else {
System.out.println(">> ERROR: Maria's list length did not change appropriately.");
}
System.out.println
("\nConfirm return: Lean In should be absent from the following list:");
mariasItemList = maria.getSignedOutItems();
for (int i=0; i < mariasItemList.length; i++) {
System.out.println(mariasItemList[i].getDescription());
}
//*********************************************************************************
System.out.println("\n*** Test case #13: Returning a mid-list item");
mariaListLength = maria.getSignedOutItems().length;
if(maria.returnItem(testItemList[3])) {
System.out.println("Correct result: The Time Machine was successfully returned.");
}
else {
System.out.println(">> ERROR: The Time Machine was not successfully returned.");
}
if(maria.getSignedOutItems().length == mariaListLength - 1) {
System.out.println("Correct result: Maria's list length changed appropriately.");
}
else {
System.out.println(">> ERROR: Maria's list length did not change appropriately.");
}
System.out.println
("\nConfirm return: The Time Machine should be absent from the following list:");
mariasItemList = maria.getSignedOutItems();
for (int i=0; i < mariasItemList.length; i++) {
System.out.println(mariasItemList[i].getDescription());
}
//*********************************************************************************
System.out.println("\n************* End of Test Cases ***************\n");
} // end main method
} // end LendingTestDriver class

View File

@@ -0,0 +1,13 @@
5
rrrcfieeeindtsndedogxceht
3
kcnanaehrduowahtrelilngaaxyttnipsivofct
7
mehnteeoumtaotpelunosisrcinmnozbozktageshsoeorlrpeowtnuo
4
xdutenkyeevnotomhooxxnyioweuoerymessngot
6
xnodithbonttchonyecneieejplmaompilro
2
aoerniewlltnroiryounfmawibeargadct
0

Binary file not shown.