473,405 Members | 2,338 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Add and show only objects of a particular user in Java?

https://www.dropbox.com/s/wob0gfcaqbj6wys/usecase.jpg?dl=0
https://www.dropbox.com/s/owm2ja9d02xa16r/class.jpg?dl=0
https://www.dropbox.com/s/1bi6hawvtvix1nn/usecase1.jpg?dl=0
https://www.dropbox.com/s/nxouisah8chp73f/usecase2.jpg?dl=0

Above is my usecase diagram, class diagram, two usecases for the program.

and below is the my program code

Main class

Expand|Select|Wrap|Line Numbers
  1. package fttconsole;
  2.  
  3. import java.util.*;
  4. import java.io.BufferedReader;
  5. import java.io.IOException;
  6. import java.io.InputStreamReader;
  7.  
  8.  
  9. public class FTTConsole {
  10.  
  11.     static int choice;
  12.     static FoodTruckTracker fd = new FoodTruckTracker();
  13.  
  14.     public static void main(String[] args) throws NumberFormatException, IOException {
  15.         // Input from the use
  16.         Scanner input = new Scanner(System.in);
  17.         String line;
  18.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));      
  19.         // Exception handling 
  20.         try {
  21.             do {
  22.                 System.out.println("\t\t\t\t\t\t\t\t\t\t\t   FOOD TRUCK REGISTRATION");
  23.                 System.out.println("\t\t\t\t\t\t\t\t\t\t\t    ========================");
  24.                 System.out.println("");
  25.                 System.out.println("\t\t\t\t\t\t\t\t\t\t\t   01.SignUP  / LogIn");
  26.                 System.out.println("\t\t\t\t\t\t\t\t\t\t\t   02.Maintain Food Trucks");
  27.                 System.out.println("\t\t\t\t\t\t\t\t\t\t\t   03.View Food Truck Information"); 
  28.                 System.out.println("\t\t\t\t\t\t\t\t\t\t\t   04.Review Food Truck Information");   
  29.                 System.out.println("\t\t\t\t\t\t\t\t\t\t\t   05.QUIT ");
  30.                 // User enter choice       
  31.                 System.out.print("Enter Your Choice: ");
  32.                 line = br.readLine();
  33.                 choice = Integer.parseInt(line);
  34.                 switch (choice) {
  35.                     case 1:
  36.                         FoodTruckTracker.SignUp();
  37.                         break;
  38.                     case 2:
  39.                         FoodTruckTracker.RecordFoodTruck();
  40.                     case 3:
  41.                      //1 FoodTruckTracker.ViewFoodTruckInfo();
  42.                         break;
  43.                     case 4:
  44.                       //  System.out.println("THANK YOU!");
  45.                         break;
  46.                     case 5:
  47.                         System.out.println("THANK YOU!");
  48.                         break;
  49.                 }
  50.             } while (choice != 5);
  51.             // catch and throw an error msg and prompt to enter correctly.
  52.         } catch (NumberFormatException e) {
  53.             System.out.println("Please insert a number  1,  2  OR 3   as a choice.!!!");
  54.             System.out.print("Enter Your Choice: ");
  55.             line = br.readLine();
  56.             choice = Integer.parseInt(line);
  57.         }
  58.     }// end main
  59. }// end class
  60.  
  61.  
User Class


Expand|Select|Wrap|Line Numbers
  1. package fttconsole;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Iterator;
  5.  
  6.  
  7. public abstract class User {
  8.     // variables
  9.  
  10.     private String username;
  11.     private String password;
  12.     private String fullName;
  13.     private String email;
  14.  
  15.     // ArayList of users
  16.     private ArrayList<User> users = new ArrayList<>();
  17.  
  18.     // no-arg constructor
  19.     public User() {
  20.     }
  21.  
  22.     // paramatized constructor
  23.     public User(String username, String password, String fullName, String email) {
  24.         this.username = username;
  25.         this.password = password;
  26.         this.fullName = fullName;
  27.         this.email = email;
  28.     }
  29.  
  30.     // Getters and Setters
  31.     public String getUsername() {
  32.         return username;
  33.     }
  34.  
  35.     public void setUsername(String username) {
  36.         this.username = username;
  37.     }
  38.  
  39.     public String getPassword() {
  40.         return password;
  41.     }
  42.  
  43.     public void setPassword(String password) {
  44.         this.password = password;
  45.     }
  46.  
  47.     public String getFullName() {
  48.         return fullName;
  49.     }
  50.  
  51.     public void setFullName(String fullName) {
  52.         this.fullName = fullName;
  53.     }
  54.  
  55.     public String getEmail() {
  56.         return email;
  57.     }
  58.  
  59.     public void setEmail(String email) {
  60.         this.email = email;
  61.     }
  62.  
  63.     public ArrayList<User> getUsers() {
  64.         return users;
  65.     }
  66.  
  67.     public void setUsers(ArrayList<User> users) {
  68.         this.users = users;
  69.     }
  70.  
  71.     public void addUser(User userIn) {
  72.         users.add(userIn);
  73.     }
  74.     // Search User By User Name
  75.  
  76.     public abstract User searchUserByName(String Name);
  77.  
  78.  
  79.  
  80.     // Search User by Password
  81.  
  82.     public abstract User searchUserPassword(String password) ;
  83.  
  84.  
  85.  
  86.       public boolean equals(FoodTruckOwner obj){
  87.     boolean result=false;
  88.     if (obj instanceof FoodTruckOwner){
  89.         FoodTruckOwner rhs = (FoodTruckOwner)obj;
  90.         if(this.getUsername().equals(rhs.getUsername()))
  91.             result= true;
  92.         else
  93.             result= false;
  94.     }
  95.     return result;
  96. }
  97.  
  98.  
  99.  abstract  String getAverageRatings();
  100.  
  101.     // toString method
  102.     @Override
  103.     public String toString() {
  104.         return "USER NAME : " + username + ", PASSWORD : " + password + ", FULL NAME : " + fullName + ", EMAIL :" + email;
  105.     }
  106. }
  107.  
  108.  
