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
8 changes: 8 additions & 0 deletions AhmedMostafaElgamal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
**Ahmed Mostafa Ibrahim Elgamal**
![my pic ahly ]https://scontent-hbe1-1.xx.fbcdn.net/v/t1.0-9/p960x960/58704175_2368633800041026_4402313844580417536_o.jpg?_nc_cat=105&_nc_sid=85a577&_nc_ohc=K-WtGmLQnkMAX_CA-ex&_nc_ht=scontent-hbe1-1.xx&_nc_tp=6&oh=b056f03a12268d7fb9a15e42f052ba5b&oe=5E9FE9FC)

**Section 1 3rd year CS dept **



![Egyptian club](https://banner2.cleanpng.com/20180418/vuq/kisspng-al-ahly-sc-dream-league-soccer-egypt-national-foot-saudi-arabia-5ad79f283835d6.2271766515240804242303.jpg)
192 changes: 96 additions & 96 deletions Project/OSTask1/src/CustomerManagerApp.java
Original file line number Diff line number Diff line change
@@ -1,96 +1,96 @@
import java.util.List;

public class CustomerManagerApp {

// declare class variables
private static DAO<Customer> customerDAO = null;

public static void main(String[] args) {
// display a welcome message
System.out.println("Welcome to the Customer Manager\n");

// set the class variables
customerDAO = new CustomerTextFile();

// display the command menu
displayMenu();

// perform 1 or more actions
String action = "";
while (!action.equalsIgnoreCase("exit")) {
// get the input from the user
action = Console.getString("Enter a command: ");
System.out.println();

if (action.equalsIgnoreCase("list")) {
displayAllCustomers();
} else if (action.equalsIgnoreCase("add")) {
addCustomer();
} else if (action.equalsIgnoreCase("del") || action.equalsIgnoreCase("delete")) {
deleteCustomer();
} else if (action.equalsIgnoreCase("help") || action.equalsIgnoreCase("menu")) {
displayMenu();
} else if (action.equalsIgnoreCase("exit")) {
System.out.println("Bye.\n");
} else {
System.out.println("Error! Not a valid command.\n");
}
}
}

public static void displayMenu() {
System.out.println("COMMAND MENU");
System.out.println("list - List all customers");
System.out.println("add - Add a customer");
System.out.println("del - Delete a customer");
System.out.println("help - Show this menu");
System.out.println("exit - Exit this application\n");
}

public static void displayAllCustomers() {
System.out.println("CUSTOMER LIST");

List<Customer> customers = customerDAO.getAll();
Customer c;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < customers.size(); i++) {
c = customers.get(i);
sb.append(StringUtils.padWithSpaces(
c.getName(), 27));
sb.append(c.getEmail());
sb.append("\n");
}
System.out.println(sb.toString());
}

public static void addCustomer() {
String firstName = Console.getLine("Enter first name: ");
String lastName = Console.getString("Enter last name: ");
String email = Console.getString("Enter customer email: ");

Customer customer = new Customer();
customer.setFirstName(firstName);
customer.setLastName(lastName);
customer.setEmail(email);
customerDAO.add(customer);

System.out.println();
System.out.println(firstName + " " + lastName
+ " has been added.\n");
}

public static void deleteCustomer() {
String email = Console.getString("Enter email to delete: ");

Customer c = customerDAO.get(email);

System.out.println();
if (c != null) {
customerDAO.delete(c);
System.out.println(c.getName()
+ " has been deleted.\n");
} else {
System.out.println("No customer matches that email.\n");
}
}
}
import java.util.List;
public class CustomerManagerApp {
// declare class variables
private static DAO<Customer> customerDAO = null;
public static void main(String[] args) {
// display a welcome message
System.out.println("Welcome to the Customer Manager\n");
// set the class variables
customerDAO = new CustomerTextFile();
// display the command menu
displayMenu();
// perform 1 or more actions
String action = "";
while (!action.equalsIgnoreCase("exit")) {
// get the input from the user
action = Console.getString("Enter a command: ");
System.out.println();
if (action.equalsIgnoreCase("1")) {
displayAllCustomers();
} else if (action.equalsIgnoreCase("2")) {
addCustomer();
} else if (action.equalsIgnoreCase("3") || action.equalsIgnoreCase("delete")) {
deleteCustomer();
} else if (action.equalsIgnoreCase("4") || action.equalsIgnoreCase("menu")) {
displayMenu();
} else if (action.equalsIgnoreCase("5")) {
System.out.println("Bye.\n");
} else {
System.out.println("Error! Not a valid command.\n");
}
}
}
public static void displayMenu() {
System.out.println("COMMAND MENU");
System.out.println("1 - List all customers");
System.out.println("2 - Add a customer");
System.out.println("3 - Delete a customer");
System.out.println("4 - Show this menu");
System.out.println("5 - Exit this application\n");
}
public static void displayAllCustomers() {
System.out.println("CUSTOMER LIST");
List<Customer> customers = customerDAO.getAll();
Customer c;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < customers.size(); i++) {
c = customers.get(i);
sb.append(StringUtils.padWithSpaces(
c.getName(), 27));
sb.append(c.getEmail());
sb.append("\n");
}
System.out.println(sb.toString());
}
public static void addCustomer() {
String firstName = Console.getLine("Enter first name: ");
String lastName = Console.getString("Enter last name: ");
String email = Console.getString("Enter customer email: ");
Customer customer = new Customer();
customer.setFirstName(firstName);
customer.setLastName(lastName);
customer.setEmail(email);
customerDAO.add(customer);
System.out.println();
System.out.println(firstName + " " + lastName
+ " has been added.\n");
}
public static void deleteCustomer() {
String email = Console.getString("Enter email to delete: ");
Customer c = customerDAO.get(email);
System.out.println();
if (c != null) {
customerDAO.delete(c);
System.out.println(c.getName()
+ " has been deleted.\n");
} else {
System.out.println("No customer matches that email.\n");
}
}
}