Retrieving map value with key

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

33 Replies - 1009 Views - Last Post: 30 June 2020 - 08:16 AM Rate Topic: -----

#16 seyidesh   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 83
  • Joined: 24-November 10

Re: Retrieving map value with key

Posted 23 June 2020 - 08:24 AM

View Postseyidesh, on 23 June 2020 - 07:48 AM, said:

View Postg00se, on 23 June 2020 - 06:56 AM, said:

Let's take one simple use case - get List<PersonalFriend> for user 'U', i.e. get a list of personal friends (not sure what other kind of friend there is) of the user called 'U'. Implementation:

map.get("U") - if null there are none.

Another use case: add a list of friends. Implementation:

a. create list and add the friends
b. map.get("U") - if null put list else
c. if not null, addAll to existing list

Note neither requires iteration or any other kind of 'querying' of the map - just using it in the normal way


I did not understand your view, You are not getting the picture:

Here is the picture:
Initially, after registration, all friends are stored in List<PersonalFriend>. Every registered Friend have access to its own personal Page where he can now add his own personalFriend, His personal friend will be store in a Map<username, ArrayList<PersonalFriend>>. The map is meant to Hold individual Personal friends in a ArrayList<PersonalFriend>.

here is the view

Inside the Map
Friend A - with username A --- ArrayList<PersonalFriend> of all his own friend
Friend B - with username B --- ArrayList<PersonalFriend> of all his own friend
Friend C - with username C --- ArrayList<PersonalFriend> of all his own friend

when a user login to view his page, he should be able to use is username as key to retrieve the values of his friends stored in the Map. as ArrayList.


Quote

Here are all the project codes. to be run, I couldn't attach the source code as zip so I had to copy it here.

Quote

Main Class



import java.util.Scanner;

public class Main {
    private static Scanner scanner = new Scanner(System.in);
    private static boolean quite = false;
    private static Gregistration register = new Gregistration("FriendLink");
    private static PersonalFriendReg pReg = new PersonalFriendReg();


    public static void main(String[] args) {

        int choice;
        startApp();
        while (!quite) {
            System.out.println(" \nClick 0 to select menu");
            System.out.println("***************************");
            choice = scanner.nextInt();
            scanner.nextLine();
            switch (choice) {
                case 0:
                    menu();
                    break;
                case 1:
                    createAccount();
                    break;
                case 2:
                    displayHome();
                    break;
                case 3:
                    addFriend();
                    break;
                case 4:
                    // deleteFriend();
                    break;
                case 5:
                    // viewFriendRecord();
                    break;
                case 6:
                    //deletePersonalAccount();
                    break;
                case 7:
                    quite();
                    break;
            }

        }

    }

    private static void startApp() {
        System.out.println("Application starting ... ");
        System.out.println("");
        System.out.println("FriendLink Vol. 0.01");
        System.out.println("You are require to register to be able to use this application");
    }

    private static void quite() {
        quite = true;
    }

    private static void menu() {
        System.out.println(" Click 0 - To select Menu \n" +
                " Click 1 - To register \n" +
                " Click 2 - To Search and Add  a friend \n" +
                " Click 3 - To delete delete friend \n" +
                " Click 4 - To view list of Personal Friend \n" +
                " Click 5 - To delete account \n");
    }

    private static void createAccount() {
        System.out.println("Enter your Username: ");
        String username = scanner.nextLine().toUpperCase();
        GeneralFriends index = register.queryGfriendRecords(username);
        if (index != null) {
            System.out.println("Username already in use, Kindly use another name");
        } else {
            System.out.println("Enter you Surname: ");
            String surname = scanner.nextLine().toUpperCase();
            System.out.println("Enter your First Name: ");
            String fName = scanner.nextLine().toUpperCase();
            System.out.println("Enter you Age: ");
            int age = scanner.nextInt();
            scanner.nextLine();
            System.out.println("Enter your Email: ");
            String email = scanner.nextLine();
            GeneralFriends create = GeneralFriends.createFriend(username, surname, fName, age, email);
//            pReg.friendList(username);
//            pReg.formList(username);
//            PersonalFriends open = PersonalFriends.createFriendList(username, surname, fName, age, email);


            if (register.addGeneralFriend(create)) {
                System.out.println("Registration is successful");
            } else {
                System.out.println("There is an Error completing your Registration.");
            }
        }
    }

