student.Java 文件
package ex02l;
import java.util.*;
import java.io.*;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;class student{
int no, classno, age;
String name, sex;
student(){
System.out.println("I`m a student!");
}
student(int n, String s){
this.no = n;
this.sex = s;
}
void getNo(int n){
this.no = n;
}
void getClassno(int n){
this.classno = n;
}
void getAge(int n){
this.age=n;
}
void getName(String s){
this.name = s;
}
void getSex(String s){
this.sex = s;
} void setNo(int n){
this.no = n;
}
void setClassno(int n){
this.classno = n;
}
void setAge(int n){
this.age = n;
}
void setName(String s){
this.name = s;
}
void setSex(String s){
this.sex = s;
}
public String toString(){
String s = " 学号: " + this.no + " 姓名: " + this.name + " 年龄: " + this.age
+ " 性别: " + this.sex + " 班级: " +this.classno;
return s;
}
}class CollegeStudent extends student{
String profession;
void getProfession(String s){
this.profession = s;
}
void setProfession(String s){
this.profession = s;
}
public String toString(){
String s = " 学号: " + this.no + " 姓名: " + this.name + " 年龄: " + this.age + " 性别: " + this.sex + " 班级: " +this.classno+"专业:"+this.profession;
return s;
}
void writefile(String s) throws FileNotFoundException, IOException{ FileOutputStream out_f = new FileOutputStream("C:\\data.txt");
byte[] b = s.getBytes();
out_f.write(b);
} void readfile() throws FileNotFoundException, IOException{
int a = 0;
FileInputStream in_f = new FileInputStream("C:\\data.txt");
while(a != -1){
a = in_f.read();
System.out.print(a);
} }}test.java文件
public class test{ public static void main(String[] args){ Scanner in = new Scanner(System.in);
String s1 = ""; CollegeStudent S = new CollegeStudent();
S.getNo( 95001 );
S.getClassno(4);
S.getAge(20);
S.getName("陈益民");
S.getSex("女");
S.getProfession("物流工程"); s1 = S.toString();
System.out.println("学生信息: \r\n" + s1); System.out.print("请输入要修改的学生信息:"+"\r\n"+"Name:");
S.setName(in.nextLine(李满缘));
System.out.print("Sex:");
S.setSex(in.nextLine(女));
System.out.print("Profession:");
S.setProfession(in.nextLine(信息管理与信息系统));
System.out.print("No:");
S.setNo(in.nextInt(107062005));
System.out.print("Classno:");
S.setClassno(in.nextInt(3));
System.out.print("Age:");
S.setAge(in.nextInt(22));
s1 = S.toString();
System.out.println("修改后的学生信息:\r\n" + s1);
try {
S.writefile(s1);
S.readfile();
} catch (FileNotFoundException ex) { } catch (IOException ex) { } } }可是test文件编译后显示:
描述 位置
找不到符号 第五行
找不到符号 第五行
无法访问student 第八行 急 ~~~~(>_<)~~~~ 大家帮帮忙啊
package ex02l;
import java.util.*;
import java.io.*;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;class student{
int no, classno, age;
String name, sex;
student(){
System.out.println("I`m a student!");
}
student(int n, String s){
this.no = n;
this.sex = s;
}
void getNo(int n){
this.no = n;
}
void getClassno(int n){
this.classno = n;
}
void getAge(int n){
this.age=n;
}
void getName(String s){
this.name = s;
}
void getSex(String s){
this.sex = s;
} void setNo(int n){
this.no = n;
}
void setClassno(int n){
this.classno = n;
}
void setAge(int n){
this.age = n;
}
void setName(String s){
this.name = s;
}
void setSex(String s){
this.sex = s;
}
public String toString(){
String s = " 学号: " + this.no + " 姓名: " + this.name + " 年龄: " + this.age
+ " 性别: " + this.sex + " 班级: " +this.classno;
return s;
}
}class CollegeStudent extends student{
String profession;
void getProfession(String s){
this.profession = s;
}
void setProfession(String s){
this.profession = s;
}
public String toString(){
String s = " 学号: " + this.no + " 姓名: " + this.name + " 年龄: " + this.age + " 性别: " + this.sex + " 班级: " +this.classno+"专业:"+this.profession;
return s;
}
void writefile(String s) throws FileNotFoundException, IOException{ FileOutputStream out_f = new FileOutputStream("C:\\data.txt");
byte[] b = s.getBytes();
out_f.write(b);
} void readfile() throws FileNotFoundException, IOException{
int a = 0;
FileInputStream in_f = new FileInputStream("C:\\data.txt");
while(a != -1){
a = in_f.read();
System.out.print(a);
} }}test.java文件
public class test{ public static void main(String[] args){ Scanner in = new Scanner(System.in);
String s1 = ""; CollegeStudent S = new CollegeStudent();
S.getNo( 95001 );
S.getClassno(4);
S.getAge(20);
S.getName("陈益民");
S.getSex("女");
S.getProfession("物流工程"); s1 = S.toString();
System.out.println("学生信息: \r\n" + s1); System.out.print("请输入要修改的学生信息:"+"\r\n"+"Name:");
S.setName(in.nextLine(李满缘));
System.out.print("Sex:");
S.setSex(in.nextLine(女));
System.out.print("Profession:");
S.setProfession(in.nextLine(信息管理与信息系统));
System.out.print("No:");
S.setNo(in.nextInt(107062005));
System.out.print("Classno:");
S.setClassno(in.nextInt(3));
System.out.print("Age:");
S.setAge(in.nextInt(22));
s1 = S.toString();
System.out.println("修改后的学生信息:\r\n" + s1);
try {
S.writefile(s1);
S.readfile();
} catch (FileNotFoundException ex) { } catch (IOException ex) { } } }可是test文件编译后显示:
描述 位置
找不到符号 第五行
找不到符号 第五行
无法访问student 第八行 急 ~~~~(>_<)~~~~ 大家帮帮忙啊
String name, sex;出现问题报的什么错??
找不到符号 第五行
找不到符号 第五行
无法访问student 第八行