Customer class
Expand|Select|Wrap|Line Numbers
  1. package fttconsole;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Iterator;
  5.  
  6. public class Customer extends User {
  7.  
  8.     private final ArrayList<Customer> customers = new ArrayList<>();
  9.  
  10.     //no-arg constructor
  11.     public Customer() {
  12.     }
  13.  
  14.     // paramatized constructor
  15.     public Customer(String username, String password, String fullName, String email) {
  16.         super(username, password, fullName, email);
  17.     }
  18.     // toString method
  19.  
  20.     @Override
  21.     public Customer searchUserByName(String Name) {
  22.         Iterator<Customer> itr = customers.iterator();
  23.         while (itr.hasNext()) {
  24.             Customer custobj = itr.next();
  25.             if (!custobj.getUsername().equals(Name)) {
  26.                 System.out.println("User name don't exist.!!! Pls. Enter a Valid Username!");
  27.             } else {
  28.                 return custobj;
  29.             }
  30.         }
  31.         return null;
  32.     }
  33.  
  34.    @Override
  35.     public void addUser(User customerIn) {
  36.         customers.add((Customer) customerIn);
  37.     }
  38.  
  39.     @Override
  40.     public  Customer searchUserPassword(String password) {
  41.         Iterator<Customer> itr = customers.iterator();
  42.         while (itr.hasNext()) {
  43.             Customer custobj = itr.next();
  44.             if (!custobj.getPassword().equals(password)) {
  45.                 System.out.println("Your password is incorrect.!!! Pls. Enter a correct password!");
  46.  
  47.             } else {
  48.                 return custobj;
  49.             }
  50.         }
  51.         return null;
  52.     }
  53.  
  54.     @Override
  55.     public String toString() {
  56.         return super.toString();
  57.     }
  58.  
  59.     @Override
  60.     String getAverageRatings() {
  61.         throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  62.     }
  63.  
  64. } // end Customer class
  65.  
  66.  
FoodTruckOwner class