    public static void addFriend() {
        System.out.println("You are required to login with your username \nto be able to add friend to your list");
        System.out.println("Enter your username: ");
        String username = scanner.nextLine().toUpperCase();
        GeneralFriends index = register.queryGfriendRecords(username);
        if (index == null) {
            System.out.println("Oops! Username does not exist, Kindly register to be able to build Friends list");
        }
        register.loginDisplay(username);
        System.out.println("Do you like to add friend to your friend-list");
        System.out.println("Type yes/no");
        String add = scanner.nextLine().toUpperCase();
        if (add == "NO") {
            menu();
        }
        System.out.println("Enter Friend Username to search for friend");
        String addFriend = scanner.nextLine().toUpperCase();
        GeneralFriends position = register.queryGfriendRecords(addFriend);
        if (position == null) {
            System.out.println("Oops! No Friend record found ");
        }
        //register.addPersonalFriend(username, addFriend);
        register.loginDisplay(username);
    }

    public static void displayHome() {
        System.out.println("Enter your Username");
        String user = scanner.nextLine().toUpperCase();
        GeneralFriends index = register.queryGfriendRecords(user);
        if (index == null) {
            System.out.println("Username is incorrect. No record found");
        } else {
            register.loginDisplay(user);
            String respond = "YES";
            System.out.println("\nWould you like to build your own friend-list? Yes/No");
            String answer = scanner.nextLine().toUpperCase();
            if (respond.equals(answer)) {
                System.out.println("Enter the Username of Friend to add");
                String friendName = scanner.nextLine().toUpperCase();
                GeneralFriends friendIndex = register.queryGfriendRecords(friendName);
                boolean flag = true;
                if (friendIndex == null) {
                    while (flag) {
                        System.out.println("\nOops! No friend found \n");
                        register.loginDisplay(user);
                        respond = "YES";
                        System.out.println("\nWould you like to build your own friend-list? Yes/No");
                        answer = scanner.nextLine().toUpperCase();
                        if (respond.equals(answer)) {
                            System.out.println("Enter the Username of Friend to add");
                            friendName = scanner.nextLine().toUpperCase();
                            if (user.equals(friendName)) {
                                System.out.println("Sorry! you are not allow to add yourself to friend-list.");
                            } else {

                                register.createFriendList(user, friendName);
                                flag = false;
                            }
                        }else{
                            flag = false;
                        }
                    }

                } else if (user.equals(friendName)) {
                    System.out.println("Sorry! you are allow to add yourself to friend-list.");
                } else {
                    register.createFriendList(user, friendName);

                }
            }

        }
    }
}




Quote

General Class



import java.util.ArrayList;
import java.util.List;

public class Gregistration<T extends Friend> implements ICommon{
    private String appName;
    private List<GeneralFriends> Gfriend;
    //private Map<String, ArrayList<PersonalFriends>> friendMap= new HashMap<String, ArrayList<PersonalFriends>>();
    private PersonalFriendReg personal = new PersonalFriendReg();
    private ArrayList<PersonalFriends> PFriend = new ArrayList<PersonalFriends>();

    public Gregistration() {
    }

    public Gregistration(String appName) {
        this.appName = appName;
        this.Gfriend = new ArrayList<GeneralFriends>();
    }

    private int findFriend(GeneralFriends friend) {
        return this.Gfriend.indexOf(friend);
    }

    private int findFriend(String userName) {
        for (int i = 0; i < Gfriend.size(); i++) {
            GeneralFriends record = this.Gfriend.get(i);
            if (record.getUserName().equals(userName)) {
                return i;
            }
        }
        return -1;
    }

    public List<GeneralFriends> getFriendsRecord(String name) {
        return this.Gfriend;
    }

