Java归档和高分 [英] Java filing and highscore

查看:57
本文介绍了Java归档和高分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在6个小时内完成作业,我完全迷路了.到目前为止,我已经在现有工作中添加了新方法,但是我不知道该怎么做. 文本文件具有名称和分数,第一种方法需要检查分数是否在前10名之中,并返回true/false:

Hi so I have an assignment due in 6 hours and I am completely lost. 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:

我迷失的最后一个方法需要将高分写入highscore.txt文件中的正确位置(按降序排列),该方法使用readHighScore()方法找到记录应位于的行号插入.

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.

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:

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

这篇关于Java归档和高分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