Expand|Select|Wrap|Line Numbers
  1.  
  2. package fttconsole;
  3.  
  4. import java.util.ArrayList;
  5. import java.util.Iterator;
  6.  
  7.  
  8. public class FoodTruckOwner extends User {
  9.  
  10.     // variables
  11.     private String licenceNo;
  12.     private ArrayList<FoodTruckOwner> foodtruckowners;
  13.  
  14.     private ArrayList<FoodTruck> truck_collection = new ArrayList<FoodTruck>() ;
  15.  
  16.  
  17.     //no-arg constructor
  18.     public FoodTruckOwner() {
  19.         this.foodtruckowners = new ArrayList<>();
  20.     }
  21.  
  22.     // pramatized constructor
  23.     public FoodTruckOwner(String username, String password, String fullName, String email, String licenceNo) {
  24.         super(username, password, fullName, email);
  25.         this.foodtruckowners = new ArrayList<>();
  26.         this.licenceNo = licenceNo;
  27.     }
  28.  
  29.     // Setters and getters
  30.     public String getLicenceNo() {
  31.         return licenceNo;
  32.     }
  33.  
  34.     public void setLicenceNo(String licenceNo) {
  35.         this.licenceNo = licenceNo;
  36.     }
  37.  
  38.  
  39.     public ArrayList<FoodTruckOwner> getFoodtrucksOwners() {
  40.     return foodtruckowners;
  41.    }
  42.  
  43.  
  44.     public void setFoodtruckOwners(ArrayList<FoodTruckOwner> foodtruckowners) {
  45.         this.foodtruckowners = foodtruckowners;
  46.     }
  47.  
  48.  public ArrayList<FoodTruck> getTruck_collection() {
  49.     return truck_collection;
  50. }
  51.  
  52. public void setTruck_collection(ArrayList<FoodTruck> Truck_collection) {
  53.     this.truck_collection = Truck_collection;
  54. }
  55.  
  56.  
  57.     // toString method
  58.  
  59.  
  60.  public void addTruck( FoodTruck truckObj){
  61.     this.truck_collection.add(truckObj);
  62. }   
  63.  
  64.  
  65.  
  66.     @Override
  67.   public void addUser(User foodtruckOwnerIn) {
  68.         foodtruckowners.add((FoodTruckOwner) foodtruckOwnerIn);
  69.     }
  70.  
  71.  
  72.     @Override
  73.     String getAverageRatings() {
  74.         throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  75.     }
  76.  
  77.  
  78.  
  79.     @Override
  80.     public FoodTruckOwner searchUserByName(String Name) {
  81.  
  82.         Iterator<FoodTruckOwner> itr = foodtruckowners.iterator();
  83.         while (itr.hasNext()) {
  84.             FoodTruckOwner ownerobj = itr.next();
  85.             if (!ownerobj.getUsername().equals(Name)) {
  86.                 System.out.println("You are not a Valid User!!! You must be a FoodTruck Owner"
  87.                         + " to Add or Modify!!!");
  88.             } else {
  89.                 return ownerobj;
  90.             }
  91.         }
  92.         return null;
  93.     }
  94.  
  95.  
  96.     @Override
  97.     public  FoodTruckOwner searchUserPassword(String password) {
  98.         Iterator<FoodTruckOwner>itr = foodtruckowners.iterator();
  99.         while (itr.hasNext()) {
  100.             FoodTruckOwner ownerobj = itr.next();
  101.             if (!ownerobj.getPassword().equals(password)) {
  102.                 System.out.println("Your password is incorrect.!!! Pls. Enter a correct password!");
  103.  
  104.             } else {
  105.                 return ownerobj;
  106.             }
  107.         }
  108.         return null;
  109.     }
  110.  
  111.         @Override
  112.     public String toString() {
  113.         return super.toString() + "\t Licence No: " + getLicenceNo();
  114.     } 
  115.  
  116. }
  117.  
  118.  
FoodTruck class
Expand|Select|Wrap|Line Numbers
  1. package fttconsole;
  2.  
  3.  
  4. import java.util.ArrayList;
  5. import java.util.Iterator;
  6.  
  7. public class FoodTruck {
  8.  
  9.     // variables
  10.     private int truckID = 0;
  11.     private String truckName;
  12.     private String location;
  13.     private String foodType;
  14.     private String status;
  15.     // ArrayList of FoodTrucks
  16.     private ArrayList<FoodTruck> foodtrucks = new ArrayList<>();
  17.      private ArrayList<FoodTruckOwner> foodtruckOwner = new ArrayList<>();
  18.  
  19.     // no-arg constructor
  20.         public FoodTruck() {
  21.     }
  22.  
  23.     // paramatized constructor
  24.     public FoodTruck(int truckID, String truckName, String location, String foodType, String status) {
  25.         this.truckID = truckID;
  26.         this.truckName = truckName;
  27.         this.location = location;
  28.         this.foodType = foodType;
  29.         this.status = status;
  30.     }
  31.     public int getTruckID() {
  32.         return truckID;
  33.     }
  34.  
  35.     public void setTruckID(int truckID) {
  36.         this.truckID = truckID;
  37.     }
  38.  
  39.     public String getTruckName() {
  40.         return truckName;
  41.     }
  42.  
  43.     public void setTruckName(String truckName) {
  44.         this.truckName = truckName;
  45.     }
  46.  
  47.     public String getLocation() {
  48.         return location;
  49.     }
  50.  
  51.     public void setLocation(String location) {
  52.         this.location = location;
  53.     }
  54.  
  55.     public String getFoodType() {
  56.         return foodType;
  57.     }
  58.  
  59.     public void setFoodType(String foodType) {
  60.         this.foodType = foodType;
  61.     }
  62.  
  63.     public String getStatus() {
  64.         return status;
  65.     }
  66.  
  67.     public void setStatus(String status) {
  68.         this.status = status;
  69.     }
  70.  
  71.     public ArrayList<FoodTruck> getFoodtrucks() {
  72.         return foodtrucks;
  73.     }
  74.  
  75.     public void setFoodtrucks(ArrayList<FoodTruck> foodtrucks) {
  76.         this.foodtrucks = foodtrucks;
  77.     }
  78.  
  79.     public ArrayList<FoodTruckOwner> getFoodtruckOwner() {
  80.         return foodtruckOwner;
  81.     }
  82.  
  83.     public void setFoodtruckOwner(ArrayList<FoodTruckOwner> foodtruckOwner) {
  84.         this.foodtruckOwner = foodtruckOwner;
  85.     }
  86.  
  87.       public void addTruck( FoodTruck truckObj){
  88.     this.foodtrucks.add(truckObj);
  89. }  
  90.  
  91.  
  92.  
  93.     // Display all the Truck details by a particular user
  94.  
  95.     public void displayAllByTruckId(User userIn) {
  96.         Iterator<FoodTruck> itr = foodtrucks.iterator();
  97.         while (itr.hasNext()) {
  98.             FoodTruck truckobj = itr.next();
  99.             if (truckobj.getTruckID() != 0) {
  100.  
  101.                 System.out.println("------------------------------------------------" + "\n"
  102.                         + "TRUCK ID : " + truckobj.getTruckID() + "\n"
  103.                         + "TRUCK NAME :" + truckobj.getTruckName() + "\n"
  104.                         + "FOOD TYPE : " + truckobj.getFoodType() + "\n"
  105.                         + "LOCATION : " + truckobj.getLocation() + "\n"
  106.                         + "STATUS :" + truckobj.getStatus() + "\n"
  107.                         + "------------------------------------------------");
  108.             } else {
  109.                 System.out.println("No FoodTrucks added Yet!!!!");
  110.             }
  111.  
  112.         }
  113.     }
  114.  
  115.  
  116.  
  117.    public void searchTruckByUserId(int truckID) {
  118.         Iterator<FoodTruck> itr = foodtrucks.iterator();
  119.         while (itr.hasNext()) {
  120.             FoodTruck truckobj = itr.next();
  121.             if (truckobj.getTruckID() == truckID) {
  122.                 for (int i = 0; i < foodtrucks.size(); i++) {
  123.                     System.out.println("Truck ID : " + foodtrucks.get(i).truckID + "\t\t" + "TRUCK NAME : " + foodtrucks.get(i).truckName);
  124.                 }
  125.  
  126.             }
  127.  
  128.         }
  129.  
  130.     }
  131.  
  132.  
  133.       public FoodTruck searchTruckByTruckId(int truckID) {
  134.         Iterator<FoodTruck> itr = foodtrucks.iterator();
  135.         while (itr.hasNext()) {
  136.             FoodTruck truckobj = itr.next();
  137.             if (truckobj.getTruckID() == (truckID)) {
  138.                 return truckobj;
  139.             }
  140.         }
  141.         System.out.println("There is No Truck By that ID..");
  142.         return null;
  143.     }
  144.  
  145.     @Override
  146.     public String toString() {
  147.         return "FoodTruck{" + "truckID=" + truckID + ", truckName=" + truckName + ", location=" + location + ", foodType=" + foodType + ", status=" + status + ", foodtrucks=" + foodtrucks + ", foodtruckOwner=" + foodtruckOwner + '}';
  148.     }
  149.  
  150. }
  151.  
  152.  