    public boolean addGeneralFriend(GeneralFriends friends) {
        int indexPosition = findFriend(friends);
        if (indexPosition >= 0) {
            System.out.println("Oops! username is not available. " + this.Gfriend.get(indexPosition).getUserName() + " Already Exist.");
            return false;
        }
        Gfriend.add(friends);

        return true;
    }

    public boolean updateGeneralFriend(GeneralFriends oldRecod, GeneralFriends newRecord) {
        int indexPosition = findFriend(oldRecod);
        if (indexPosition < 0) {
            System.out.println("Oops! Record not found");
            return false;
        }
        this.Gfriend.set(indexPosition, newRecord);
        return true;
    }

    public boolean removeGeneralFriend(String name) {
        int indexPosition = findFriend(name);
        if (indexPosition < 0) {
            System.out.println("No record is found.");
            return false;
        }
        this.Gfriend.remove(indexPosition);
        return true;
    }

    public int searchFriend(String name) {
        int indexPositon = findFriend(name);
        if (this.Gfriend.get(indexPositon).getUserName().equals(name)) {
            System.out.println(this.Gfriend.get(indexPositon).toString());
            return indexPositon;
        }
        System.out.println("Oops! No record found.");
        return -1;
    }

    public GeneralFriends queryGfriendRecords(String name) {
        int indexPosition = findFriend(name);
        if (indexPosition >= 0) {
            return Gfriend.get(indexPosition);
        }
        return null;
    }

    public void printGfriendList() {
        for (int i = 0; i < this.Gfriend.size(); i++) {
            System.out.println((i + 1) + "." + this.Gfriend.get(i).getsName() + " " + this.Gfriend.get(i).getsName() +
                    " \t Ussername  -> " + this.Gfriend.get(i).getUserName() + " \tAge -> " +
                    this.Gfriend.get(i).getAge() + " Email -> " + this.Gfriend.get(i).getEmail());
        }
    }



    @Override
    public void loginDisplay(String userName) {
        int index = findFriend(userName);
            System.out.println("\n***--***--***-xxx-***--***--***");
            System.out.println("");
            System.out.println("Welcome! " + Gfriend.get(index).getsName() + ",");
            LoginDisplayPage<PersonalFriends> display = new LoginDisplayPage<PersonalFriends>(userName);
            display.headerDisplay(userName);

        }

    public void createFriendList(String userName, String friendName) {
        FriendMap<PersonalFriends> mapRoom = new FriendMap(userName);
        FriendMap<PersonalFriends> fd = new FriendMap(userName);
        int index = findFriend(friendName);

        int friendPosition = findFriend(friendName);
        if (friendPosition < 0) {
            System.out.println("Friend Record Does not exist");
        } else {
            String username = userName;
            String friendUsername = Gfriend.get(index).getUserName();
            String friendFName = Gfriend.get(index).getfName();
            String friendSName = Gfriend.get(index).getsName();
            int friendAge = Gfriend.get(index).getAge();
            String friendEmail = Gfriend.get(index).getEmail();
           // int friendIndex = findFriend(friendName);
            PersonalFriends<T> create = Friend.createFriendList(username, friendUsername, friendFName, friendSName, friendAge, friendEmail);
            int myIndex = findFriend(userName);
            if(myIndex >= 0 ){
                if(PFriend.add(create) ) {
                     System.out.println("You have successfully add a friend to your list");

                }else{
                    System.out.println("There was an error adding new friend");
                }
            }
            if(mapRoom.createMap(username, PFriend)){
                System.out.println("Map created ");
                FriendMap map = new FriendMap(username);
                map.printMapDetails();

            }else{
                System.out.println("Error Creating Map");
            }


        }
    }

    private int findPfriend(String username){
        final int i = PFriend.indexOf(username);
        return i;
    }

}



Quote

PersonalFriend Map


