简体   繁体   English

Java归档和高分

[英]Java filing and highscore

Hi so I have an assignment due in 6 hours and I am completely lost. 嗨,我要在6小时内完成作业,我完全迷路了。 I have new methods added to my existing work done so far but I don't know how to do them. 到目前为止,我已经在现有工作中添加了新方法,但是我不知道该怎么做。 The text file has names and scores, and the first method needs to check if the score is among the top 10 and return true/false: 文本文件具有名称和分数,第一种方法需要检查分数是否在前10名之中,并返回true / false:

the last method that I am lost in needs to write the high score into highscore.txt file, at the correct position(in descending order), the method uses readHighScore() method to find the line number where the record should be inserted. 我迷失的最后一个方法需要将高分写入到highscore.txt文件中的正确位置(按降序排列),该方法使用readHighScore()方法来查找应在其中插入记录的行号。

public static void recordHighScore(String name, int score){
    }

You can't insert data into text files. 您不能将数据插入文本文件。 You can only append/rewrite. 您只能追加/重写。 These are the steps: 这些步骤是:

  • Read data and store into objects. 读取数据并存储到对象中。
  • Get the highest/lowest from the objects (you can also sort them with Collections.sort() or Arrays.sort() ) 从对象中获取最高/最低(您也可以使用Collections.sort()Arrays.sort()对它们进行Arrays.sort()
  • Write the sorted objects back into the text file. 将排序后的对象写回到文本文件中。 (You will be overwriting the text file with new data) (您将用新数据覆盖文本文件)

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

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