Java 需要帮助创建学生信息代码吗
我需要帮助创建一个程序 必须包括: 1.大学生 A.一定有 我学生姓名(姓名和姓氏) 二,。生日 三、身份证# 四、年级(大一、大二等) v课程表(数组?) vi.3您选择的构造函数(必须包含默认值) 七,。所有实例变量的Getter和Setter方法 1.这意味着每个实例变量至少有2个方法,以便能够获取和设置这些变量。 2.方法将是公共的,这样它们可以在类之外使用,而实例变量将是私有的,这样它们就不会被类的用户破坏。 八,。所有方法的适当文档 这就是我目前所拥有的Java 需要帮助创建学生信息代码吗,java,Java,我需要帮助创建一个程序 必须包括: 1.大学生 A.一定有 我学生姓名(姓名和姓氏) 二,。生日 三、身份证# 四、年级(大一、大二等) v课程表(数组?) vi.3您选择的构造函数(必须包含默认值) 七,。所有实例变量的Getter和Setter方法 1.这意味着每个实例变量至少有2个方法,以便能够获取和设置这些变量。 2.方法将是公共的,这样它们可以在类之外使用,而实例变量将是私有的,这样它们就不会被类的用户破坏。 八,。所有方法的适当文档 这就是我目前所拥有的 public class S
public class StudentTester
{
public static void main(String[] args)
{
Student someGuy = new Student(); //This creates a new student using the defalt constructor
Student someGal = new Student("Amanda","Soh"); //This creates a new student and automatically sets the firt and last name variables
String justAHolder = someGuy.getFullName();
String justAnotherHolder = someGal.getFullName();
System.out.print(someGal.getFullName());
someGuy.setMonth(11);
someGal.setMonth(14);
//If you uncomment the next line and try and compile the program, you will be able to see how it generates an error
//someGal.grade=12; //NO, NO, No, grade is supposed to be private!!!!!
}
/**
* Constructor for objects of class Student
*/
public Student()
{
// initialise instance variables
fName = "John";
lName = "Doe";
}
/**
* This is my second constructor example that students name
*
* @param fName This is the input for the first name
* @param lName This is the input for the last name
*/
public Student(String fName, String lName)
{
this();
this.fName = fName;
this.lName = lName;
}
//Here are the Getter Methods
/**
* This is the getter method to get the full name
*
* @return This returns the first and last name as a single String
*/
public String getFullName()
{
return fName+" "+lName;
}
//Here are the Setter Methods
/**
* This is the method to set the month of the students birthday
*
* @param newMonth The new month to set the birthdate with
*/
public void setMonth(int newMonth)
{
if(newMonth>0 && newMonth<13)
{
bDayMonth = newMonth;
}else
{
System.out.println("No one is born in Octovember!");
}
}
public class StudentTester
{
公共静态void main(字符串[]args)
{
Student someGuy=new Student();//这将使用defalt构造函数创建一个新学生
Student someGal=new Student(“Amanda”,“Soh”);//这将创建一个新学生并自动设置firt和last name变量
String justAHolder=someGuy.getFullName();
字符串justAnotherHolder=someGal.getFullName();
System.out.print(someGal.getFullName());
某个人。设定月(11);
一个月(14);
//如果您取消对下一行的注释并尝试编译该程序,您将能够看到它是如何生成错误的
//someGal.grade=12;//不,不,不,年级应该是私人的!!!!!
}
/**
*类Student对象的构造函数
*/
公立学生()
{
//初始化实例变量
fName=“约翰”;
lName=“Doe”;
}
/**
*这是我的第二个由学生命名的构造函数示例
*
*@param fName这是名字的输入
*@param lName这是姓氏的输入
*/
公立学生(字符串fName,字符串lName)
{
这个();
this.fName=fName;
this.lName=lName;
}
//下面是Getter方法
/**
*这是获取全名的getter方法
*
*@return此命令以单个字符串的形式返回名字和姓氏
*/
公共字符串getFullName()
{
返回fName+“”+lName;
}
//下面是Setter方法
/**
*这是设置学生生日月份的方法
*
*@param newMonth用于设置生日的新月份
*/
公共无效设置月(整数新月)
{
如果(newMonth>0&&newMonth您的学生班级:
package com.test;
public class Student {
public Student() {
firstName = "John";
lastName = "Doe";
birthDate = "05/11/1990";
}
public Student(String fName, String lName, String dob, String sGrade,
String[] classSchedule) {
firstName = fName;
lastName = lName;
birthDate = dob;
grade = sGrade;
schedule = classSchedule;
}
private String firstName;
private String lastName;
private String birthDate;
private String grade;
private String[] schedule;
/**
* @return the firstName
*/
public String getFirstName() {
return firstName;
}
/**
* @param firstName
* the firstName to set
*/
public void setFirstName(String firstName) {
this.firstName = firstName;
}
/**
* @return the lastName
*/
public String getLastName() {
return lastName;
}
/**
* @param lastName
* the lastName to set
*/
public void setLastName(String lastName) {
this.lastName = lastName;
}
/**
* @return the birthDate
*/
public String getBirthDate() {
return birthDate;
}
/**
* @param birthDate
* the birthDate to set
*/
public void setBirthDate(String birthDate) {
this.birthDate = birthDate;
}
/**
* @return the grade
*/
public String getGrade() {
return grade;
}
/**
* @param grade
* the grade to set
*/
public void setGrade(String grade) {
this.grade = grade;
}
/**
* @return the schedule
*/
public String[] getSchedule() {
return schedule;
}
/**
* @param schedule
* the schedule to set
*/
public void setSchedule(String[] schedule) {
this.schedule = schedule;
}
public String getFullName() {
return firstName + " " + lastName;
}
}
然后是tester类:
package com.test;
public class StudentTester {
/**
* @param args
*/
public static void main(String[] args) {
Student st1 = new Student(); // This creates a new student using the
// defalt constructor
String[] sch = { "Math 10.30", "Physics 14.00" };
Student st2 = new Student("Amanda", "Soh", "10/12/1990", "Freshman",
sch);// This creates a new student and automatically sets all
// attributes
System.out.println("First Student is: " + st1.getFullName());
System.out.println("Details of 2nd student: " + st2.getFullName() + " "
+ st2.getBirthDate() + " " + st2.getGrade() + " "
+ st2.getSchedule()[0] + " " + st2.getSchedule()[1]);
}
}
我看到了你的代码,但找不到问题。