import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class FriendMap<T extends PersonalFriends> {
    private String userName;
    Map<String, ArrayList<PersonalFriends>> friendMap= new HashMap<String, ArrayList<PersonalFriends>>();
    ArrayList<PersonalFriends> friendRecord;

    public FriendMap(String userName) {
        this.userName = userName;
        this.friendRecord = new ArrayList<PersonalFriends>();
    }

    public boolean createMap(String username, ArrayList<PersonalFriends> myFriend){
        friendMap.put(username, myFriend);
        return true;
    }

    public ArrayList<PersonalFriends> returnFriendsInMap(String username){
        for(Map.Entry<String, ArrayList<PersonalFriends>> data : friendMap.entrySet()){
            friendRecord = data.getValue();
        }
        return this.friendRecord;
    }


//    public ArrayList<PersonalFriends> returnFriendsInMap(String username){
//        String key = findFriendsKey(username);
//        for(Map.Entry<String, ArrayList<PersonalFriends>> data : friendMap.entrySet()){
//           if(key.equals(data.getKey())){
//               return data.getValue();
//           }
//        }
//        return null;
//    }


    public String findFriendsKey(String username){
        for(String key: friendMap.keySet()){
         if(friendMap.containsKey(username)){
                return key;
            }
        }
        return null;
    }

    public ArrayList<PersonalFriends> friendRecord(String username){

        for(String key : friendMap.keySet()){
           ArrayList<PersonalFriends> value = friendMap.get(key);
            //do something to value
        }

        String key = findFriendsKey(username);
        ArrayList<PersonalFriends> myfriend = friendMap.get(key);
        return myfriend;
    }

    public void printMapDetails(){
        for(Map.Entry<String, ArrayList<PersonalFriends>> data : friendMap.entrySet()){
            String k = data.getKey();
            ArrayList<PersonalFriends> friendList = data.getValue();
            System.out.println("Key: " + k);
            for(int i = 0; i <friendList.size(); i++){
                System.out.println(friendList.get(i));
            }

        }
    }
}







Quote

PersonalFriend Object Class


public class PersonalFriends<T>  {
    private String userName;
    private String fName;
    private String sName;
    private int age;
    private String email;
   private String friendUsername;

    private String comment;
    private String time;
    private String Date;

    public PersonalFriends( String friendUsername) {
        this.friendUsername = friendUsername;
    }

    public PersonalFriends( String friendUsername, String userName, String fName, String sName, int age, String email) {
        this.userName = userName;
        this.fName = fName;
        this.sName = sName;
        this.age = age;
        this.email = email;
        this.friendUsername = friendUsername;
    }

