还是关于java的问题啊,帮助一下我吧,谢谢
编写一个完整的JavaApplication程序。该程序包含类Person、Student、TestStudent,具体要求如下:⑴类Person①属性name:Stri...
编写一个完整的Java Application 程序。该程序包含类Person、Student、TestStudent,具体要求如下:
⑴类Person
①属性
name : String对象,表示一个人姓名
sex: char类型,用来表示性别
id:String对象,表示身份证号
phone:String对象,表示联系电话
email :String对象,表示E-mail地址
②方法
Person(Name name, char sex, String id):构造函数
String getId() :获得身份证号
void setEmail(String email) :设置E-mail地址
void setPhone(String phone) :设置联系电话
public String toString() :返回个人的各项信息,包括姓名、性别等上述属性
⑵类Student
从Person类派生,增加了以下属性和方法:
① 属性
sNo: long类型,表示学生的学号
sClass: String对象,表示学生的班级
② 方法
Student(long sNo, String name, char sex, String id):构造函数
setClass(String sClass): 设置学生的班级信息
public String toString() :返回学生的各项信息,包括学号、班级、姓名等上述属性
(3)类TestStudent作为主类要完成测试功能
(注:程序框架已给出,请填写完整。)
import java.io.*;
class Person
{
protected String name;
protected char sex;
protected String id;
protected String phone;
protected String email;
Person(String name, char sex, String id)
{
}
String getId()
{
}
String getName()
{
}
void setEmail(String email)
{
}
void setPhone(String phone)
{
}
public String toString()
{ String s = new String( "\n\t 姓名: " + name + "\n\t 性别: " + sex);
if (id != null) s += "\n\t 身份证号: " + id;
if (phone != null) s += "\n\t 联系电话: " + phone;
if (email != null) s += "\n\t 联系email: " + email;
return s; }
}
}
class Student extends Person
{
Student(long sNo, String name, char sex, String id)
{
}
void setClass(String sClass)
{
}
public String toString()
{ String s = new String( "\n\t 姓名: " + name + "\n\t 性别: " + sex +"\n\t 学号:"+ sNo );
if(sClass!=null) s+="\n\t 班级:"+sClass;
if (id != null) s += "\n\t 身份证号: " + id;
if (phone != null) s += "\n\t 联系电话: " + phone;
if (email != null) s += "\n\t 联系email: " + email;
return s;
}
}
public class TestStudent
{ public static void main(String args[])
{ Student aStudent = new Student(2004001, "王非", 女,"2202198506070222");
aStudent.setPhone("88078549");
aStudent.setEmail("wangfei@zjtvu.edu.cn");
System.out.println("student info: " + aStudent); }
}
} 展开
⑴类Person
①属性
name : String对象,表示一个人姓名
sex: char类型,用来表示性别
id:String对象,表示身份证号
phone:String对象,表示联系电话
email :String对象,表示E-mail地址
②方法
Person(Name name, char sex, String id):构造函数
String getId() :获得身份证号
void setEmail(String email) :设置E-mail地址
void setPhone(String phone) :设置联系电话
public String toString() :返回个人的各项信息,包括姓名、性别等上述属性
⑵类Student
从Person类派生,增加了以下属性和方法:
① 属性
sNo: long类型,表示学生的学号
sClass: String对象,表示学生的班级
② 方法
Student(long sNo, String name, char sex, String id):构造函数
setClass(String sClass): 设置学生的班级信息
public String toString() :返回学生的各项信息,包括学号、班级、姓名等上述属性
(3)类TestStudent作为主类要完成测试功能
(注:程序框架已给出,请填写完整。)
import java.io.*;
class Person
{
protected String name;
protected char sex;
protected String id;
protected String phone;
protected String email;
Person(String name, char sex, String id)
{
}
String getId()
{
}
String getName()
{
}
void setEmail(String email)
{
}
void setPhone(String phone)
{
}
public String toString()
{ String s = new String( "\n\t 姓名: " + name + "\n\t 性别: " + sex);
if (id != null) s += "\n\t 身份证号: " + id;
if (phone != null) s += "\n\t 联系电话: " + phone;
if (email != null) s += "\n\t 联系email: " + email;
return s; }
}
}
class Student extends Person
{
Student(long sNo, String name, char sex, String id)
{
}
void setClass(String sClass)
{
}
public String toString()
{ String s = new String( "\n\t 姓名: " + name + "\n\t 性别: " + sex +"\n\t 学号:"+ sNo );
if(sClass!=null) s+="\n\t 班级:"+sClass;
if (id != null) s += "\n\t 身份证号: " + id;
if (phone != null) s += "\n\t 联系电话: " + phone;
if (email != null) s += "\n\t 联系email: " + email;
return s;
}
}
public class TestStudent
{ public static void main(String args[])
{ Student aStudent = new Student(2004001, "王非", 女,"2202198506070222");
aStudent.setPhone("88078549");
aStudent.setEmail("wangfei@zjtvu.edu.cn");
System.out.println("student info: " + aStudent); }
}
} 展开
1个回答
展开全部
//Person.java
public class Person {
protected String name;
protected char sex;
protected String id;
protected String phone;
protected String email;
public Person(String name, char sex, String id) {
super();
this.name = name;
this.sex = sex;
this.id = id;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public char getSex() {
return sex;
}
public void setSex(char sex) {
this.sex = sex;
}
public String toString() {
String s = new String("\n\t 姓名: " + name + "\n\t 性别: " + sex);
if (id != null)
s += "\n\t 身份证号: " + id;
if (phone != null)
s += "\n\t 联系电话: " + phone;
if (email != null)
s += "\n\t 联系email: " + email;
return s;
}
}
//Student.java
public class Student extends Person {
private long sNo;
private String sClass;
public Student(long sNo, String name, char sex, String id) {
super(name, sex, id);
this.sNo=sNo;
}
public String getSClass() {
return sClass;
}
public void setSClass(String class1) {
sClass = class1;
}
public long getSNo() {
return sNo;
}
public void setSNo(long no) {
sNo = no;
}
public String toString() {
String s = new String("\n\t 姓名: " + name + "\n\t 性别: " + sex
+ "\n\t 学号:" + sNo);
if (sClass != null)
s += "\n\t 班级:" + sClass;
if (id != null)
s += "\n\t 身份证号: " + id;
if (phone != null)
s += "\n\t 联系电话: " + phone;
if (email != null)
s += "\n\t 联系email: " + email;
return s;
}
}
//TestStudent.java
public class TestStudent {
public static void main(String args[]) {
Student aStudent = new Student(2004001l, "王非", '女', "2202198506070222");
aStudent.setPhone("88078549");
aStudent.setEmail("wangfei@zjtvu.edu.cn");
System.out.println("student info: " + aStudent);
}
}
public class Person {
protected String name;
protected char sex;
protected String id;
protected String phone;
protected String email;
public Person(String name, char sex, String id) {
super();
this.name = name;
this.sex = sex;
this.id = id;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public char getSex() {
return sex;
}
public void setSex(char sex) {
this.sex = sex;
}
public String toString() {
String s = new String("\n\t 姓名: " + name + "\n\t 性别: " + sex);
if (id != null)
s += "\n\t 身份证号: " + id;
if (phone != null)
s += "\n\t 联系电话: " + phone;
if (email != null)
s += "\n\t 联系email: " + email;
return s;
}
}
//Student.java
public class Student extends Person {
private long sNo;
private String sClass;
public Student(long sNo, String name, char sex, String id) {
super(name, sex, id);
this.sNo=sNo;
}
public String getSClass() {
return sClass;
}
public void setSClass(String class1) {
sClass = class1;
}
public long getSNo() {
return sNo;
}
public void setSNo(long no) {
sNo = no;
}
public String toString() {
String s = new String("\n\t 姓名: " + name + "\n\t 性别: " + sex
+ "\n\t 学号:" + sNo);
if (sClass != null)
s += "\n\t 班级:" + sClass;
if (id != null)
s += "\n\t 身份证号: " + id;
if (phone != null)
s += "\n\t 联系电话: " + phone;
if (email != null)
s += "\n\t 联系email: " + email;
return s;
}
}
//TestStudent.java
public class TestStudent {
public static void main(String args[]) {
Student aStudent = new Student(2004001l, "王非", '女', "2202198506070222");
aStudent.setPhone("88078549");
aStudent.setEmail("wangfei@zjtvu.edu.cn");
System.out.println("student info: " + aStudent);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询