求作业 编写一个图形界面的Java Application程序
编写图形界面的JavaApplication程序,对于用户输入的每个学生信息(包括学号、姓名、年龄、性别、专业、成绩),按要求在指定目录下创建以学号为名字的文件,并向文件...
编写图形界面的Java Application程序,对于用户输入的每个学生信息(包括学号、姓名、年龄、性别、专业、成绩),按要求在指定目录下创建以学号为名字的文件,并向文件中写入此学生的信息;然后选择打开以学号为名字的学生信息文件,输出这个学生的有关信息。
要有源程序和运行结果,急急急!谢谢了啊,50分奉上! 展开
要有源程序和运行结果,急急急!谢谢了啊,50分奉上! 展开
1个回答
展开全部
/**
* 学生类
* @author Shurrik
*/
public class Student {
private String sid;
private String sname;
private int sage;
private char gender;
private String specialty;
private int grade;
public Student(String sid, String sname, int sage, char gender,
String specialty, int grade) {
super();
this.sid = sid;
this.sname = sname;
this.sage = sage;
this.gender = gender;
this.specialty = specialty;
this.grade = grade;
}
public String getSid() {
return sid;
}
public void setSid(String sid) {
this.sid = sid;
}
public String getSname() {
return sname;
}
public void setSname(String sname) {
this.sname = sname;
}
public int getSage() {
return sage;
}
public void setSage(int sage) {
this.sage = sage;
}
public char getGender() {
return gender;
}
public void setGender(char gender) {
this.gender = gender;
}
public String getSpecialty() {
return specialty;
}
public void setSpecialty(String specialty) {
this.specialty = specialty;
}
public int getGrade() {
return grade;
}
public void setGrade(int grade) {
this.grade = grade;
}
}
----------------------偶是分割线------------------------
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
/**
* 学生管理者类
* @author Shurrik
*/
public class StudentManager {
private String filePath;
private Student stu;
public StudentManager(String filePath,Student stu) {
this.filePath = filePath;
this.stu = stu;
}
/**
* 按学号读取并返回学生信息
* @param sid 学号
* @return 学生信息
*/
public String loadStudentInfo(String sid) {
File StudentInfoFile = new File(this.filePath+"\\"+sid+".txt");
String StudentInfo = "";
try {
FileReader fr = new FileReader(StudentInfoFile);
BufferedReader reader = new BufferedReader(fr);
String line = "";
while((line = reader.readLine()) != null){
StudentInfo += line+"\r\n";
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return StudentInfo;
}
/**
* 保存学生信息以文本文档的形式存入硬盘中
*/
public void saveStudentInfo() {
File StudentInfoFile = new File(this.filePath+"\\"+stu.getSid()+".txt");
try {
FileWriter fw = new FileWriter(StudentInfoFile);
BufferedWriter writer = new BufferedWriter(fw);
writer.write("学号:"+stu.getSid()+"\r\n");
writer.write("姓名:"+stu.getSname()+"\r\n");
writer.write("年龄:"+stu.getSage()+"\r\n");
writer.write("性别:"+stu.getGender()+"\r\n");
writer.write("专业:"+stu.getSpecialty()+"\r\n");
writer.write("成绩:"+stu.getGrade());
writer.close();
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
----------------------偶是分割线------------------------
import java.io.File;
/**
* 测试类
* @author Shurrik
*/
public class Test {
public static void main(String[] args) {
Student stu = new Student("S2010001", "Jack", 21, '男', "Java", 94);
String filePath = "D:\\StudentInfo";
File folder = new File(filePath);
if(!folder.exists()){
folder.mkdirs();
}
StudentManager manager = new StudentManager(filePath, stu);
manager.saveStudentInfo();
String StudentInfo = manager.loadStudentInfo("S2010001");
System.out.println(StudentInfo);
}
}
基本满足了你的要求,其他功能很容易扩展,自己写写看吧。
* 学生类
* @author Shurrik
*/
public class Student {
private String sid;
private String sname;
private int sage;
private char gender;
private String specialty;
private int grade;
public Student(String sid, String sname, int sage, char gender,
String specialty, int grade) {
super();
this.sid = sid;
this.sname = sname;
this.sage = sage;
this.gender = gender;
this.specialty = specialty;
this.grade = grade;
}
public String getSid() {
return sid;
}
public void setSid(String sid) {
this.sid = sid;
}
public String getSname() {
return sname;
}
public void setSname(String sname) {
this.sname = sname;
}
public int getSage() {
return sage;
}
public void setSage(int sage) {
this.sage = sage;
}
public char getGender() {
return gender;
}
public void setGender(char gender) {
this.gender = gender;
}
public String getSpecialty() {
return specialty;
}
public void setSpecialty(String specialty) {
this.specialty = specialty;
}
public int getGrade() {
return grade;
}
public void setGrade(int grade) {
this.grade = grade;
}
}
----------------------偶是分割线------------------------
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
/**
* 学生管理者类
* @author Shurrik
*/
public class StudentManager {
private String filePath;
private Student stu;
public StudentManager(String filePath,Student stu) {
this.filePath = filePath;
this.stu = stu;
}
/**
* 按学号读取并返回学生信息
* @param sid 学号
* @return 学生信息
*/
public String loadStudentInfo(String sid) {
File StudentInfoFile = new File(this.filePath+"\\"+sid+".txt");
String StudentInfo = "";
try {
FileReader fr = new FileReader(StudentInfoFile);
BufferedReader reader = new BufferedReader(fr);
String line = "";
while((line = reader.readLine()) != null){
StudentInfo += line+"\r\n";
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return StudentInfo;
}
/**
* 保存学生信息以文本文档的形式存入硬盘中
*/
public void saveStudentInfo() {
File StudentInfoFile = new File(this.filePath+"\\"+stu.getSid()+".txt");
try {
FileWriter fw = new FileWriter(StudentInfoFile);
BufferedWriter writer = new BufferedWriter(fw);
writer.write("学号:"+stu.getSid()+"\r\n");
writer.write("姓名:"+stu.getSname()+"\r\n");
writer.write("年龄:"+stu.getSage()+"\r\n");
writer.write("性别:"+stu.getGender()+"\r\n");
writer.write("专业:"+stu.getSpecialty()+"\r\n");
writer.write("成绩:"+stu.getGrade());
writer.close();
fw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
----------------------偶是分割线------------------------
import java.io.File;
/**
* 测试类
* @author Shurrik
*/
public class Test {
public static void main(String[] args) {
Student stu = new Student("S2010001", "Jack", 21, '男', "Java", 94);
String filePath = "D:\\StudentInfo";
File folder = new File(filePath);
if(!folder.exists()){
folder.mkdirs();
}
StudentManager manager = new StudentManager(filePath, stu);
manager.saveStudentInfo();
String StudentInfo = manager.loadStudentInfo("S2010001");
System.out.println(StudentInfo);
}
}
基本满足了你的要求,其他功能很容易扩展,自己写写看吧。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询