FoodTruckTracker class
Expand|Select|Wrap|Line Numbers
  1.  
  2. package fttconsole;
  3.  
  4. import java.util.*;
  5. import java.util.regex.Matcher;
  6. import java.util.regex.Pattern;
  7.  
  8.  
  9. public class FoodTruckTracker {
  10.  
  11.     // Array List of users and foodtrucks
  12.     static ArrayList<User> users = new ArrayList<>();
  13.     static ArrayList<FoodTruck> foodtrucks = new ArrayList<>();
  14.     // variables
  15.     private static int truckId = 0;
  16.     private static String location = "";
  17.     private static String status = "";
  18.     // Instance of class User and  FoodTruck
  19.     static FoodTruck objFoodTruck = new FoodTruck();
  20.     static User objCustomer = new Customer();
  21.     static User objFoodTruckOwner = new FoodTruckOwner();
  22.  
  23.     //static User objUser2 = new  FoodTruckOwner();
  24.     static Scanner sc = new Scanner(System.in);
  25.  
  26.     //no-arg constructor
  27.     public FoodTruckTracker() {
  28.  
  29.     }
  30.  
  31.     // paramatized constructor
  32.     public FoodTruckTracker(ArrayList<User> users, ArrayList<FoodTruck> foodtrucks, ArrayList<FoodTruckOwner> foodtruckowners) {
  33.         FoodTruckTracker.users = users;
  34.         FoodTruckTracker.foodtrucks = foodtrucks;
  35.     }
  36. // Getters and Setters
  37.  
  38.     public ArrayList<User> getUsers() {
  39.         return users;
  40.     }
  41.  
  42.     public void setUsers(ArrayList<User> users) {
  43.         FoodTruckTracker.users = users;
  44.     }
  45.  
  46.     public ArrayList<FoodTruck> getFoodtrucks() {
  47.         return foodtrucks;
  48.     }
  49.  
  50.     public void setFoodtrucks(ArrayList<FoodTruck> foodtrucks) {
  51.         FoodTruckTracker.foodtrucks = foodtrucks;
  52.     }
  53. // Method SignUp User
  54.  
  55.     public static void SignUp() {
  56.         System.out.println("\n \t  USER SIGN UP ");
  57.         System.out.print("------------------------------------------------\n");
  58.         System.out.print("--> Are You a  Customer(C) or Truck Owner(T)? :  ");
  59.         String choice = sc.next();
  60.         System.out.println();
  61.         //If the user is a Customer Type
  62.         if (choice.equalsIgnoreCase("C")) {
  63.  
  64.             sc.nextLine();
  65.             // Enter username
  66.             System.out.print("USER NAME : ");
  67.             String username = sc.nextLine();
  68.             // if user name  is greater than 20
  69.             if (username.length() > 20) {
  70.                 do {    // error msg. Invalid input! until a correct value is entered.
  71.                     System.out.println("Invalid Input!! Please Enter Username not greater than 20 character : ");
  72.                     username = sc.nextLine();
  73.                 } while (username.length() > 20);
  74.             }
  75.             // User enter password    
  76.             System.out.print("PASSWORD :");
  77.             String password = sc.nextLine();
  78.             // If password is not valid
  79.             if (!passValid(password)) {
  80.                 do { // error msg. Invalid password! until a correct value is entered.
  81.                     System.out.println("InValid Input!! Write a password greater than 6 character");
  82.                     System.out.print("PASSWORD :");
  83.                     password = sc.nextLine();
  84.                 } while (!passValid(password));
  85.             }
  86.             // Enter full name
  87.             System.out.println("FULL NAME : ");
  88.             String fullname = sc.nextLine();
  89.             // if full name is greater than 20 character
  90.             if (fullname.length() > 20) {
  91.                 do { //error msg. Invalid full name! until a correct value is entered.
  92.                     System.out.println("Invalid Input!! Please Enter Fullname not greater than 20 character : ");
  93.                     username = sc.nextLine();
  94.                 } while (username.length() > 20);
  95.             }
  96.             // Enter user email
  97.             System.out.print("EMAIL  : ");
  98.             String email = sc.nextLine();
  99.             // if email is not valid
  100.             if (!emailValid(email)) {
  101.                 do { // error msg. Invalid Email.! until a correct value is entered.
  102.                     System.out.println("Invalid Input!! Please Enter email in the format java2@gmail.com : ");
  103.                     System.out.print("EMAIL :");
  104.                     email = sc.next();
  105.                 } while (!emailValid(email));
  106.  
  107.             }
  108.             // new Customer is created
  109.  
  110.             System.out.println("------------------------------------");
  111.             System.out.println("-->Are You sure You want to Save!! (Y/N)");
  112.             String answer = sc.next();
  113.             if (answer.equalsIgnoreCase("y")) {
  114.                 Customer cust = new Customer(username, password, fullname, email);
  115.                 objCustomer.addUser(cust);
  116.                 System.out.println("Customer added successfully .....");
  117.  
  118.                 System.out.println(cust.toString());
  119.  
  120.                 LogInAndUpdateCust();
  121.  
  122.             } else {
  123.                 System.out.println("Cancelled Information....");
  124.  
  125.             }
  126.  
  127.             // Else User is a Food Truck Owner
  128.         } else if (choice.equalsIgnoreCase("T")) {
  129.             // Enter user name
  130.             sc.nextLine();
  131.             System.out.print("USERNAME : ");
  132.             String username = sc.nextLine();
  133.             if (username.length() > 20) {
  134.                 do { // If username is not Valid.. error msg. until a correct one is entered.
  135.                     System.out.print("Invalid Input!!. Please enter username not greater than 20");
  136.                     System.out.println("USERNAME : ");
  137.                     username = sc.nextLine();
  138.                 } while (username.length() > 20);
  139.             } // Enter password
  140.             System.out.print("PASSWORD :");
  141.             String password = sc.nextLine();
  142.             if (!passValid(password)) {
  143.                 do { // password is incorrect error msg. prompt to enter the correct value.
  144.                     System.out.print("Not a Valid Password. Pls. Enter a password not less than 6 character!!");
  145.                     System.out.println("PASSWORD :");
  146.                     password = sc.nextLine();
  147.                 } while (!passValid(password));
  148.             }
  149.             // Enter full name
  150.             System.out.print("FULL NAME :");
  151.             String fullname = sc.nextLine();
  152.             if (fullname.length() > 20) {
  153.                 do { // error msg. until a valid name is entered. 
  154.                     System.out.print("Invalid Name. Name should not be more than  20 characters in length!!");
  155.                     System.out.println("FULL NAME :");
  156.                     fullname = sc.nextLine();
  157.                 } while (fullname.length() > 20);
  158.             }
  159.             // User enter email address
  160.             System.out.print("EMAIL : ");
  161.             String email = sc.nextLine();
  162.             if (!emailValid(email)) {
  163.                 do { // error msg. until a valid email is entered.
  164.                     System.out.println("InValid Email!! Write email in the format java2@gmail.com");
  165.                     System.out.print("EMAIL :");
  166.                     email = sc.nextLine();
  167.                 } while (!emailValid(email));
  168.             } // Enter Licence Number
  169.             System.out.print("ENTER LICENSE NO in the format -> L1111: ");
  170.             String license = sc.nextLine();
  171.             license = license.toUpperCase();
  172.             // If licence in not valid
  173.             if (!isValidLicence(license)) {
  174.                 do { // error msg. until a valid licence is entered.
  175.                     System.out.println("InValid License!! Write License in the format -> L1111");
  176.                     System.out.print("LICENSE :");
  177.                     license = sc.nextLine();
  178.                 } while (!isValidLicence(license));
  179.             }
  180.             // New Truck  Owner is created.
  181.             User ownerIn = new FoodTruckOwner(username,password,fullname,email,license);
  182.             System.out.println("------------------------------------");
  183.             System.out.println("-->Are You sure You want to Save!! (Y/N)");
  184.             String answer = sc.next();
  185.             if (answer.equalsIgnoreCase("Y")) {
  186.                 objFoodTruckOwner.addUser(ownerIn); // --------------------------------------------------------------> TruckOwners to a different list
  187.                 System.out.println("Truck Owner added successfully .....");
  188.                 System.out.println(ownerIn.toString());
  189.                 System.out.println();
  190.  
  191.                     LogInAndUpdateOwner();
  192.  
  193.             } else {
  194.                 System.out.println("Cancelled Information....");
  195.             }
  196.  
  197.         } else {
  198.             System.out.println("Enter either Customer(C) or Truck Owner (T)");
  199.         }
  200.     }
  201.  
  202.  
  203.  
  204.  
  205.  
  206.     public static void LogInAndUpdateCust() {
  207.  
  208.         // User Login  to the System Method
  209.         System.out.println();
  210.         System.out.println("------------------------------------------------------------------");
  211.         System.out.println("--> Please LogIn to the System By Entering your Username and Password.");
  212.         System.out.println();
  213.         // Enter username
  214.         System.out.print("Enter your username  : ");
  215.         String username = sc.next();
  216.         // user is searched
  217.         User foundUser = objCustomer.searchUserByName(username);
  218.         // if user found
  219.         if (foundUser == null) {   // Enter password
  220.             do{
  221.                    System.out.print("Enter your username  : ");
  222.                     username = sc.next();
  223.                     foundUser = objCustomer.searchUserByName(username);
  224.             }while(foundUser==null);
  225.         }
  226.  
  227.               System.out.println("Enter your password :");
  228.               String password = sc.next();
  229.               User foundPass = objCustomer.searchUserPassword(password);
  230.               // if  password is correct user LogIned.
  231.  
  232.               if(foundPass==null){
  233.                   do{
  234.                   System.out.println("Enter your password : ");
  235.                   password  = sc.next();
  236.                   foundPass = objCustomer.searchUserPassword(password);
  237.                   }while(foundPass==null);
  238.               }
  239.                 System.out.println("");
  240.                 System.out.println("You are Successfully LogIned.!!!!");
  241.                 // Option for the user to Modify the logIn details or Not
  242.                 System.out.println("--> Do you wants to Modify your LogIn details ??(Y)es   OR  (N)o :");
  243.                 String ans = sc.next();
  244.                 //if user wants to modify
  245.                 if (ans.equalsIgnoreCase("Y")) {
  246.  
  247.                     // User modify the details
  248.                     System.out.print("Full  Name  :");
  249.                     String newfullName = sc.next();
  250.                     System.out.print("Email  : ");
  251.                     String newEmail = sc.next();
  252.                     System.out.print("password : ");
  253.                     String newPassword = sc.next();
  254.                     // user entered details is set and updated.
  255.                     foundUser.setUsername(newfullName);
  256.                     foundUser.setPassword(newPassword);
  257.                     foundUser.setEmail(newEmail);
  258.                     System.out.println("---------------------");
  259.                     System.out.println("Updated Successfully!!");
  260.  
  261.                 } else { // if user don't want to modify logout.
  262.                     System.out.println("You are Logged Out");
  263.                 }
  264.  
  265.  
  266.     }
  267.  
  268.     public static void LogInAndUpdateOwner() {
  269.  
  270.         // User Login  to the System Method
  271.         System.out.println();
  272.         System.out.println("------------------------------------------------------------------");
  273.         System.out.println("--> Please LogIn to the System By Entering your Username and Password.");
  274.         System.out.println();
  275.         // Enter username
  276.         System.out.print("Enter your username  : ");
  277.         String username = sc.next();
  278.         // user is searched
  279.         User foundUser = objFoodTruckOwner.searchUserByName(username);
  280.         // if user found
  281.  
  282.         if (foundUser == null) {   // Enter password
  283.             do{
  284.                    System.out.print("Enter your username  : ");
  285.                     username = sc.next();
  286.                     foundUser = objFoodTruckOwner.searchUserByName(username);
  287.             }while(foundUser==null);
  288.         }
  289.  
  290.               System.out.println("Enter your password :");
  291.               String password = sc.next();
  292.               User foundPass = objFoodTruckOwner.searchUserPassword(password);
  293.               // if  password is correct user LogIned.
  294.  
  295.               if(foundPass==null){
  296.                   do{
  297.                   System.out.println("Enter your password : ");
  298.                   password  = sc.next();
  299.                   foundPass = objFoodTruckOwner.searchUserPassword(password);
  300.                   }while(foundPass==null);
  301.               }
  302.                 System.out.println("");
  303.                 System.out.println("You are Successfully LogIned.!!!!");
  304.  
  305.                 // Option for the user to Modify the logIn details or Not
  306.                 System.out.println("--> Do you wants to Modify your LogIn details ??(Y)es   OR  (N)o :");
  307.                 String ans = sc.next();
  308.                 //if user wants to modify
  309.                 if (ans.equalsIgnoreCase("Y")) {
  310.  
  311.                     // User modify the details
  312.                     System.out.print("Full  Name  :");
  313.                     String newfullName = sc.next();
  314.                     System.out.print("Email  : ");
  315.                     String newEmail = sc.next();
  316.                     System.out.print("password : ");
  317.                     String newPassword = sc.next();
  318.                     // user entered details is set and updated.
  319.                     foundUser.setUsername(newfullName);
  320.                     foundUser.setPassword(newPassword);
  321.                     foundUser.setEmail(newEmail);
  322.                     System.out.println("---------------------");
  323.                     System.out.println("Updated Successfully!!");
  324.  
  325.                 } else { // if user don't want to modify logout.
  326.                     System.out.println("You are Logged Out");
  327.                 }
  328.             }
  329.  
  330.  
  331.  
  332.     // Email Validator 
  333.     public static Boolean emailValid(String email) {
  334.  
  335.         if (email.contains("@") || email.contains(".com")) {
  336.             return true;
  337.         } else {
  338.             return false;
  339.         }
  340.     }
  341.  
  342.     // Password Validator
  343.     public static Boolean passValid(String pass) {
  344.         if (pass.length() > 6) {
  345.             return true;
  346.         } else {
  347.             return false;
  348.         }
  349.     }
  350.  
  351.     //Licence Validator
  352.     public static Boolean isValidLicence(String Licence) {
  353.         int lengd = Licence.length();
  354.         //Sé til thess ad bílnúmer getur ekki verid lengra en 5 stafir
  355.         if (lengd > 5) {
  356.             System.out.println("License  numbers can not be more then 5 characters");
  357.         }
  358.  
  359.         Matcher m = Pattern.compile("[A-Z](\\d\\d)\\d\\d").matcher(Licence);
  360.         if (m.find()) {
  361.             return true;
  362.  
  363.         } else {
  364.             return false;
  365.         }
  366.     }
  367.  
  368.     // Add Food Truck Method 
  369.     public static void RecordFoodTruck() {
  370.  
  371.         //1. User Login to the System
  372.            // Truck Owner Login  to the System Method
  373.          System.out.println();
  374.         System.out.println("------------------------------------------------------------------");
  375.         System.out.println("--> Please LogIn to the System By Entering your Username and Password.");
  376.         System.out.println();
  377.         // Enter username
  378.         System.out.print("Enter your username  : ");
  379.         String username = sc.next();
  380.         // user is searched
  381.         User foundUser = objFoodTruckOwner.searchUserByName(username);
  382.         // if user found
  383.  
  384.         if (foundUser == null) {   // Enter password
  385.             do{
  386.                    System.out.print("Enter your username  : ");
  387.                     username = sc.next();
  388.                     foundUser = objFoodTruckOwner.searchUserByName(username);
  389.             }while(foundUser==null);
  390.         }
  391.  
  392.               System.out.println("Enter your password :");
  393.               String password = sc.next();
  394.               User foundPass = objFoodTruckOwner.searchUserPassword(password);
  395.               // if  password is correct user LogIned.
  396.  
  397.               if(foundPass==null){
  398.                   do{
  399.                   System.out.println("Enter your password : ");
  400.                   password  = sc.next();
  401.                   foundPass = objFoodTruckOwner.searchUserPassword(password);
  402.                   }while(foundPass==null);
  403.               }
  404.                 System.out.println("");
  405.                 System.out.println("You are Successfully LogIned.!!!!");
  406.               System.out.println("*****************************************");
  407.                 System.out.println("Full Name  : " + foundUser.getFullName());
  408.                 System.out.println("Email : " + foundUser.getEmail());
  409.               System.out.println("*****************************************");
  410.  
  411.               // show the list of foodTrucks belongs to the user if exist
  412.            objFoodTruck.displayAllByTruckId(foundUser); // -------------------------------------------------------- A method to display foodtrucks belonging to 
  413.            // to the user only.
  414.         // 2. Add Food Truck Information
  415.         System.out.println();
  416.         System.out.println("---------------------------------------------\n");
  417.         System.out.println("\n \t  RECORD FOOD TRUCK  INFORMATION ");
  418.         System.out.print("------------------------------------------------\n");
  419.         // Option to Add a Truck or Modify Food Truck.
  420.         System.out.println("Do you want to (A)dd  Or  (M)odify Food Truck Information ?: ");
  421.         String ans = sc.next();
  422.         // If user wants to Add
  423.  
  424.         // if user wants to add a truck
  425.         if (ans.equalsIgnoreCase("A")) {
  426.  
  427.             System.out.print("Truck ID : ");
  428.             // truck Id is generated automatically and incremented as user add more trucks.
  429.             truckId++;
  430.             objFoodTruck.setTruckID(truckId);
  431.             System.out.println(truckId);
  432.             // User enter Truck Name
  433.             System.out.print("Truck Name : ");
  434.             String truckName = sc.next();
  435.  
  436.             // Truck location automatically set to unknown
  437.             System.out.print("Truck Location  :");
  438.             location = "unknown";
  439.             objFoodTruck.setLocation(location);
  440.             System.out.println(location);
  441.             // User enter Food type
  442.  
  443.             System.out.print("Food Type : ");
  444.             String foodType = sc.next();
  445.             // User status automatically set to unknown
  446.  
  447.             System.out.print("Status : ");
  448.             status = "unknown";
  449.             objFoodTruck.setLocation(status);
  450.             System.out.println(status);
  451.             // A new Food truck is created
  452.             FoodTruck foodtruck = new FoodTruck(truckId, truckName, location, foodType, status);
  453.             // Food truck added to arraylist
  454.            objFoodTruck.addTruck(foodtruck);// -----------------------------------------------------------Truck to be added to the found user
  455.             System.out.println();
  456.             System.out.println(foodtruck.toString());
  457.             System.out.println();
  458.             System.out.println("Truck  Added Successfully.");
  459.             //If user wants to modify the  truck information                     
  460.         } else if (ans.equalsIgnoreCase("M")) {
  461.             //3. Method to  Modify Trucks Information
  462.  
  463.         } else {
  464.             System.out.println("You should Enter  (A)dd or  (M)odify Only!! ");
  465.         }
  466.     }
  467.  
  468. }
  469.  
  470.  

