简体   繁体   English

编写 java 程序,根据玩家对象数组中的玩家 id 检索玩家详细信息

[英]Write a java program to retrieve the player details based on the player id from the array of player objects

this is my code:这是我的代码:

public class Player

    2 public class PlayerUtility {
  
    4   public Player findPlayerDetailsById(Player[] arr, int playerIdToSearch){
    
    7 ..
          
   18 return null;   
    2 public class Main {
    3   public static void main(String[] args) {
   ...
        
   12       PlayerUtility obj=new PlayerUtility();
        ..
   18           System.out.println(obj.findPlayerDetailsById(pObj,id));
        
   21   if(obj.findPlayerDetailsById(pObj,id)==null)
   22   {
   23       System.out.println("No player found");

It's giving the outputs as expected according to the test cases but there's one failed test case Fail 1 - Check the return type of findPlayerDetailsById method in PlayerUtility class(or)the findPlayerDetailsById method returns the null value what should i return instead?它根据测试用例提供预期的输出,但是有一个失败的测试用例 Fail 1 - 检查 PlayerUtility 类中 findPlayerDetailsById 方法的返回类型(或)findPlayerDetailsById 方法返回 null 值我应该返回什么?

First thing please remove return statement from main because main is of void type.首先请从 main 中删除 return 语句,因为 main 是 void 类型。

Second check whether array variable Obj is even initialized or not(or even you need to use Obj value which is not required)or you only need arr variable to complete operation第二次检查数组变量 Obj 是否被初始化(甚至你需要使用不需要的 Obj 值)或者你只需要 arr 变量来完成操作

Third implement getPlayerName and getPhoneNumber method before calling them.第三,在调用它们之前实现 getPlayerName 和 getPhoneNumber 方法。

Fourth check this statement pObj.setPlayerId(id) it's incorrect because you cannot call method without using array index which will refer to an object.第四次检查这个语句 pObj.setPlayerId(id) 它是不正确的,因为你不能在不使用数组索引的情况下调用方法,数组索引将引用 object。

Remove these basic error and edit problem with new issue you are facing if their is any删除这些基本错误并编辑您面临的新问题(如果有的话)

update: i was able to get rid of the last error by returning the array and not an empty object.更新:我能够通过返回数组而不是空的 object 来消除最后一个错误。 Thank you for all the help!谢谢大家的帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM