我正在做一个考勤系统项目,在那里我阅读教师姓名,课程,学生和学生课程,最后是学生缺席。 这是学生档案:
6
12 Ahmed Suliman 2
ECCE230 0
ECCE356 0
71 Abdulrahim Naser 2
ECCE436 0
ECCE430 0
94 Huda Bassam 3
ECCE356 0
ECCE436 0
ECCE430 0
26 Amna Alzaabi 1
ENGR112 0
52 Mohamed Almansoori 3
ECCE356 0
ECCE430 0
ECCE230 0
80 Noor Alantali 1
ENGR112 0
这是我用来阅读它们的代码:
int studID[];
String studFname[], studLname[], studCo[]; int noc, nos;
Course c[];
AssetManager assetManager = getAssets();
InputStream input2;
try {
int CStuds = 0;
input2 = assetManager.open("Student info.txt");
Scanner studscan = new Scanner(input2);
nos = studscan.nextInt();
studID = new int[nos];
studFname = new String[nos];
studLname = new String[nos];
for (int e = 0; e < nos; e++)
{
studID[e] = studscan.nextInt();
studFname[e] = studscan.next();
studLname[e] = studscan.next();
noc = studscan.nextInt();
studCo = new String[noc];
studAbs = new int[noc];
for (int q = 0; q < noc; q++)
{
studCo[q] = studscan.next();
studAbs[q] = studscan.nextInt();
}
for (int h = 0; h < noc; h++){
if (InsCourse.equals(studCo[h]))
{
SelectedStuds[CStuds] = studID[e] + " - "+ studFname[e] + " " + studLname[e];
studAbs = new int[nos];
StudentAbsence[CStuds] = studAbs[e];
//Toast.makeText(getBaseContext(), SelectedStuds[a], Toast.LENGTH_SHORT).show();
CStuds++;
}
}
}
studscan.close();
//Toast.makeText(getBaseContext(), SelectedStuds[0], Toast.LENGTH_SHORT).show();
CourseStudents = new String[SelectedStuds.length];
StudentsAbs = new String[SelectedStuds.length];
for (int t = 0; t < SelectedStuds.length; t++) {
CourseStudents[t] = SelectedStuds[t];
StudentsAbs[t] = StudentAbsence[t] + "%";
}
// Toast.makeText(getBaseContext(), SelectedStuds[0] + SelectedStuds[1], Toast.LENGTH_SHORT).show();
android.R.layout.simple_list_item_1 ,instructorArray);
} catch (IOException e) {
e.printStackTrace();
}
我没有在此处粘贴完整代码,但这足以解决问题。 所以我在那里读到的东西叫做StudsAbs,它就是缺席。在文件中它的当前为0;我要创建一个按钮,按下时应该为特定学生更新此值。但是,我想知道如何更改文件中一个学生的特定值并在程序中显示它。那么如何替换输入文件中的特定值或单词并更新它以再次显示?This picture is an example of the attendace. I want the 0% to change when I click save attendance, but how to replace a specific value in the input file?