My problem is in food Maintain foodtruck.. in the Menu choice.

user login by entering username and password. After login
the user foodtruckowner either add or modify.

When the foodtruckowner(which is a user) login the foodtrucks he has added will be shown. My problem is all
the foodtrucks is showing to the user..
I know this is a simple mistake.. I couln't solve it..

A help is most appreciated...
Thanks
Nov 22 '16 #1
2 1243
Are there any guys!??
Nov 22 '16 #2
chaarmann
785 Expert 512MB
There are a lot of guys, but nobody wants to find the needle in the haystack first before he can start helping.
So please do us a favour and reduce your problem to the bare minimum, that means to around 10-20 lines of code that show the problem, instead of some thousand lines of code!
Nov 24 '16 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Bob Bedford | last post by:
I've to allow an particular user to access a particular directory, but I've no access to the server. The administrator said I've to create a dir by a php script (I know) and give full access to the...
2
by: Peter | last post by:
Hello! Please, could anybody tell me, is it possible to run an asp page as particular user? I have this situation where I have one shared folder on particular server and this folder is shared...
3
by: vj | last post by:
I'm building a large infrastructure with about 30 servers (all running linux). I allow my end users to write scripts which then get broken down in smaller parts and run across the 30 servers. The...
1
by: masri999 | last post by:
How to find All Permissions in the Current Database for a particular User in SQL 2005 ? Thanks M A Srinivas
2
by: vijayalakshmip | last post by:
Hi All, I want a query to findout all(count) the transaction( insert/ update /delete) for all tables in a particular user for the database.All the transaction happened in single day,in tables. I...
1
by: hussainiyad | last post by:
Hi all, Can anyone tell me how to get a record for particular user or Number In my sql i,v Pinvoice table following fields InvNo int 1001 ItemNo 001
1
by: techuse | last post by:
link 1:compose link 2: readmail <div name="compose" id="compose"> //code for compose mail </div>
0
by: Geser | last post by:
Hello! I need help to create a script that woud look for all instances of a particular user id being used on a server (W2K and W2K3 servers). The user id may be used to run scheduled jobs, etc -...
0
by: napstar | last post by:
I would like to know how to customize a list library to show only the user's documents. do sharepoint lists have an event analogous to ASP.NET Page Load event?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.