Skip to content

Commit

Permalink
Initial work on classes + methods
Browse files Browse the repository at this point in the history
  • Loading branch information
conor-walker committed Apr 10, 2021
1 parent 2f7db63 commit c9a3ec5
Show file tree
Hide file tree
Showing 17 changed files with 187 additions and 50 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea/workspace.xml
target
124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 0 additions & 29 deletions src/main/java/AllCustomers.java

This file was deleted.

1 change: 0 additions & 1 deletion src/main/java/Customer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ public class Customer {
private String lastName;
private String emailAddress;
private String password;
final public static String dataSourceName = "customer";

public Customer(String emailAddress, String firstName, String lastName, String password){
this.emailAddress = emailAddress;
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/Customers.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import java.util.List;

public interface Customers {
public List<Customer> getAllCustomers();
}
23 changes: 23 additions & 0 deletions src/main/java/CustomersFromFile.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import java.util.ArrayList;
import java.util.List;

public class CustomersFromFile implements Customers {
List<Customer> listOfCustomers = new ArrayList<>();

public List<Customer> getAllCustomers(){
ReadDelimitedFile readDelimitedFile = new ReadDelimitedFile();
List<String[]> fileData = readDelimitedFile.getFileData("customer.csv");
addToList(fileData);
return listOfCustomers;
}

private void addToList(List<String[]> customerList){
for(String[] customer : customerList){
listOfCustomers.add(arrayToCustomer(customer));
}
}

private Customer arrayToCustomer(String[] customerInfo){
return new Customer(customerInfo[0],customerInfo[1],customerInfo[2],customerInfo[3]);
}
}
11 changes: 11 additions & 0 deletions src/main/java/Display.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class Display {
public void mainMenu(){

}
public void displayItems(){

}
public void leaveStore(){

}
}
2 changes: 2 additions & 0 deletions src/main/java/Items.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
public class Items {
}
17 changes: 6 additions & 11 deletions src/main/java/LogIn.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ private String input(String message) {
return userInput.nextLine();
}

private String getPassword(String emailAddress){
AllCustomers allCustomers = new AllCustomers();
private String getPassword(String emailAddress) {
Customers allCustomers = new CustomersFromFile();
String password = "";
List<Customer> listOfCustomers = allCustomers.getListOfCustomers();
for (Customer customer :listOfCustomers){
if (customer.getEmailAddress().equals(emailAddress)){
List<Customer> listOfCustomers = allCustomers.getAllCustomers();
for (Customer customer : listOfCustomers) {
if (customer.getEmailAddress().equals(emailAddress)) {
password = customer.getPassword();
}
}
Expand All @@ -24,7 +24,7 @@ private String getPassword(String emailAddress){
public void logIn() {
String emailAddress = input("Enter email address");
String password = getPassword(emailAddress);
if (password == "") {
if (password.equals("")) {
System.out.println("You are not a user");
}
else if (password.equals(input("Enter password"))){
Expand All @@ -34,9 +34,4 @@ else if (password.equals(input("Enter password"))){
System.out.println("Wrong password, no second chances");
}
}

public static void main(String[] args){
LogIn logIn = new LogIn();
logIn.logIn();
}
}
8 changes: 8 additions & 0 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
public class Main {

public static void main(String[] args){
LogIn logIn = new LogIn();
logIn.logIn();
}

}
8 changes: 4 additions & 4 deletions src/main/java/ReadDelimitedFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

public class ReadDelimitedFile {

private String fileDelimitor = ",";
private String fileDelimiter = ",";
private String filePathPrefix = "src/main/resources/";

public void setFileDelimitor(String fileDelimitor){
this.fileDelimitor = fileDelimitor;
public void setFileDelimiter(String fileDelimiter){
this.fileDelimiter = fileDelimiter;
}

public List<String[]> getFileData(String fileName){
Expand All @@ -20,7 +20,7 @@ public List<String[]> getFileData(String fileName){
Scanner propertyReader = new Scanner(propertyFile);
while (propertyReader.hasNextLine()) {
String fileRow = propertyReader.nextLine();
fileData.add(fileRow.split(fileDelimitor));
fileData.add(fileRow.split(fileDelimiter));
}
propertyReader.close();
} catch (IOException e) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/customer.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
emailAddress,firstName,lastName,password
derek.somerville@glasgow.ac.uk,Derek,Somerville,1234
matthew.barr@glasgow.ac.uk,Matt,Barr,4321
e.kelly.1@research.gla.ac.uk,Ethan,Kelly,9876
e.kelly.1@research.gla.ac.uk,Ethan,Kelly,9876
2089327W@student.gla.ac.uk,Conor,Walker,password
Binary file removed target/classes/AllCustomers.class
Binary file not shown.
Binary file removed target/classes/Customer.class
Binary file not shown.
Binary file removed target/classes/LogIn.class
Binary file not shown.
Binary file removed target/classes/ReadDelimitedFile.class
Binary file not shown.
4 changes: 0 additions & 4 deletions target/classes/customer.csv

This file was deleted.

0 comments on commit c9a3ec5

Please sign in to comment.