'I only want to print one list of the arrays not all of them

So im making a program for school on making an interface that if you login with the correct credentials. You will be greeted with how many games you own and the names of the games.


Enter your credentialsEmail : [email protected]

Password : 4567

You Own 2 GamesGames Owned : [[Syrim, Metal Gear Solid V], [CS:GO, Kirby, Valorant]]

Process finished with exit code 0


like the above .

I only want the result to be


Enter your credentialsEmail : [email protected]

Password : 4567

You Own 2 Games Games Owned : [[Syrim, Metal Gear Solid V]

Process finished with exit code 0


so its only one choice of the list inside the array i made.

package com.company;

import java.util.Arrays;

public class userService {
    private String[][] games = new String[2][1];
    private String[][] data = new String[2][3];
    private String email, password, gamesOwned = "";

    //ini namanya constructor yang akan dijalankan setiap class diinisialisasikan
    public userService(String emails, String passwords, String gamesBought) {
        gamesOwned = gamesBought;
        email = emails;
        password = passwords;
        String[][] games = {
                {"Syrim", "Metal Gear Solid V"},
                {"CS:GO", "Kirby", "Valorant"}
        };
        this.games = games;

        String[][] data = {
                {"[email protected]", "12345", "Own 2 Games"},
                {"[email protected]", "4567", "Own 3 Games"}
        };
        this.data = data;
    }

    //method bernama checkCredential
    private boolean checkCredential() {
        for (int i = 0; i < data.length; i++) {
            if (data[i][0].equals(email)) {
                if (data[i][1].equals(password)) {
                    gamesOwned = data[i][2];
                    return true;

                }
            }
        }
        return false;
    }
    private boolean checkGames() {
        for(int j = 0; j < games.length; j++) {
            if(games[j][0].equals(gamesOwned)) {

            return true;

            }
        }
        return false;
    }

    //method bernama login
    public void login() {
        boolean status = checkCredential(); checkGames();
        if (status == true) System.out.println("\nYou " + gamesOwned);
            System.out.println("Games Owned : " + Arrays.deepToString(games));


    }
}

here is the code that i made. and so i imagine that one account will have the skyrim, metal gear solid v. and the other account in the program to have the cs:go, kirby, valorant games.

please help enlighten me and maybe give me better logic for future homework thank you very much!!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source