    public PersonalFriends(String userName, String comment, String time, String date) {
        this.userName = userName;
        this.comment = comment;
        this.time = time;
        Date = date;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getfName() {
        return fName;
    }

    public void setfName(String fName) {
        this.fName = fName;
    }

    public String getsName() {
        return sName;
    }

    public void setsName(String sName) {
        this.sName = sName;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public static PersonalFriends createFriendList( String userName, String friendUsername, String fName, String sName, int age, String email){
        return new PersonalFriends(userName, friendUsername, fName, sName, age, email);
    }

    public static PersonalFriends CreateComments(String userName, String comment, String time, String date){
        return new PersonalFriends( userName, comment, date, time );
    }

    @Override
    public String toString() {
        return "PersonalFriends{" +
                "userName='" + userName + '\'' +
                ", fName='" + fName + '\'' +
                ", sName='" + sName + '\'' +
                ", age=" + age +
                ", email='" + email + '\'' +
                '}';
    }





Quote

General Friend Object Class



public class GeneralFriends  {

    private String userName;
    private String fName;
    private String sName;
    private int age;
    private String email;

    public GeneralFriends(String userName) {
        this.userName = userName;
    }

    public GeneralFriends(String userName, String fName, String sName, int age, String email) {
        this.userName = userName;
        this.fName = fName;
        this.sName = sName;
        this.age = age;
        this.email = email;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getfName() {
        return fName;
    }

    public void setfName(String fName) {
        this.fName = fName;
    }

    public String getsName() {
        return sName;
    }

    public void setsName(String sName) {
        this.sName = sName;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public static GeneralFriends createFriend( String userName,  String sName,String fName, int age, String email){
        return new GeneralFriends(userName, fName, sName, age, email);
    }

    @Override
    public String toString() {
        return "GeneralFriends{" +
                "Username= '" + userName + '\'' +
                ", First Name= '" + fName + '\'' +
                ", Surname= '" + sName + '\'' +
                ", Age= " + age +
                ", Email= '" + email + '\'' +
                '}';
    }


}



Quote

Interfaces Class


public interface ICommon {
      void loginDisplay(String userName);
      //List<PersonalFriends> PFriend();

}




Quote

Login Class


import java.util.ArrayList;

public class LoginDisplayPage<T extends PersonalFriends> {
    private String username;
    private ArrayList<T> myFriendList;

    public LoginDisplayPage(String username) {
        this.username = username;
         this.myFriendList = new ArrayList<>();
    }

    public void headerDisplay(String username) {
        FriendMap fm = new FriendMap(username);
       myFriendList = fm.returnFriendsInMap(username);

            int count = 0;
            for (int i = 0; i < myFriendList.size(); i++) {
                System.out.println(myFriendList.get(i));
                count++;
            }
            System.out.println(" \t\t\t\t\t\t FriendList: " + count + " Friend(s)");
            System.out.println("***--***--***--***--***--***--***--***--***--***");
            System.out.println("");

            String key = fm.findFriendsKey(username);
            System.out.println("The key : " + key);



        }
    }


Was This Post Helpful? 0
  • +
  • -

#17 seyidesh   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 83
  • Joined: 24-November 10

Re: Retrieving map value with key

Posted 23 June 2020 - 08:32 AM

View PostNormR, on 23 June 2020 - 08:18 AM, said:

Quote

the Map session is not working

Can you make a small, simpler version with hardcoded values where needed that will compile and execute for testing. There is no need for any GUI. The required user input should be replaced by statements to load the Lists and Maps as needed for the test. The program should execute and show the problem without any user input required.


I have already posted all the code to be run and test. The code is running fine but the objective is the problem.
If you run it, you will notice that the Map is not returning any values
Was This Post Helpful? 0
  • +
  • -

#18 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 832
  • View blog
  • Posts: 6,392
  • Joined: 25-December 13

Re: Retrieving map value with key

Posted 23 June 2020 - 08:44 AM

The posted code has missing classes. Eg Friend and PersonalFriendReg

Also the code is full of warnings: warning: [rawtypes] found raw type:
They need to be fixed so the code compiles cleanly.

Also the code requires user input:
    private static Scanner scanner = new Scanner(System.in);


That needs to either be removed or changed.
It is possible to preload ALL input to the program by using a String with all user input in the Scanner class's constructor. For example:
    private static Scanner scanner = new Scanner("3 Help\nme\n2");


I do not care to enter any input to test a program. The program needs to provide ALL required input for testing.

This post has been edited by NormR: 23 June 2020 - 09:04 AM

Was This Post Helpful? 0
  • +
  • -

#19 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3698
  • View blog
  • Posts: 16,952
  • Joined: 20-September 08

Re: Retrieving map value with key

Posted 23 June 2020 - 08:48 AM

Quote

I did not understand your view, You are not getting the picture:

I assure you i am getting the picture, since everything you said immediately below that sentence accords with what I said above it ;)

Quote

If you run it, you will notice that the Map is not returning any values

How would you know? Any method that would cause values to be returned is either commented out, unimplemented, or both:

Quote

// viewFriendRecord();

This post has been edited by g00se: 23 June 2020 - 08:55 AM
Reason for edit:: Clarification

Was This Post Helpful? 0
  • +
  • -

#20 seyidesh   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 83
  • Joined: 24-November 10

Re: Retrieving map value with key

Posted 23 June 2020 - 09:11 AM

View PostNormR, on 23 June 2020 - 08:44 AM, said:

The posted code has missing classes. Eg Friend and PersonalFriendReg

Also the code is full of warnings: warning: [rawtypes] found raw type:
They need to be fixed so the code compiles cleanly.

Also the code requires user input:
    private static Scanner scanner = new Scanner(System.in);


That needs to either be removed or changed.
It is possible to preload ALL input to the program by using a String with all user input in the Scanner class's constructor. For example:
    private static Scanner scanner = new Scanner("3 Help\nme\n2");


I do not care to enter any input to test a program. The program needs to provide ALL required input for testing.


Quote

The posted code has missing classes. Eg Friend and PersonalFriendReg


The above classes are not functional, that is why i did not attach them. and for the scanner, on your IDE import Scanner
Was This Post Helpful? 0
  • +
  • -

#21 seyidesh   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 83
  • Joined: 24-November 10

Re: Retrieving map value with key

Posted 23 June 2020 - 09:18 AM

Quote

If you run it, you will notice that the Map is not returning any values


I can assure you the Map method is not commented, I have run the application but what I notice is that The method Creating the Map did not create those value even though the method returns true, because if you call the method that retrieves the value of the MAP, nothing is returned. and that is where my bug is. and that is where I need a fix but i couldn't find the problem.
Was This Post Helpful? 0
  • +
  • -

#22 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 832
  • View blog
  • Posts: 6,392
  • Joined: 25-December 13

Re: Retrieving map value with key

Posted 23 June 2020 - 09:33 AM

Quote

The above classes are not functional,

Then remove their references from the code so the code can compile without errors.

Quote

if you call the method that retrieves the value of the MAP, nothing is returned.

What is the name of that method? Where is it called?
Was This Post Helpful? 0
  • +
  • -

#23 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3698
  • View blog
  • Posts: 16,952
  • Joined: 20-September 08

Re: Retrieving map value with key

Posted 23 June 2020 - 09:36 AM

Quote

I can assure you the Map method is not commented
I can only go by the code you have posted. In that, the method that shows the contents of the map is commented out

I suggest you put up a zip file of your runnable code somewhere we can download it, like Google Drive
Was This Post Helpful? 1
  • +
  • -

#24 seyidesh   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 83
  • Joined: 24-November 10

Re: Retrieving map value with key

Posted 23 June 2020 - 10:05 AM

View Postg00se, on 23 June 2020 - 09:36 AM, said:

Quote

I can assure you the Map method is not commented
I can only go by the code you have posted. In that, the method that shows the contents of the map is commented out

I suggest you put up a zip file of your runnable code somewhere we can download it, like Google Drive


Here is the link to the complete source code.
The Source Code
Was This Post Helpful? 0
  • +
  • -

#25 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 832
  • View blog
  • Posts: 6,392
  • Joined: 25-December 13

Re: Retrieving map value with key

Posted 23 June 2020 - 10:09 AM

Can you also post the complete contents of the console from when you execute the program
that shows all the input and the error?
Was This Post Helpful? 0
  • +
  • -

#26 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3698
  • View blog
  • Posts: 16,952
  • Joined: 20-September 08

Re: Retrieving map value with key

Posted 23 June 2020 - 12:00 PM

Welcome! R,
FriendList: 0 Friend(s)
***--***--***--***--***--***--***--***--***--***

The key : null

Would you like to build your own friend-list? Yes/No
Yes
Enter the Username of Friend to add
Alan

Oops! No friend found

That doesn't make any sense at all. If you're letting your user add their first friend, why would you search and tell them that friend isn't found and then go on immediately to the register login display? Of course it isn't!

This post has been edited by g00se: 23 June 2020 - 12:03 PM
Reason for edit:: Clarification

Was This Post Helpful? 0
  • +
  • -

#27 seyidesh   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 83
  • Joined: 24-November 10

Re: Retrieving map value with key

Posted 23 June 2020 - 12:29 PM

View Postg00se, on 23 June 2020 - 12:00 PM, said:

Welcome! R,
FriendList: 0 Friend(s)
***--***--***--***--***--***--***--***--***--***

The key : null

Would you like to build your own friend-list? Yes/No
Yes
Enter the Username of Friend to add
Alan

Oops! No friend found

That doesn't make any sense at all. If you're letting your user add their first friend, why would you search and tell them that friend isn't found and then go on immediately to the register login display? Of course it isn't!



Quote

why would you search and tell them that friend isn't found and then go on immediately to the register login display?


It is expected that anyone using the app must have registered one, the program is not for you to start searching for friends that have not registered. Before you can search for a friend, that means you are sure the friend is on General friend list and if the friend is not on that list, it will return no friend found.

The program is still under development, I can tell you that there are so many checked and functions to be done, but I just want yo cross the bridge one after the other. If you look at the code very well, you will notice there is no password, all those functionality will be added one I get the main function.

Here are the steps and what i intend the code to do.

1. App start.
2. Registration is required to do anything on the app.
3. Once you registered, you can build your own friend list, by search for friend with their username or name,

4. Mutual friend can relate and share communication.

There are other functionalities to be added but at this stage....

Were you able to observe the Map bug, what did I do wrong?

This post has been edited by seyidesh: 23 June 2020 - 12:38 PM

Was This Post Helpful? 0
  • +
  • -

#28 NormR   User is online

  • D.I.C Lover
  • member icon

Reputation: 832
  • View blog
  • Posts: 6,392
  • Joined: 25-December 13

Re: Retrieving map value with key

Posted 23 June 2020 - 12:32 PM

Can you also post the complete contents of the console from when you execute the program
that shows all the input and the error?

What does a user need to enter as data to the program to see the problem you are having?
Was This Post Helpful? 0
  • +
  • -

#29 g00se   User is offline

  • D.I.C Lover
  • member icon

Reputation: 3698
  • View blog
  • Posts: 16,952
  • Joined: 20-September 08

Re: Retrieving map value with key

Posted 23 June 2020 - 01:43 PM

Quote

It is expected that anyone using the app must have registered one, the program is not for you to start searching for friends that have not registered. Before you can search for a friend ...


You're not reading my comment properly. There is no user searching going on at all. Plus, friends don't register, the user registers. Moreover, the output i showed above happened after i registered.

As a general point, you're asking for advice, and i, as an experienced Java programmer, am giving it to you. You seem to be in some strange way 'defending' your (broken) application. That's pointless. I've just pointed out where your program flow is wrong, which strangely is very close to the question you were asking. It's strange that you've not run your own application and gone through the logical steps that a new user would take and found exactly what i've just found and therefore asked a question about that ...

This post has been edited by g00se: 23 June 2020 - 01:53 PM
Reason for edit:: Clarification

Was This Post Helpful? 0
  • +
  • -

#30 seyidesh   User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 83
  • Joined: 24-November 10

Re: Retrieving map value with key

Posted 24 June 2020 - 02:39 AM

View Postg00se, on 23 June 2020 - 01:43 PM, said:

Quote

It is expected that anyone using the app must have registered one, the program is not for you to start searching for friends that have not registered. Before you can search for a friend ...


You're not reading my comment properly. There is no user searching going on at all. Plus, friends don't register, the user registers. Moreover, the output i showed above happened after i registered.



I sincerely appreciate your comments and contributions, and I am not discarding all your advise, I am carefully following through, I am a junior programmer, I still have a lot of things to learn in Java. Please don't be discouraged with my response to your comments, my scope of understanding may not be wide enough to view things the way you are viewing it, kindly be patient to guide me through.

Quote

There is no user searching going on at all. Plus, friends don't register,

I got your Point about user searching not going on. I have tried to re-exam the code but I need to clear somethings here, I don't know if you try to register more than one friend to see if the program is searching for the other friend. Every user has his own login Page, Where he will search for other friends. If you registered more than one friend, you will see what I am talking about.

I know my logic may be wrong one way or the other, that is why I need the help of an experienced programmer to help me figure out where I missed my steps. Where I have a logical error in this program is adding the searched friend to a personal stored Arraylist in The Map.

Here is another version of the same code link: Code Link in this version you will see the search taking place, but where the problem was is in when a particular user is in his own login page, he is expected to only see the number of friends he has added in his own FriendList: 0 Friend(s) but the program is displaying the same number of friends added for all user in their own login page. After carefully going through the codes, I noticed a bug in the way Map is created to shore friend and retrieve friends' details and that was what brought about the first code I shared the link. kindly run this other code and you will notice that at your first login without having friends in your friend list, the program displays nothing for the friend but after adding friend, you will also see the difference. Mind you, kingly register more than one friend to be able to test this

This post has been edited by seyidesh: 24 June 2020 - 02:44 AM

Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3