求大神编写一个小java程序 5
新建名为测试类文件MyInformation(主类),使用system.out.println()方法输出个人信息(2)定义学生类Student:属性包括学校(Strin...
新建名为测试类文件MyInformation(主类),使用system.out.println()方法输出个人信息
(2)定义学生类Student:属性包括学校(String),专业(String),学号(String)、姓名(String)、性别(String)和年龄(int);定义一个方法PrintInformation(),输出学生个人信息;在测试类MyInformation(主类)中创建学生类对象stu1,存储个人信息并调用PrintInformation()方法输出结果
(3)完成上述(2)中的程序后,增加一个空的构造方法和一个带有参数的构造方法,创建对象stu1时自动调用带参数的构造方法,然后调用PrintInformation()方法输出结果
(4)完成上述(2)中的程序后,设置性别和年龄两个属性为私有属性,并为私有属性编写访问器方法(set方法和get方法),并测试所编写的访问器方法。
(5)完成上述(4)中的程序后,删除学校属性,定义一个父类School:属性包括学校(String);然后在类Student中继承父类School,并测试程序。(30分)
(6)完成上述(4)中的程序后,删除PrintInformation()方法,定义一个接口Information,抽象方法包括PrintInformation()方法;然后在类Student中实现Information接口,并测试程序。 展开
(2)定义学生类Student:属性包括学校(String),专业(String),学号(String)、姓名(String)、性别(String)和年龄(int);定义一个方法PrintInformation(),输出学生个人信息;在测试类MyInformation(主类)中创建学生类对象stu1,存储个人信息并调用PrintInformation()方法输出结果
(3)完成上述(2)中的程序后,增加一个空的构造方法和一个带有参数的构造方法,创建对象stu1时自动调用带参数的构造方法,然后调用PrintInformation()方法输出结果
(4)完成上述(2)中的程序后,设置性别和年龄两个属性为私有属性,并为私有属性编写访问器方法(set方法和get方法),并测试所编写的访问器方法。
(5)完成上述(4)中的程序后,删除学校属性,定义一个父类School:属性包括学校(String);然后在类Student中继承父类School,并测试程序。(30分)
(6)完成上述(4)中的程序后,删除PrintInformation()方法,定义一个接口Information,抽象方法包括PrintInformation()方法;然后在类Student中实现Information接口,并测试程序。 展开
6个回答
展开全部
下面是第(1)题到第(4)题的答案,随后再附上后面两道的答案
package test;
public class MyInformation {
/*
* 新建名为测试类文件MyInformation(主类),使用system.out.println()方法输出个人信息
* (2)定义学生类Student:属性包括学校(String),专业(String),学号(String)、姓名(String)、性别(String)和年龄(int);
* 定义一个方法PrintInformation(),输出学生个人信息;
* 在测试类MyInformation(主类)中创建学生类对象stu1,存储个人信息并调用PrintInformation()方法输出结果
* (3)完成上述(2)中的程序后,增加一个空的构造方法和一个带有参数的构造方法,创建对象stu1时自动调用带参数的构造方法,然后调用PrintInformation()方法输出结果
* (4)完成上述(2)中的程序后,设置性别和年龄两个属性为私有属性,并为私有属性编写访问器方法(set方法和get方法),并测试所编写的访问器方法。
* (5)完成上述(4)中的程序后,删除学校属性,定义一个父类School:属性包括学校(String);然后在类Student中继承父类School,并测试程序。
* (6)完成上述(4)中的程序后,删除PrintInformation()方法,定义一个接口Information,抽象方法包括PrintInformation()方法;
* 然后在类Student中实现Information接口,并测试程序。
*/
public static void main(String[] args){
Student stu1 = new Student();
stu1.PrintInformation();
System.out.println("//////////////////////////////////////////////////////////////////////////");
Student stu2 = new Student("Li Si","male", 19, "Tianjin University", "Computer Science and Technology", "201492084");
stu2.PrintInformation();
System.out.println("//////////////////////////////////////////////////////////////////////////");
Student stu3 = new Student();
stu3.setName("Zhang San");
stu3.setSex("male");
stu3.setAge(18);
stu3.setSchool("Tianjin University");
stu3.setMajor("Computer Science and Technology");
stu3.setNumber("201492082");
System.out.println("Student Information is as followed:");
System.out.println("name: " + stu3.getName());
System.out.println("sex: " + stu3.getSex());
System.out.println("age: " + stu3.getAge());
System.out.println("school: " + stu3.getSchool());
System.out.println("major: " + stu3.getMajor());
System.out.println("number: " + stu3.getNumber());
System.out.println("////////////////////////////////////////////////////////////////////////////");
}
}
class Student{
private String school;
private String major;
private String number;
private String name;
private String sex;
private int age;
Student(){
this.name = "Wang Wu";
this.sex = "male";
this.age = 18;
this.school = "Tianjin University";
this.major = "Computer Science and Techonlory";
this.number = "201492078";
}
Student(String name, String sex, int age, String school, String major, String number){
this.school = school;
this.major = major;
this.name = name;
this.sex = sex;
this.age = age;
this.number = number;
}
public void setSchool(String school){
this.school = school;
}
public void setMajor(String major){
this.major = major;
}
public void setNumber(String number){
this.number = number;
}
public void setName(String name){
this.name = name;
}
public void setSex(String sex){
this.sex = sex;
}
public void setAge(int age){
this.age = age;
}
public String getName(){
return name;
}
public String getSex(){
return sex;
}
public int getAge(){
return age;
}
public String getSchool(){
return school;
}
public String getMajor(){
return major;
}
public String getNumber(){
return number;
}
public void PrintInformation(){
System.out.println("Student Information is as followed:");
System.out.println("name: " + name);
System.out.println("sex: " + sex);
System.out.println("age: "+ age);
System.out.println("school:" + school);
System.out.println("major: " + major);
System.out.println("number: " + number);
}
}
第(5)问答案
package test;
public class MyInformation {
/*
* 新建名为测试类文件MyInformation(主类),使用system.out.println()方法输出个人信息
* (2)定义学生类Student:属性包括学校(String),专业(String),学号(String)、姓名(String)、性别(String)和年龄(int);
* 定义一个方法PrintInformation(),输出学生个人信息;
* 在测试类MyInformation(主类)中创建学生类对象stu1,存储个人信息并调用PrintInformation()方法输出结果
* (3)完成上述(2)中的程序后,增加一个空的构造方法和一个带有参数的构造方法,创建对象stu1时自动调用带参数的构造方法,然后调用PrintInformation()方法输出结果
* (4)完成上述(2)中的程序后,设置性别和年龄两个属性为私有属性,并为私有属性编写访问器方法(set方法和get方法),并测试所编写的访问器方法。
* (5)完成上述(4)中的程序后,删除学校属性,定义一个父类School:属性包括学校(String);然后在类Student中继承父类School,并测试程序。
* (6)完成上述(4)中的程序后,删除PrintInformation()方法,定义一个接口Information,抽象方法包括PrintInformation()方法;
* 然后在类Student中实现Information接口,并测试程序。
*/
public static void main(String[] args){
Student stu1 = new Student();
stu1.PrintInformation();
System.out.println("//////////////////////////////////////////////////////////////////////////");
Student stu2 = new Student("Li Si","male", 19, "Tianjin University", "Computer Science and Technology", "201492084");
stu2.PrintInformation();
System.out.println("//////////////////////////////////////////////////////////////////////////");
Student stu3 = new Student();
stu3.setName("Zhang San");
stu3.setSex("male");
stu3.setAge(18);
stu3.setSchool("Tianjin University");
stu3.setMajor("Computer Science and Technology");
stu3.setNumber("201492082");
System.out.println("Student Information is as followed:");
System.out.println("name: " + stu3.getName());
System.out.println("sex: " + stu3.getSex());
System.out.println("age: " + stu3.getAge());
System.out.println("school: " + stu3.getSchool());
System.out.println("major: " + stu3.getMajor());
System.out.println("number: " + stu3.getNumber());
System.out.println("////////////////////////////////////////////////////////////////////////////");
}
}
class School{
String school;
}
class Student extends School{
//private String school;
private String major;
private String number;
private String name;
private String sex;
private int age;
Student(){
this.name = "Wang Wu";
this.sex = "male";
this.age = 18;
this.school = "Tianjin University";
this.major = "Computer Science and Techonlory";
this.number = "201492078";
}
Student(String name, String sex, int age, String school, String major, String number){
this.school = school;
this.major = major;
this.name = name;
this.sex = sex;
this.age = age;
this.number = number;
}
public void setSchool(String school){
this.school = school;
}
public void setMajor(String major){
this.major = major;
}
public void setNumber(String number){
this.number = number;
}
public void setName(String name){
this.name = name;
}
public void setSex(String sex){
this.sex = sex;
}
public void setAge(int age){
this.age = age;
}
public String getName(){
return name;
}
public String getSex(){
return sex;
}
public int getAge(){
return age;
}
public String getSchool(){
return school;
}
public String getMajor(){
return major;
}
public String getNumber(){
return number;
}
public void PrintInformation(){
System.out.println("Student Information is as followed:");
System.out.println("name: " + name);
System.out.println("sex: " + sex);
System.out.println("age: "+ age);
System.out.println("school:" + school);
System.out.println("major: " + major);
System.out.println("number: " + number);
}
}
第(6)问答案:
接口类:
package test;
public interface Information {
void PrintInformation();
}
完成及测试类:
package test;
public class MyInformation {
/*
* 新建名为测试类文件MyInformation(主类),使用system.out.println()方法输出个人信息
* (2)定义学生类Student:属性包括学校(String),专业(String),学号(String)、姓名(String)、性别(String)和年龄(int);
* 定义一个方法PrintInformation(),输出学生个人信息;
* 在测试类MyInformation(主类)中创建学生类对象stu1,存储个人信息并调用PrintInformation()方法输出结果
* (3)完成上述(2)中的程序后,增加一个空的构造方法和一个带有参数的构造方法,创建对象stu1时自动调用带参数的构造方法,然后调用PrintInformation()方法输出结果
* (4)完成上述(2)中的程序后,设置性别和年龄两个属性为私有属性,并为私有属性编写访问器方法(set方法和get方法),并测试所编写的访问器方法。
* (5)完成上述(4)中的程序后,删除学校属性,定义一个父类School:属性包括学校(String);然后在类Student中继承父类School,并测试程序。
* (6)完成上述(4)中的程序后,删除PrintInformation()方法,定义一个接口Information,抽象方法包括PrintInformation()方法;
* 然后在类Student中实现Information接口,并测试程序。
*/
public static void main(String[] args){
Student stu1 = new Student();
stu1.PrintInformation();
System.out.println("//////////////////////////////////////////////////////////////////////////");
Student stu2 = new Student("Li Si","male", 19, "Tianjin University", "Computer Science and Technology", "201492084");
stu2.PrintInformation();
System.out.println("//////////////////////////////////////////////////////////////////////////");
Student stu3 = new Student();
stu3.setName("Zhang San");
stu3.setSex("male");
stu3.setAge(18);
stu3.setSchool("Tianjin University");
stu3.setMajor("Computer Science and Technology");
stu3.setNumber("201492082");
System.out.println("Student Information is as followed:");
System.out.println("name: " + stu3.getName());
System.out.println("sex: " + stu3.getSex());
System.out.println("age: " + stu3.getAge());
System.out.println("school: " + stu3.getSchool());
System.out.println("major: " + stu3.getMajor());
System.out.println("number: " + stu3.getNumber());
System.out.println("////////////////////////////////////////////////////////////////////////////");
}
}
class School{
String school;
}
class Student extends School implements Information{
//private String school;
private String major;
private String number;
private String name;
private String sex;
private int age;
Student(){
this.name = "Wang Wu";
this.sex = "male";
this.age = 18;
this.school = "Tianjin University";
this.major = "Computer Science and Techonlory";
this.number = "201492078";
}
Student(String name, String sex, int age, String school, String major, String number){
this.school = school;
this.major = major;
this.name = name;
this.sex = sex;
this.age = age;
this.number = number;
}
public void setSchool(String school){
this.school = school;
}
public void setMajor(String major){
this.major = major;
}
public void setNumber(String number){
this.number = number;
}
public void setName(String name){
this.name = name;
}
public void setSex(String sex){
this.sex = sex;
}
public void setAge(int age){
this.age = age;
}
public String getName(){
return name;
}
public String getSex(){
return sex;
}
public int getAge(){
return age;
}
public String getSchool(){
return school;
}
public String getMajor(){
return major;
}
public String getNumber(){
return number;
}
public void PrintInformation(){
System.out.println("Student Information is as followed:");
System.out.println("name: " + name);
System.out.println("sex: " + sex);
System.out.println("age: "+ age);
System.out.println("school:" + school);
System.out.println("major: " + major);
System.out.println("number: " + number);
}
}
package test;
public class MyInformation {
/*
* 新建名为测试类文件MyInformation(主类),使用system.out.println()方法输出个人信息
* (2)定义学生类Student:属性包括学校(String),专业(String),学号(String)、姓名(String)、性别(String)和年龄(int);
* 定义一个方法PrintInformation(),输出学生个人信息;
* 在测试类MyInformation(主类)中创建学生类对象stu1,存储个人信息并调用PrintInformation()方法输出结果
* (3)完成上述(2)中的程序后,增加一个空的构造方法和一个带有参数的构造方法,创建对象stu1时自动调用带参数的构造方法,然后调用PrintInformation()方法输出结果
* (4)完成上述(2)中的程序后,设置性别和年龄两个属性为私有属性,并为私有属性编写访问器方法(set方法和get方法),并测试所编写的访问器方法。
* (5)完成上述(4)中的程序后,删除学校属性,定义一个父类School:属性包括学校(String);然后在类Student中继承父类School,并测试程序。
* (6)完成上述(4)中的程序后,删除PrintInformation()方法,定义一个接口Information,抽象方法包括PrintInformation()方法;
* 然后在类Student中实现Information接口,并测试程序。
*/
public static void main(String[] args){
Student stu1 = new Student();
stu1.PrintInformation();
System.out.println("//////////////////////////////////////////////////////////////////////////");
Student stu2 = new Student("Li Si","male", 19, "Tianjin University", "Computer Science and Technology", "201492084");
stu2.PrintInformation();
System.out.println("//////////////////////////////////////////////////////////////////////////");
Student stu3 = new Student();
stu3.setName("Zhang San");
stu3.setSex("male");
stu3.setAge(18);
stu3.setSchool("Tianjin University");
stu3.setMajor("Computer Science and Technology");
stu3.setNumber("201492082");
System.out.println("Student Information is as followed:");
System.out.println("name: " + stu3.getName());
System.out.println("sex: " + stu3.getSex());
System.out.println("age: " + stu3.getAge());
System.out.println("school: " + stu3.getSchool());
System.out.println("major: " + stu3.getMajor());
System.out.println("number: " + stu3.getNumber());
System.out.println("////////////////////////////////////////////////////////////////////////////");
}
}
class Student{
private String school;
private String major;
private String number;
private String name;
private String sex;
private int age;
Student(){
this.name = "Wang Wu";
this.sex = "male";
this.age = 18;
this.school = "Tianjin University";
this.major = "Computer Science and Techonlory";
this.number = "201492078";
}
Student(String name, String sex, int age, String school, String major, String number){
this.school = school;
this.major = major;
this.name = name;
this.sex = sex;
this.age = age;
this.number = number;
}
public void setSchool(String school){
this.school = school;
}
public void setMajor(String major){
this.major = major;
}
public void setNumber(String number){
this.number = number;
}
public void setName(String name){
this.name = name;
}
public void setSex(String sex){
this.sex = sex;
}
public void setAge(int age){
this.age = age;
}
public String getName(){
return name;
}
public String getSex(){
return sex;
}
public int getAge(){
return age;
}
public String getSchool(){
return school;
}
public String getMajor(){
return major;
}
public String getNumber(){
return number;
}
public void PrintInformation(){
System.out.println("Student Information is as followed:");
System.out.println("name: " + name);
System.out.println("sex: " + sex);
System.out.println("age: "+ age);
System.out.println("school:" + school);
System.out.println("major: " + major);
System.out.println("number: " + number);
}
}
第(5)问答案
package test;
public class MyInformation {
/*
* 新建名为测试类文件MyInformation(主类),使用system.out.println()方法输出个人信息
* (2)定义学生类Student:属性包括学校(String),专业(String),学号(String)、姓名(String)、性别(String)和年龄(int);
* 定义一个方法PrintInformation(),输出学生个人信息;
* 在测试类MyInformation(主类)中创建学生类对象stu1,存储个人信息并调用PrintInformation()方法输出结果
* (3)完成上述(2)中的程序后,增加一个空的构造方法和一个带有参数的构造方法,创建对象stu1时自动调用带参数的构造方法,然后调用PrintInformation()方法输出结果
* (4)完成上述(2)中的程序后,设置性别和年龄两个属性为私有属性,并为私有属性编写访问器方法(set方法和get方法),并测试所编写的访问器方法。
* (5)完成上述(4)中的程序后,删除学校属性,定义一个父类School:属性包括学校(String);然后在类Student中继承父类School,并测试程序。
* (6)完成上述(4)中的程序后,删除PrintInformation()方法,定义一个接口Information,抽象方法包括PrintInformation()方法;
* 然后在类Student中实现Information接口,并测试程序。
*/
public static void main(String[] args){
Student stu1 = new Student();
stu1.PrintInformation();
System.out.println("//////////////////////////////////////////////////////////////////////////");
Student stu2 = new Student("Li Si","male", 19, "Tianjin University", "Computer Science and Technology", "201492084");
stu2.PrintInformation();
System.out.println("//////////////////////////////////////////////////////////////////////////");
Student stu3 = new Student();
stu3.setName("Zhang San");
stu3.setSex("male");
stu3.setAge(18);
stu3.setSchool("Tianjin University");
stu3.setMajor("Computer Science and Technology");
stu3.setNumber("201492082");
System.out.println("Student Information is as followed:");
System.out.println("name: " + stu3.getName());
System.out.println("sex: " + stu3.getSex());
System.out.println("age: " + stu3.getAge());
System.out.println("school: " + stu3.getSchool());
System.out.println("major: " + stu3.getMajor());
System.out.println("number: " + stu3.getNumber());
System.out.println("////////////////////////////////////////////////////////////////////////////");
}
}
class School{
String school;
}
class Student extends School{
//private String school;
private String major;
private String number;
private String name;
private String sex;
private int age;
Student(){
this.name = "Wang Wu";
this.sex = "male";
this.age = 18;
this.school = "Tianjin University";
this.major = "Computer Science and Techonlory";
this.number = "201492078";
}
Student(String name, String sex, int age, String school, String major, String number){
this.school = school;
this.major = major;
this.name = name;
this.sex = sex;
this.age = age;
this.number = number;
}
public void setSchool(String school){
this.school = school;
}
public void setMajor(String major){
this.major = major;
}
public void setNumber(String number){
this.number = number;
}
public void setName(String name){
this.name = name;
}
public void setSex(String sex){
this.sex = sex;
}
public void setAge(int age){
this.age = age;
}
public String getName(){
return name;
}
public String getSex(){
return sex;
}
public int getAge(){
return age;
}
public String getSchool(){
return school;
}
public String getMajor(){
return major;
}
public String getNumber(){
return number;
}
public void PrintInformation(){
System.out.println("Student Information is as followed:");
System.out.println("name: " + name);
System.out.println("sex: " + sex);
System.out.println("age: "+ age);
System.out.println("school:" + school);
System.out.println("major: " + major);
System.out.println("number: " + number);
}
}
第(6)问答案:
接口类:
package test;
public interface Information {
void PrintInformation();
}
完成及测试类:
package test;
public class MyInformation {
/*
* 新建名为测试类文件MyInformation(主类),使用system.out.println()方法输出个人信息
* (2)定义学生类Student:属性包括学校(String),专业(String),学号(String)、姓名(String)、性别(String)和年龄(int);
* 定义一个方法PrintInformation(),输出学生个人信息;
* 在测试类MyInformation(主类)中创建学生类对象stu1,存储个人信息并调用PrintInformation()方法输出结果
* (3)完成上述(2)中的程序后,增加一个空的构造方法和一个带有参数的构造方法,创建对象stu1时自动调用带参数的构造方法,然后调用PrintInformation()方法输出结果
* (4)完成上述(2)中的程序后,设置性别和年龄两个属性为私有属性,并为私有属性编写访问器方法(set方法和get方法),并测试所编写的访问器方法。
* (5)完成上述(4)中的程序后,删除学校属性,定义一个父类School:属性包括学校(String);然后在类Student中继承父类School,并测试程序。
* (6)完成上述(4)中的程序后,删除PrintInformation()方法,定义一个接口Information,抽象方法包括PrintInformation()方法;
* 然后在类Student中实现Information接口,并测试程序。
*/
public static void main(String[] args){
Student stu1 = new Student();
stu1.PrintInformation();
System.out.println("//////////////////////////////////////////////////////////////////////////");
Student stu2 = new Student("Li Si","male", 19, "Tianjin University", "Computer Science and Technology", "201492084");
stu2.PrintInformation();
System.out.println("//////////////////////////////////////////////////////////////////////////");
Student stu3 = new Student();
stu3.setName("Zhang San");
stu3.setSex("male");
stu3.setAge(18);
stu3.setSchool("Tianjin University");
stu3.setMajor("Computer Science and Technology");
stu3.setNumber("201492082");
System.out.println("Student Information is as followed:");
System.out.println("name: " + stu3.getName());
System.out.println("sex: " + stu3.getSex());
System.out.println("age: " + stu3.getAge());
System.out.println("school: " + stu3.getSchool());
System.out.println("major: " + stu3.getMajor());
System.out.println("number: " + stu3.getNumber());
System.out.println("////////////////////////////////////////////////////////////////////////////");
}
}
class School{
String school;
}
class Student extends School implements Information{
//private String school;
private String major;
private String number;
private String name;
private String sex;
private int age;
Student(){
this.name = "Wang Wu";
this.sex = "male";
this.age = 18;
this.school = "Tianjin University";
this.major = "Computer Science and Techonlory";
this.number = "201492078";
}
Student(String name, String sex, int age, String school, String major, String number){
this.school = school;
this.major = major;
this.name = name;
this.sex = sex;
this.age = age;
this.number = number;
}
public void setSchool(String school){
this.school = school;
}
public void setMajor(String major){
this.major = major;
}
public void setNumber(String number){
this.number = number;
}
public void setName(String name){
this.name = name;
}
public void setSex(String sex){
this.sex = sex;
}
public void setAge(int age){
this.age = age;
}
public String getName(){
return name;
}
public String getSex(){
return sex;
}
public int getAge(){
return age;
}
public String getSchool(){
return school;
}
public String getMajor(){
return major;
}
public String getNumber(){
return number;
}
public void PrintInformation(){
System.out.println("Student Information is as followed:");
System.out.println("name: " + name);
System.out.println("sex: " + sex);
System.out.println("age: "+ age);
System.out.println("school:" + school);
System.out.println("major: " + major);
System.out.println("number: " + number);
}
}
展开全部
你好,我帮你写哈。
写好了,你看下你的消息。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个程序没什么难度,,懂点java基础知识,就可以写出来
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
I'm sorry that I can't help you.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你也真是逗比!分值那么小,谁帮你啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
i don't konw!!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询