当前位置:首页 » 编程语言 » javastudent

javastudent

发布时间: 2023-04-19 09:31:12

java:定义一个表示学生信息的类student

1.Bean
package com.test;

public class Student {
private String sSO;//学号
private String sName;//姓名
private String sSex;//性别
private String sAge;//年龄
private String sJava;//成绩嫌谨
public String getSSO() {
return sSO;
}
public void setSSO(String sso) {
sSO = sso;
}
public String getSName() {
return sName;
}
public void setSName(String name) {
sName = name;
}
public String getSSex() {
return sSex;
}
public void setSSex(String sex) {
sSex = sex;
}
public String getSAge() {
return sAge;
}
public void setSAge(String age) {
sAge = age;
}
public String getSJava() {
return sJava;
}
public void setSJava(String java) {
sJava = java;
}
}

2.测试类帆者让
package com.test;

public class textStudent {

/**
* @param args
*/
public static void main(String[] args) {
Student s1 = new Student();//学生对象一
Student s2 = new Student();//学生对象二
//学生一信息
s1.setSName("Tom");
s1.setSSO("1001002");
s1.setSAge("18");
s1.setSSex("男");
s1.setSJava("89");
//学生二信息
s2.setSName("Lucy");
s2.setSSO("1001001");
s2.setSAge("19");
s2.setSSex("女");
s2.setSJava("90");

System.out.println("两名学生的信息如下:");
System.out.println("学号\t姓名\t年龄\t性别\态局t成绩");
System.out.println(s1.getSSO()+"\t"+s1.getSName()+"\t"+s1.getSAge()+"\t"+s1.getSSex()+"\t"+s1.getSJava());
System.out.println(s2.getSSO()+"\t"+s2.getSName()+"\t"+s2.getSAge()+"\t"+s2.getSSex()+"\t"+s2.getSJava());
System.out.println();
int sj1 = Integer.parseInt(s1.getSJava());
int sj2 = Integer.parseInt(s2.getSJava());
double sum = (sj1+sj2)/2.0;//保留一位小数
System.out.println("平均成绩为:"+sum);
}

}

⑵ java定义Student类(包括name,number等属性),定义一个List类型的容器,往容器中添加

定义Student类:
package com.tip.app.common.test;
public class Student {
private String name;
private int number;
private String age;
private String sex;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public String getAge() {
return age;
}
public void setAge(String age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}

}
-------------------------------------------------------------------------
定义一个List类型的容器,往容器中添加:
package com.tip.app.common.test;
import java.util.ArrayList;
import java.util.List;
public class Stest {
public static void main(String[] args) {
//蠢纯尘创建Student类,填写属性
Student student = new Student();
student.setAge("age");
student.setName("带禅name");
student.setNumber(18);
student.setSex("sex"裤则);

//创建list 往list添加student
List<Student> students = new ArrayList<Student>();
students.add(student);

}
}

⑶ 编写一个简单Java类Student类。 2. 编写一个简单Java类Student类

public class Student {
// 1)包含两个属性sno(学号)和age(年龄),属性全部封装。
private String sno;
private int age;

// ① 提供一个两参构造方法对属性赋值,另外提供一个无参构造方法。
public Student(String sno, int age) {
this.sno = sno;
this.age = age;
}

public Student() {
}

// ② 提供一个返回信息的方法,方法名getInfo( ),返回两个属性的信息。
public void getInfo() {
System.out.println("学号: " + sno + ", 年龄: " + age);
}

// ③ 提供getter和setter方法。
public String getSno() {
return sno;
}

public void setSno(String sno) {
this.sno = sno;
}

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}
}

⑷ java定义一个学生类Student

1:
packagewo;
-
publicclassStudentText{
publicstaticvoidmain(String[]args){
Students1=newStudent(01,"张三");
Students2=newStudent(02,"李四");
booleanb=s1.equals(s2);
System.out.println(b);
}

}
classStudent{
privateintnum;
privateStringnema;

publicStudent(intnum,Stringnema){
super();
this.num=num;
this.nema=nema;
}
publicStudent(){

}
publicintgetNum(){
returnnum;
}
publicvoidsetNum(intnum){
this.num=num;
}
publicStringgetNema(){
returnnema;
}
publicvoidsetNema(Stringnema){
this.nema=nema;
}


publicbooleanequals(Objectobj){
if(this==obj)
returntrue;
if(obj==null)
returnfalse;
if(getClass()!=obj.getClass())
returnfalse;

if(num!=this.num)
returnfalse;
returntrue;
}

}
2

packagewo;

publicclasspolyTest{

publicstaticvoidmain(String[]args){
pensonp=newpenson("张三",25);
System.out.println(p);
loyeel=newloyee(01,3000);
System.out.println(l);
Managerm=newManager("老师");
System.out.println(m);

}

}
classpenson{
privateStringname;
privateintage;
publicpenson(){
super();
}
publicpenson(Stringname,intage){
super();
this.name=name;
this.age=age;
}
publicStringgetName(){
returnname;
}
publicvoidsetName(Stringname){
this.name=name;
}
publicintgetAge(){
returnage;
}
publicvoidsetAge(intage){
this.age=age;
}
publicStringtoString(){
return"penson[姓名:"+name+",年龄:"+age+"]";
}
}
classloyee{
privateintid;
privatedoublesalary;
publicloyee(){
super();
}
publicloyee(intid,doublesalary){
super();
}
publicintgetID(){
returnid;
}
publicvoidsetID(intiD){
id=iD;
}
publicdoublegetSalary(){
returnsalary;
}
publicvoidsetSalary(doublesalary){
this.salary=salary;
}
publicStringtoString(){
return"loyee[工号"+id+",工资:"+salary+"]";
}
}
classManager{
privateStringtype;
publicManager(){
super();
}
publicManager(Stringtype){
super();
this.type=type;
}
publicStringgetType(){
returntype;
}

publicvoidsetType(Stringtype){
this.type=type;
}
publicStringtoString(){
return"Manager[职务名称:"+type+"]";}
}

⑸ 用java定义一个Student类,如何操作

package com.tgyt.nzft.core.listview;

public class Student {

private String s_no;//学号
private String s_name;//姓名
private boolean isLeader;//班干部否
private String s_sex;//性别
private double s_shuxue;//数学
private double s_yuwen;//语文
private double s_waiyu;//外语

//学生信息录入
public void addStudentInfo(String s_no, String s_name, boolean isLeader, String s_sex,
double s_shuxue, double s_yuwen, double s_waiyu) {
this.s_no = s_no;
this.s_name = s_name;
this.isLeader = isLeader;
this.s_sex = s_sex;
this.s_shuxue = s_shuxue;
this.s_yuwen = s_yuwen;
this.s_waiyu = s_waiyu;
}

//获得总分
public double getTotal(){
return s_shuxue + s_yuwen + s_waiyu;
}

//平均分
public double getV(){
return getTotal() / 3;
}

public static void main(String[] args) {
Student student = new Student();
student.addStudentInfo("no_101", "女霸王", false, "女", 100, 35, 55);
System.out.println("总分:" + student.getTotal());
System.out.println("平局分:" + student.getTotal());
}
}

⑹ 编写JAVA程序 学生类Student

public class Student{
private String name;
private int xh;

public Student(){}
public Student(String name, String xh){
this.name = name;
this.xh = xh;
}
public String getName(){
return name;
}
public String getXh(){
return xh;
}
public void setName(String name){
this.name = name;
}
public void setXh(String xh){
this.xh = xh;
}
public void print(){
System.out.println("My name is "+name+",xh is"+xh+");
}
}

⑺ java设计一个Student类

publicclassStudent{

privateStringsName;
privateStringsClass;
privateStringsID;
Student(StringsID,StringsName)
{
this.sID=sID;
this.sName=sName;
}
Student(StringsID,StringsName,StringsClass)
{
this(sID,sName);
this.sClass=sClass;
}
publicStringtoString()
{
Stringret="";
if(sName!=null)
{
ret=ret+sName;
}
if(sID!=null)
{
ret=ret+"("+sID+",";
}else
{
ret=ret+"(,";
}
if(sClass!=null)
{
ret=ret+sClass+")";
}else
{
ret=ret和肢+")"唤猜世;
}
returnret;

}
publicStringgetsName()兆纤{
returnsName;
}
publicvoidsetsName(StringsName){
this.sName=sName;
}
publicStringgetsClass(){
returnsClass;
}
publicvoidsetsClass(StringsClass){
this.sClass=sClass;
}
publicStringgetsID(){
returnsID;
}
publicvoidsetsID(StringsID){
this.sID=sID;
}
}
publicclassStudentDemo{
publicstaticvoidmain(String[]args)
{
Student[]st=newStudent[5];
st[0]=newStudent("student0","id0","class0");
st[1]=newStudent("student1","id1","class1");
st[2]=newStudent("student2","id2","class2");
st[3]=newStudent("student3","id3","class3");
st[4]=newStudent("student4","id4","class4");

for(inti=0;i<st.length;i++)
{
System.out.println(st[i].toString());
}
}
}

⑻ java student类的创建

代码为Test.java

classstudent{
privateStringsno;
privateStringsname;
privateStringssex;
privateintage;

publicstudent(Stringsno,Stringsname,Stringssex,intage){
super();
this.sno=sno;
this.sname=sname;
this.ssex=ssex;
this.age=age;
}
publicvoidgetInfo(){
System.out.println("学号:"+this.sno+".姓名:"+this.sname
+".性别:"+this.ssex+".年龄:"+this.age);
}
publicvoidsetAge(intage){
this.age=age;
}
}
publicclassTest{
publicstaticvoidmain(String[]args){
studentstu=newstudent("s31","张三","男",20);
//获取学生信息
stu.getInfo();
//修改年龄
stu.setAge(30);
//获取修改后的学生信息
System.out.println("修改后的学生信息为:");
stu.getInfo();
}
}

⑼ java新建Student类,创建三个对象,使用对象年龄进行排序

  • 新建一个学生类

publicclassStudent{
privateStringname;
privateintage;


publicStudent(Stringname,intage){
this.name=name;
this.age=age;
}

publicStringtoString(){
return"Student[name="+name+",age="+age+"]";
}
publicStringgetName(){
returnname;
}
publicvoidsetName(Stringname){
this.name=name;
}
publicintgetAge(){
returnage;
}
publicvoidsetAge(intage){
this.age=age;
}

}
  • 然后新建一个测试类; 在测试类中,使用了2种方案进行排序,

importjava.util.ArrayList;
importjava.util.Comparator;

publicclassTest{
publicstaticvoidmain(String[]args){
ArrayList<Student>list=newArrayList<Student>();
list.add(newStudent("张三",9));
list.add(newStudent("李四",8));
list.add(newStudent("王五",10));
list.add(newStudent("赵六",7));
list.add(newStudent("田七",11));

sortFun1(list);
sortFun2(list);
}

//1:比较传统的方式仔旁贺
publicstaticvoidsortFun1(ArrayList<启磨Student>list){
System.out.println("从大到小排列念派");
list.sort(newComparator<Student>(){

@Override
publicintcompare(Studento1,Studento2){
return-(o1.getAge()-o2.getAge());//添加负号,从小到大
}
});
for(Studentstudent:list){
System.out.println(student);
}
}

//2.java8流处理方式
publicstaticvoidsortFun2(ArrayList<Student>list){
System.out.println("从小到大排列");
list.stream().sorted((o1,o2)->o1.getAge()-o2.getAge()).forEach(System.out::println);
}
}

⑽ JAVA创建学生类Student,学生姓名变量stuname,学生学号变量stunumber

public class StudentVo {
private String stuname;
private String stunumber;
private String stuclass;

public StudentVo(String stuname, String stunumber, String stuclass) {
this.stuname = stuname;
this.stunumber = stunumber;
this.stuclass = stuclass;
}
@Override
public String toString() {
return "StudentVo{" +
"我是'" + stuclass + '\'' +
"班级学生,我叫='" + stuname + '\'' +
", 学号为:'" + stunumber + '\'' +
'}';
}

public String getStuname() {
return stuname;
}

public void setStuname(String stuname) {
this.stuname = stuname;
}

public String getStunumber() {
return stunumber;
}

public void setStunumber(String stunumber) {
this.stunumber = stunumber;
}

public String getStuclass() {
return stuclass;
}

public void setStuclass(String stuclass) {
this.stuclass = stuclass;
}
}

热点内容
钉钉密码密码是什么 发布:2024-11-01 20:34:51 浏览:730
老款卡罗拉自动挡有哪些配置 发布:2024-11-01 20:34:06 浏览:570
android图片判断 发布:2024-11-01 20:34:03 浏览:267
怎么给自己手机写一个脚本 发布:2024-11-01 20:23:41 浏览:241
c语言大小写判断 发布:2024-11-01 20:21:53 浏览:130
php的点餐系统源码 发布:2024-11-01 20:13:53 浏览:714
拜占庭算法 发布:2024-11-01 20:10:31 浏览:357
xcode编译参数 发布:2024-11-01 20:00:04 浏览:665
苹果5怎么设置密码锁屏 发布:2024-11-01 19:54:55 浏览:124
宝塔上传文件夹 发布:2024-11-01 19:39:50 浏览:257