當前位置:首頁 » 編程語言 » 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;
}
}

熱點內容
java數組包含字元串 發布:2024-11-01 22:31:15 瀏覽:791
伺服器和家用電腦質量 發布:2024-11-01 22:28:29 瀏覽:488
sqlserver默認實例 發布:2024-11-01 22:23:42 瀏覽:959
sort排序java 發布:2024-11-01 22:23:26 瀏覽:47
解壓後的apk無法安裝 發布:2024-11-01 22:22:10 瀏覽:666
公司的pop伺服器地址 發布:2024-11-01 22:22:07 瀏覽:119
朵唯m30手機配置是真的嗎如何 發布:2024-11-01 22:16:56 瀏覽:681
夢幻西遊怎麼清理緩存 發布:2024-11-01 22:15:52 瀏覽:344
如何配置fcm 發布:2024-11-01 22:08:15 瀏覽:854
原裝電腦配置哪個好 發布:2024-11-01 22:05:49 瀏覽:729