Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.sun.org.apache.bcel.internal.generic.Select;
- import java.util.Scanner;
- public class test {
- public static void main(String[] args) {
- customerManagement();
- }
- private static void customerManagement() {
- Scanner input = new Scanner(System.in);
- String customerName;
- String customerNewName="";
- String customerOldName;
- String oldAddress;
- String newAddress;
- String oldMoveInDate;
- String newMoveInDate;
- String oldSegment;
- String newSegment;
- int oldNoOfWaterMeters;
- int newNoOfWaterMeters;
- int oldZipcode;
- int newZipcode;
- String moveInDate;
- String zipcode;
- String address;
- String segment;
- String waterMeter;
- String moveOutDate;
- String customerID;
- boolean quit = false;
- do {
- int menuItem; //This will save your menu choice
- System.out.println("/////////////////////////////////////////");
- System.out.println("Press '1' for: Adding new customer"); //Change these depending on the number of choices
- System.out.println("Press '2' for: Deleting customer"); //Change these depending on the number of choices
- System.out.println("Press '3' for: Update customer");
- System.out.println("Press '4' for: Returning to the main menu"); //TODO is not returning (alse case:4)
- System.out.print("Enter your choice here: ");
- menuItem = validateIntInput(); //Keep this to validate menu
- System.out.println("/////////////////////////////////////////");
- switch (menuItem) {
- case 1: //TODO testing sql + changing data type
- System.out.println("Enter the customer name:");
- customerName = input.next();
- System.out.println("Enter the address:");
- input.nextLine();
- address = input.nextLine();
- System.out.println("Enter the zipcode:");
- zipcode = input.next();
- System.out.println("Enter the move in date:");
- moveInDate = input.next();
- System.out.println("Enter the move out date");
- moveOutDate = input.next();
- System.out.println("Enter the segment:");
- segment = input.next();
- System.out.println("Enter the number of water meters:");
- waterMeter = input.next();
- //Inserting new data into the customer table
- DB.insertSQL("INSERT INTO tblCustomer (fldCustomerName, fldAddress, fldZipcode, fldMoveInDate, fldSegment, fldNumberOfWaterMeters, fldMoveOutDate) VALUES('"+customerName+"', '"+address+"', '"+zipcode+"', '"+moveInDate+"', '"+segment+"', '"+waterMeter+"', '"+moveOutDate+"')");
- System.out.println(customerName +" " + address +" " + zipcode+ " "+ moveInDate + " " + segment + " " + waterMeter + " " + moveOutDate);
- break;
- case 2:
- DB.selectSQL("SELECT fldCustomerName FROM tblCustomer");
- do {
- String data = DB.getDisplayData();
- if (data.equals(DB.NOMOREDATA)) {
- break;
- } else
- System.out.print(data);
- }
- while (true);
- System.out.println("You can enter the customer name here you want to delete from the system:");
- customerName = input.next();
- //Delete data
- DB.deleteSQL("DELETE from tblCustomer where fldCustomerName='"+customerName+"';" );
- System.out.println(customerName + " is removed from the list");
- break;
- case 3:
- System.out.println("You can update information about customers here:");
- do {
- System.out.println("/////////////////////////////////////////");
- System.out.print("Please choose which information would you like to update:");
- System.out.println();
- System.out.println("Press '1' for: Customer Name");
- System.out.println("Press '2' for: Address");
- System.out.println("Press '3' for: Zipcode");
- System.out.println("Press '4' for: Move in date");
- System.out.println("Press '5' for: Segment");
- System.out.println("Press '6' for: Number of Water meters");
- System.out.println("Press '7' for: Go back to main menu");
- menuItem = validateIntInput(); //Keep this to validate menu
- System.out.println("/////////////////////////////////////////");
- switch (menuItem) {
- case 1:
- System.out.println("Please input the customer name what you want to change:");//Enter the code that needs to run if 1 was the option choosed.
- customerOldName = input.nextLine();
- System.out.println(customerOldName);
- DB.selectSQL("SELECT fldCustomerName, fldCustomerID FROM tblCustomer WHERE fldCustomerName='"+customerOldName+"';");//
- do {
- String data = DB.getDisplayData();
- if (data.equals(DB.NOMOREDATA)) {
- break;
- } else
- System.out.print(data);
- }
- while (true);
- System.out.println("Insert Customer ID");
- customerID = input.next();
- System.out.println("Insert New Name");
- input.nextLine();
- customerNewName = input.nextLine();
- //Update data in Customer Name field
- if (customerNewName.length()>0) {
- DB.updateSQL("UPDATE tblCustomer SET fldCustomerName='" + customerNewName + "' WHERE fldCustomerID='" + customerID + "'");
- System.out.println("Customer number " + customerID + " has his name changed to " + customerNewName);
- }
- break;
- case 2:
- System.out.println("Please input the old address which you want to change:");
- oldAddress = input.nextLine();
- System.out.println(oldAddress);
- DB.selectSQL("SELECT fldAddress, fldCustomerID FROM tblCustomer WHERE fldAddress='"+oldAddress +"';");//
- do {
- String data = DB.getDisplayData();
- if (data.equals(DB.NOMOREDATA)) {
- break;
- } else
- System.out.print(data);
- }
- while (true);
- System.out.println("Insert Customer ID");
- customerID = input.next();
- System.out.println("Please input the new address:");
- input.nextLine();
- newAddress = input.nextLine();
- //Update data in Address field
- DB.updateSQL("UPDATE tblCustomer SET fldAddress='" + newAddress + "' WHERE fldCustomerID='" + customerID + "'");
- System.out.println("Customer number " + customerID + " has his name changed to " + newAddress);
- break;
- case 3://TODO does it make sense to update it?
- System.out.println("Please input the old zipcode which you want to change:");
- oldZipcode = input.nextInt();
- System.out.println(oldZipcode);
- DB.selectSQL("SELECT fldZipcode, fldCustomerID FROM tblCustomer WHERE fldZipcode='"+oldZipcode +"';");//
- do {
- String data = DB.getDisplayData();
- if (data.equals(DB.NOMOREDATA)) {
- break;
- } else
- System.out.print(data);
- }
- while (true);
- System.out.println("Insert Customer ID");
- customerID = input.next();
- System.out.println("Please input the new zipcode:");
- input.nextLine();
- newZipcode = input.nextInt();
- //Update data in Address field
- DB.updateSQL("UPDATE tblCustomer SET fldZipcode='" + newZipcode + "' WHERE fldCustomerID='" + customerID + "'");
- System.out.println("Customer number " + customerID + " has his name changed to " + newZipcode);
- break;
- case 4:
- System.out.println("Please input the old move in date which you want to change:");
- oldMoveInDate = input.next();
- System.out.println(oldMoveInDate);
- DB.selectSQL("SELECT fldMoveInDate, fldCustomerID FROM tblCustomer WHERE fldMoveInDate='"+oldMoveInDate +"';");//
- do {
- String data = DB.getDisplayData();
- if (data.equals(DB.NOMOREDATA)) {
- break;
- } else
- System.out.print(data);
- }
- while (true);
- System.out.println("Insert Customer ID");
- customerID = input.next();
- System.out.println("Please input the new date of move in:");
- input.nextLine();
- newMoveInDate = input.next();
- //Update data in Address field
- DB.updateSQL("UPDATE tblCustomer SET fldMoveInDate='" + newMoveInDate + "' WHERE fldCustomerID='" + customerID + "'");
- System.out.println("Customer number " + customerID + " has his name changed to " + newMoveInDate);
- System.out.println();
- break;
- case 5:
- System.out.println("Please input the old segment type which you want to change:");
- oldSegment = input.next();
- System.out.println(oldSegment);
- DB.selectSQL("SELECT fldSegment, fldCustomerID FROM tblCustomer WHERE fldSegment='"+oldSegment +"';");//
- do {
- String data = DB.getDisplayData();
- if (data.equals(DB.NOMOREDATA)) {
- break;
- } else
- System.out.print(data);
- }
- while (true);
- System.out.println("Insert Customer ID");
- customerID = input.next();
- System.out.println("Please input the new segment type:");
- input.nextLine();
- newSegment = input.next();
- //Update data in Address field
- DB.updateSQL("UPDATE tblCustomer SET fldSegment='" + newSegment + "' WHERE fldCustomerID='" + customerID + "'");
- System.out.println("Customer number " + customerID + " has his name changed to " + newSegment);
- System.out.println();
- break;
- case 6:
- System.out.println("Please input the number of water meters which you want to change:");
- oldNoOfWaterMeters = input.nextInt();
- System.out.println(oldNoOfWaterMeters);
- DB.selectSQL("SELECT fldNumberOfWaterMeters, fldCustomerID FROM tblCustomer WHERE fldNumberOfWaterMeters='"+oldNoOfWaterMeters +"';");//
- do {
- String data = DB.getDisplayData();
- if (data.equals(DB.NOMOREDATA)) {
- break;
- } else
- System.out.print(data);
- }
- while (true);
- System.out.println("Insert Customer ID");
- customerID = input.next();
- System.out.println("Please input the new number of water meters:");
- input.nextLine();
- newNoOfWaterMeters = input.nextInt();
- //Update data in Address field
- DB.updateSQL("UPDATE tblCustomer SET fldNoOfWaterMeters='" + newNoOfWaterMeters + "' WHERE fldCustomerID='" + customerID + "'");
- System.out.println("Customer number " + customerID + " has his name changed to " + newNoOfWaterMeters);
- System.out.println();
- break;
- case 7:
- quit = true; //This will make the loop stop after running the program - Used when user want to go back
- break;
- default:
- System.out.println("Invalid choice. Try again: ");
- }
- } while (!quit);
- break;
- case 4:
- quit = true; //This will make the loop stop after running the program - Used when user want to go back
- break;
- default:
- System.out.println("Invalid choice. Try again: ");
- }
- } while (!quit);
- }
- private static int validateIntInput() {
- // VALIDATES IF THE INPUT IS AN INT
- Scanner input = new Scanner(System.in);
- while (true) {
- //System.out.println("1: Billing");
- //System.out.println("2: Economy:");
- //System.out.println("3: Statistics");
- //System.out.println("0. Quit");
- try {
- int a = input.nextInt();
- if (a == 0) {
- return 0;
- } else {
- return a;
- }
- } catch (java.util.InputMismatchException e) {
- System.out.println("You didn't enter a number - Try again: ");
- input.nextLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment