當前位置:首頁 » 考試成績 » 定義學生類student有三個屬性成績

定義學生類student有三個屬性成績

發布時間: 2021-01-17 00:39:48

Ⅰ 求一道編程題。我創建了學生類。定義了3個欄位。名稱,成績。和總成績。但是編寫的求和方法為什麼只能。

Sum函數不要這樣寫嘛,給它傳個參數,傳1就計算第1次的返回,傳2就計算第2次的返回

Ⅱ 定義一個學生類,有姓名,學號,成績(int類型)三個屬性 求大神幫助啊!謝謝各位

importjava.util.ArrayList;
importjava.util.Collections;
importjava.util.List;

publicclassSorter{

publicstaticvoidmain(String[]args){

<Student>students=newArrayList<Student>();

Studentstudent1=newStudent();
student1.id="1";
student1.name="張三";
student1.score=60;
students.add(student1);

Studentstudent2=newStudent();
student2.id="2";
student2.name="李四";
student2.score=70;
students.add(student2);

Studentstudent3=newStudent();
student3.id="3";
student3.name="王二";
student3.score=80;
students.add(student3);

Collections.sort(students);

for(Studentstudent:students){
System.out.println("編號:"+student.id+",姓名:"+student.name+",成績:"+student.score);
}

}

}

<Student>{

publicStringid;
publicStringname;
publicintscore;

@Override
publicintcompareTo(Studento){
if(score>o.score){
return-1;
}elseif(score<o.score){
return1;
}
return0;
}

}

Ⅲ 定義一個學生類,包含學號、姓名和總分三個屬性,要求創建5個學生對象,並查找總分大於200分學生的信息

import java.util.Scanner;

class Students{
protected int sid; //學號
protected String name; //姓名
protected double score; //總分

public Students(){
}

public Students(int sid, String name, double score){
this.sid = sid;
this.name = name;
this.score = score;
}

public double getScore(){
return this.score;
}

public void display(){
System.out.println("學號:" + sid);
System.out.println("姓名:" + name);
System.out.println("總分:" + score);
}
}
public class Test26 {
public static void main(String[] args) {
Students[] studs = new Students[5];
int i;
int sid;
String name;
double score;
Scanner scan = new Scanner(System.in);

System.out.println("添加學生信息");
for(i=0; i<studs.length; i++){
System.out.print("學號:");
sid = scan.nextInt();
System.out.print("姓名:");
name = scan.next();
System.out.print("總分:");
score = scan.nextDouble();
studs[i] = new Students(sid, name, score);
}

System.out.println("總分大於200分學生的信息");
for(i=0; i<studs.length; i++){
if(studs[i].getScore() > 200){
studs[i].display();
}
}
}
}

Ⅳ 定義一個學生類, 需要有姓名, 年齡, 考試成績三個成員屬性. 屬性(成員變數)需要私有並提供get, set方法.

public class Student {

內private String name ;
private int age;
private double Exam;
public String getName() {
容return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public double getExam() {
return Exam;
}
public void setExam(double exam) {
Exam = exam;
}

}

Ⅳ java:定義學生類Student, 其中屬性有 name, id, score ,分別表示姓名,學好,成績.....

定義一個表示學生信息的類Student,要求如下:

(1)類Student的成員變數:

sNO表示學號;sName表示姓名;sSex表示性別;表示年齡;sJava:表示Java課程成績。

(2)類Student帶參數的構造方法:

在構造方法中通過形參完成對成員變數的賦值操作。

(3)類Student的方法成員:

getNo():獲得學號;

getName():獲得姓名;

getSex():獲得性別;

getAge()獲得年齡;

getJava():獲得Java課程成績

(4)根據類Student的定義,創建五個該類的對象,輸出每個學生的信息,計算並輸出這五個學生Java語言成績的平均值,以及計算並輸出他們Java語言成績的最大值和最小值。*/

Ⅵ 定義一個學生類,需要有姓名,年齡,考試成績三個成員屬性,創建5個對象,屬性可以任意值。OC

.h文件

#import <Foundation/Foundation.h>

@interface Student : NSObject
{
NSString *name;
int age;
float score;
}
-(void)setName:(NSString *)newname;
-(NSString *)name;
-(void)setAge:(int)newage;
-(int)age;
-(void)setScore:(float)newscore;
-(float)score;
-(Student *)initWithName:(NSString *)newname andAge:(int)newage andScore:(float)newscore;
+(Student *)studentWithName:(NSString *)newname andAge:(int)newage andScore:(float)newscore;
-(NSComparisonResult)compareWithScore:(Student *)stu;
-(NSComparisonResult)compareWithAge:(Student *)stu;
-(NSComparisonResult)compareWithName:(Student *)stu;
@end

Student.m文件

  • #import "Student.h"

    @implementation Student
    -(void)setName:(NSString *)newname{
    name=newname;
    }
    -(NSString *)name{
    return name;
    }
    -(void)setAge:(int)newage{
    age=newage;
    }
    -(int)age{
    return age;
    }
    -(void)setScore:(float)newscore{
    score=newscore;
    }
    -(float)score{
    return score;
    }
    -(Student *)initWithName:(NSString *)newname andAge:(int)newage andScore:(float)newscore{
    self=[super init];
    if (self) {
    name=newname;
    age=newage;
    score=newscore;
    }
    return self;
    }
    +(Student *)studentWithName:(NSString *)newname andAge:(int)newage andScore:(float)newscore{
    Student *stu=[[Student alloc]initWithName:newname andAge:newage andScore:newscore];
    return stu;
    }
    -(NSComparisonResult)compareWithScore:(Student *)stu{
    NSComparisonResult result1;
    if (self.score>stu.score) {
    return NSOrderedDescending;
    }
    else if (self.score<stu.score){
    return NSOrderedAscending;
    }
    else{
    return NSOrderedSame;
    }
    return result1;
    }
    -(NSComparisonResult)compareWithAge:(Student *)stu{
    NSComparisonResult result2;
    if (self.age>stu.age) {
    return NSOrderedDescending;
    } else if(self.age<stu.age){
    return NSOrderedAscending;
    }
    else{
    return NSOrderedSame;
    }
    return result2;
    }
    -(NSComparisonResult)compareWithName:(Student *)stu{
    return [self.name compare:stu.name];
    }
    -(NSString *)description{
    NSString *str=[NSString stringWithFormat:@"%f,%d,%@",score,age,name];
    return str;
    }

    @end

    測試代碼

Student *stu=[Student new];
[stu setScore:65.5];
[stu setAge:21];
[stu setName:@"zhangsan"];
Student *stu1=[Student new];
[stu1 setScore:70.3];
[stu1 setAge:19];
[stu1 setName:@"lisi"];
Student *stu2=[Student new];
[stu2 setScore:56.5];
[stu2 setAge:18];
[stu2 setName:@"wangwu"];
Student *stu3=[Student new];
[stu3 setScore:85.6];
[stu3 setAge:25];
[stu3 setName:@"mingming"];
Student *stu4=[Student new];
[stu4 setScore:95.4];
[stu4 setAge:20];
[stu4 setName:@"xionghong"];
NSArray *stuArr=[NSArray arrayWithObjects:stu,stu1,stu2,stu3,stu4, nil];
NSArray *sortArr=[stuArr sortedArrayUsingSelector:@selector(compareWithScore:)];
NSLog(@"按成績排序後:");
for (int i=0; i<sortArr.count; i++) {
Student *a=[sortArr objectAtIndex:i];
NSLog(@"Myname is %@,age is %d,score is %f",a.name,a.age,a.score);
}
NSArray *sortArr1=[stuArr sortedArrayUsingSelector:@selector(compareWithAge:)];
NSLog(@"按年齡排序後:");{
for (int i=0; i<sortArr1.count; i++) {
Student *a=[sortArr1 objectAtIndex:i];
NSLog(@"Myname is %@,age is %d,score is %f",a.name,a.age,a.score);
}
}
NSArray *sortArr2=[stuArr sortedArrayUsingSelector:@selector(compareWithName:)];
NSLog(@"按姓名排序後:");{
for (int i=0; i<sortArr2.count; i++) {
Student *a=[sortArr2 objectAtIndex:i];
NSLog(@"Myname is %@,age is %d,score is %f",a.name,a.age,a.score);
}
}

Ⅶ 定義一個學生類,需要有姓名,年齡,考試成績三個成員屬性,創建5個對象,屬性可以任意值。(Objective-C

  1. 創建一個Obj,設置obj的三個屬性(string類型):姓名、年齡、成績;

  2. 給obj每個屬性賦值的時候,重寫每個屬性的set、get、方法;

  3. 賦值完成後,存入數組;

  4. 查詢的時候寫個排序演算法,輸出列印

Ⅷ 【java】定義學生類,包含三個屬性:學號,成績,及入學日期(日期也為類【急求!!】

最簡單的就是重寫學生類的 equals() 和 hashCode() 以 入學日期為關鍵欄位, 然後調用Arrays.sort() 方法, 默認就是升序排序

Ⅸ 定義一個學生類, 需要有姓名, 年齡, 考試成績三個成員屬性

public class Student {
private String name;private int age;private double score;public Student(String name,int age,double score){
this.name=name;
this.age=age;
this.score=score;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}

Ⅹ 定義一個表示學生的類(Student) Student類包括表示學生的學號姓名性別年齡和3門課程成績的信息數據及

這是學生類:
public class Student {

private int xuehao;

private String xingming;

private String xingbie;

private int shuxue;

private int yuwen;

private int yingyu;

public int getShuxue() {
return shuxue;
}

public void setShuxue(int shuxue) {
this.shuxue = shuxue;
}

public String getXingbie() {
return xingbie;
}

public void setXingbie(String xingbie) {
this.xingbie = xingbie;
}

public String getXingming() {
return xingming;
}

public void setXingming(String xingming) {
this.xingming = xingming;
}

public int getXuehao() {
return xuehao;
}

public void setXuehao(int xuehao) {
this.xuehao = xuehao;
}

public int getYingyu() {
return yingyu;
}

public void setYingyu(int yingyu) {
this.yingyu = yingyu;
}

public int getYuwen() {
return yuwen;
}

public void setYuwen(int yuwen) {
this.yuwen = yuwen;
}

public int average(int x,int y,int z){

return (x+y+z)/3;

}

}

這是測試類:
public class TestStudent{
public static void main(String args[]) {
Student st1=new Student();
st1.setShuxue(75);
st1.setYingyu(80);
st1.setYuwen(85);
System.out.println("第一個學生的平均成績為:"+st1.average(st1.getShuxue(),st1.getYingyu(),st1.getYuwen()));
Student st2=new Student();
Student st3=new Student();
Student st4=new Student();
Student st5=new Student();

}

}
你要求5個學生對象,我寫出一個,後面的依次類推.應該會吧.

熱點內容
武漢大學學生會輔導員寄語 發布:2021-03-16 21:44:16 瀏覽:612
七年級學生作文輔導學案 發布:2021-03-16 21:42:09 瀏覽:1
不屑弟高考成績 發布:2021-03-16 21:40:59 瀏覽:754
大學畢業證會有成績單 發布:2021-03-16 21:40:07 瀏覽:756
2017信陽學院輔導員招聘名單 發布:2021-03-16 21:40:02 瀏覽:800
查詢重慶2018中考成績查詢 發布:2021-03-16 21:39:58 瀏覽:21
結業考試成績怎麼查詢 發布:2021-03-16 21:28:40 瀏覽:679
14中醫醫師資格筆試考試成績查分 發布:2021-03-16 21:28:39 瀏覽:655
名著賞析課程標准 發布:2021-03-16 21:27:57 瀏覽:881
北京大學商業領袖高端培訓課程 發布:2021-03-16 21:27:41 瀏覽:919