精华内容
下载资源
问答
  • JAVA定义学生类

    2012-10-25 15:50:37
    定义一个学生类,包括姓名,年龄。JAVA实现的,简单写了一个
  • package student; public class Student { private String name; private int age; public Student(){} public Student(String name,int age){ this.name=name; this.age=age; ...System.out.pr...
    package student;
    public class Student {
    	private String name;
    	private int age;
    	public Student(){}
    	public Student(String name,int age){
    		this.name=name;
    		this.age=age;
    	}
    	public void study(){
    		System.out.println("好好学习,天天向上。");
    	}
    	public void setName(String name){
    		this.name=name;
    	}
    	public String getName(){
    		return name;
    	}
    	public void setAge(int age){
    		this.age=age;
    	}
    	public int getAge(){
    		return age;
    	}
    	public static void main(String[] args)
    	{
    		Student s=new Student();
    		s.name="lele";
    		s.age=18;
    		System.out.println(s.name+s.age);
    		s.study();
    		Student s1=new Student("lena",19);
    		System.out.println(s1.getName()+s1.getAge());
    		s1.study();
    	}
    }
    
    展开全文
  • 这个也是在class Admin中的private static void avg(List data) {for (int i = 0; i < data.size(); i++) {List list = (List) data.get(i);double sum = 0.0;int year = 0;for (int j = 0; j <...

    这个也是在class Admin中的

    private static void avg(List data) {

    for (int i = 0; i < data.size(); i++) {

    List list = (List) data.get(i);

    double sum = 0.0;

    int year = 0;

    for (int j = 0; j < list.size(); j++) {

    Student s = (Student) list.get(j);

    sum += s.getChengji();

    year = s.getLevel();

    }

    System.out.println(year + "级平均成绩:" + (sum / list.size()));

    }

    }

    private static List group(List data) {

    int oldKey = 0;

    List result = new ArrayList();

    List list = null;

    for (int i = 0; i < data.size(); i++) {

    Student s = (Student) data.get(i);

    int newKey = s.getLevel();

    if (oldKey == newKey) {

    if (list == null) {

    list = new ArrayList();

    }

    list.add(s);

    } else {

    if (list != null) {

    result.add(list);

    list = null;

    }

    if (list == null) {

    list = new ArrayList();

    list.add(s);

    }

    oldKey = newKey;

    }

    }

    if (list != null) {

    result.add(list);

    }

    return result;

    }

    private static void sort(List data) {

    Collections.sort(data, new Comparator() {

    public int compare(Object o1, Object o2) {

    Student s1 = (Student) o1;

    Student s2 = (Student) o2;

    return (int) (s1.getChengji() - s2.getChengji());

    }

    });

    }

    private static void show(List data) {

    for (int i = 0; i < data.size(); i++) {

    System.out.println(data.get(i));

    }

    }

    展开全文
  • 匿名用户1级2018-01-12 回答import java.util.ArrayList;import java.util.Collections;import java.util.Comparator;import java.util.List;public class Admin {public static void main(String... args) {List ...

    匿名用户

    1级

    2018-01-12 回答

    import java.util.ArrayList;

    import java.util.Collections;

    import java.util.Comparator;

    import java.util.List;

    public class Admin {

    public static void main(String... args) {

    List data = new ArrayList();

    Student s0 = new Student();

    s0.setNo("000");

    s0.setName("a");

    s0.setChengji(100.0);

    data.add(s0);

    Student s1 = new Student();

    s1.setNo("001");

    s1.setName("b");

    s1.setChengji(99.0);

    data.add(s1);

    Student s2 = new Student();

    s2.setNo("002");

    s2.setName("c");

    s2.setChengji(98.0);

    data.add(s2);

    System.out.println("排序前");

    show(data);

    System.out.println("排序后");

    sort(data);

    show(data);

    }

    private static void sort(List data) {

    Collections.sort(data, new Comparator() {

    public int compare(Object o1, Object o2) {

    Student s1 = (Student) o1;

    Student s2 = (Student) o2;

    return (int) (s1.getChengji() - s2.getChengji());

    }

    });

    }

    private static void show(List data) {

    for (int i = 0; i < data.size(); i++) {

    System.out.println(data.get(i));

    }

    }

    }

    class Student {

    private String no;

    private String name;

    private double chengji;

    public double getChengji() {

    return chengji;

    }

    public void setChengji(double chengji) {

    this.chengji = chengji;

    }

    public String getName() {

    return name;

    }

    public void setName(String name) {

    this.name = name;

    }

    public String getNo() {

    return no;

    }

    public void setNo(String no) {

    this.no = no;

    }

    public String toString() {

    return "学号:" + no + ",姓名:" + name + ",成绩:" + chengji;

    }

    }

    结果

    排序前

    学号:000,姓名:a,成绩:100.0

    学号:001,姓名:b,成绩:99.0

    学号:002,姓名:c,成绩:98.0

    排序后

    学号:002,姓名:c,成绩:98.0

    学号:001,姓名:b,成绩:99.0

    学号:000,姓名:a,成绩:100.0

    追问:

    那这个呢。。。麻烦了~! 定义一个学生类(姓名、学号、性别、分数)。构建一个向量对象,在里面存放20个学生信息。按照学号找出2009级学生的成绩平均值、2008级学生的平均值,2010级学生的成绩平均值。

    追答:

    字数太多了,一次传不上去,你追问吧,我一次给你一点,你自己合一下

    public static void main(String... args) {

    List data = new ArrayList();

    Student s0 = new Student();

    s0.setNo("000");

    s0.setLevel(2009);

    s0.setName("a");

    s0.setChengji(100.0);

    data.add(s0);

    Student s1 = new Student();

    s1.setNo("001");

    s1.setLevel(2009);

    s1.setName("b");

    s1.setChengji(99.0);

    data.add(s1);

    Student s2 = new Student();

    s2.setNo("002");

    s2.setLevel(2008);

    s2.setName("c");

    s2.setChengji(98.0);

    data.add(s2);

    Student s3 = new Student();

    s3.setNo("003");

    s3.setLevel(2008);

    s3.setName("d");

    s3.setChengji(97.0);

    data.add(s3);

    System.out.println("排序前");

    show(data);

    System.out.println("排序后");

    sort(data);

    show(data);

    // 按照学号找出2009,2008,2007级学生的成绩平均值

    // 从学号判断有点麻烦,加个属性level入学年份

    data = group(data);

    avg(data);

    }

    追问:

    嗯嗯嗯

    追答:

    这个也是在class Admin中的

    private static void avg(List data) {

    for (int i = 0; i < data.size(); i++) {

    List list = (List) data.get(i);

    double sum = 0.0;

    int year = 0;

    for (int j = 0; j < list.size(); j++) {

    Student s = (Student) list.get(j);

    sum += s.getChengji();

    year = s.getLevel();

    }

    System.out.println(year + "级平均成绩:" + (sum / list.size()));

    }

    }

    private static List group(List data) {

    int oldKey = 0;

    List result = new ArrayList();

    List list = null;

    for (int i = 0; i < data.size(); i++) {

    Student s = (Student) data.get(i);

    int newKey = s.getLevel();

    if (oldKey == newKey) {

    if (list == null) {

    list = new ArrayList();

    }

    list.add(s);

    } else {

    if (list != null) {

    result.add(list);

    list = null;

    }

    if (list == null) {

    list = new ArrayList();

    list.add(s);

    }

    oldKey = newKey;

    }

    }

    if (list != null) {

    result.add(list);

    }

    return result;

    }

    private static void sort(List data) {

    Collections.sort(data, new Comparator() {

    public int compare(Object o1, Object o2) {

    Student s1 = (Student) o1;

    Student s2 = (Student) o2;

    return (int) (s1.getChengji() - s2.getChengji());

    }

    });

    }

    private static void show(List data) {

    for (int i = 0; i < data.size(); i++) {

    System.out.println(data.get(i));

    }

    }

    展开全文
  • 1、定义学生类Student,包含学号、姓名、成绩三个属性,默认构造方法、带参数构造方法; 2、Student类实现Comparable接口,并实现compareTo方法(按照成绩属性比较大小); 3、定义测试类,创建5个学生对象,并使用...

    第9章 对象和类

    第10章 面对对象思考

    第11章 继承和多态

    第12章 异常处理和文本I/O

    第13章 抽象类和对象

    主要:实现Comparable接口

    题目描述:作业内容要求:

    1、定义学生类Student,包含学号、姓名、成绩三个属性,默认构造方法、带参数构造方法;

    2、Student类实现Comparable接口,并实现compareTo方法(按照成绩属性比较大小);

    3、定义测试类,创建5个学生对象,并使用Arrays.sort()方法对5个学生对象排序。

    可能的Java代码:

    /**
     *  方便输入和测试的原因,把属性  姓名和学号  给隐藏忽略输入了,需要的自己改下  几个null值为name1、mark1.....mark4。   
     */
    /**
     * @author XXXXX
     *  2、Student类实现Comparable接口,并实现compareTo方法(按照成绩属性比较大小);---->这句话后面一句不懂  
     * 
     */
     //暂时不想改了,出了错误,只满足第二局前一部分,后一部分,有可能在Student类中实现????应该不是在Student类中实现实现Comparable接口吧。。。。。。那样的话,怎么实现ComparableStudent???最多在Student类实现compareTo方法(按照成绩属性比较大小),然后在ComparableStudent类中实现Comparable接口吧。。。。。。。。。。。。
    import java.util.Scanner;
    	public class Main
    	{
    		
    		public static void main(String[] args) {
    			Scanner sc=new Scanner(System.in);
    			
    			/*System.out.print("Enter the mark of Student1: ");
    			String mark1=sc.next();
    			System.out.print("Enter the name of Student1: ");
    			String name1=sc.next();*/
    			System.out.print("Enter the grade of Student1: ");
    			double grade1=sc.nextDouble();
    			
    			/*System.out.print("Enter the mark of Student2: ");
    			String mark2=sc.next();
    			System.out.print("Enter the name of Student2: ");
    			String name2=sc.next();*/
    			System.out.print("Enter the grade of Student2: ");
    			double grade2=sc.nextDouble();
    			
    			/*System.out.print("Enter the mark of Student3: ");
    			String mark3=sc.next();
    			System.out.print("Enter the name of Student3: ");
    			String name3=sc.next();*/
    			System.out.print("Enter the grade of Student3: ");
    			double grade3=sc.nextDouble();
    			
    			/*System.out.print("Enter the mark of Student4: ");
    			String mark4=sc.next();
    			System.out.print("Enter the name of Student4: ");
    			String name4=sc.next();*/
    			System.out.print("Enter the grade of Student4: ");
    			double grade4=sc.nextDouble();
    			
    			/*System.out.print("Enter the mark of Student5: ");
    			String mark5=sc.next();
    			System.out.print("Enter the name of Student5: ");
    			String name5=sc.next();*/
    			System.out.print("Enter the grade of Student5: ");
    			double grade5=sc.nextDouble();							
                System.out.println();	
                
    				ComparableStudent student1=new ComparableStudent(null, null, grade1);
    				ComparableStudent student2=new ComparableStudent(null, null, grade2);
    				ComparableStudent student3=new ComparableStudent(null, null, grade3);
    				ComparableStudent student4=new ComparableStudent(null, null, grade4);
    				ComparableStudent student5=new ComparableStudent(null, null, grade5);	
    				
    				ComparableStudent student6 = (ComparableStudent)Max.max(student1, student2);
    				ComparableStudent student7 = (ComparableStudent)Max.max(student3, student4);
    				ComparableStudent student8 = (ComparableStudent)Max.max(student6, student7);
    				
    				ComparableStudent student9 = (ComparableStudent)Max.max(student5, student8);
    								
    				System.out.println("The Student1's Grade is " + student1.getGrade());
    				System.out.println("The Student2's Grade is " + student2.getGrade());
    				System.out.println("The Student3's Grade is " + student3.getGrade());
    				System.out.println("The Student4's Grade is " + student4.getGrade());
    				System.out.println("The Student5's Grade is " + student5.getGrade());
    				System.out.println();
    				
    				ComparableStudent[] students= {
    						new ComparableStudent(null, null, grade1),
    						new ComparableStudent(null, null, grade2),
    						new ComparableStudent(null, null, grade3),
    						new ComparableStudent(null,null, grade4),
    						new ComparableStudent(null, null, grade5),
    				};
    				
    				java.util.Arrays.sort(  students);
    				
    				for(Student student:students) 
    				{
    					System.out.println(student.getGrade());
    				}
    		}
    	}
    
    	class Student
    	{
    		String  mark;
    		String  name;
    		double  grade;
    		Student()
    		{
    			
    		}
    			
    		Student(String  mark,String name,double grade)
    		{
    			this.mark=mark;
    			this.name=name;
    			this.grade=grade;
    		}
    		
    		void setMark(){
    			this.mark=mark;			
    		}
    		public String getMark(String mark){
    			return mark;
    		}
    		void setNamek(){
    			this.name=name;			
    		}
    		public String getName(String name){
    			return name;
    		}
    		void setGrade(){
    			this.grade=grade;			
    		}
    		public double getGrade(){
    			return grade;
    		}
    		
    	}
    	
    	class ComparableStudent extends Student implements Comparable
    	{
    		
    		public ComparableStudent(String  mark,String name,double grade)
    		{
    			super(mark, name, grade);
    		}
    		
    		public int compareTo(Object  o)
    		{
    			if(getGrade()>((Student) o).getGrade())
    			{	
    				return 1;	
    			}
    			
    			else if(getGrade()<((Student) o).getGrade())
    			{	
    				return -1;	
    			}
    			else
    			{
    				return 0;
    			}
    
    		}
    		//@Override
    		public String toString() 
    		{
    			return super.toString()+"mark: "+getMark(mark)+" name"+getName(name)+"grade:" +getGrade();
    			/输出只有成绩,没有学号和姓名
    		}
    }
    	class Max
    	{
    		public static ComparableStudent max(ComparableStudent o1, ComparableStudent o2)
    		{
    			if (o1.compareTo(o2) > 0)
    				return o1;
    			else
    				return o2;
    		}
    		
    	}	
    

    样例运行结果:
    在这里插入图片描述

    END

    展开全文
  • } }import java.util.Scanner; public class main { public static void main(String[] args) { Scanner scan=new Scanner(System.in); System.out.print("输入学生的人数:"); int number = scan....
  • 求解JAVA定义一个课程类和一个学生类和测试类mip版关注:152答案:1悬赏:0解决时间 2021-01-28 06:31已解决2021-01-27 21:33课程类中包含:属性:课程的名称和成绩方法:属性的get/set方法学生类中包含:属性:学生...
  • /*定义一个,来模拟“学生”属性 (是什么)姓名年龄行为(能做什么)吃饭睡觉学习对应到Java当中成员变量(属性)String nanme; //姓名成员方法(行为)//成员方法不要staticpublic viod eat(){}public viod sleep(){...
  • 匿名用户3级2009-10-08 回答import java.util.Scanner;public class Student1{private String name;private int computer_score;private int english_score;private int maths_score;public void setName(String ...
  • } /** * @param sJava * the sJava to set */ public void setsJava(int sJava) { this.sJava = sJava; } /** * @param sNo * @param sName * @param sSex * @param sAge * @param sJava */ ...
  • 得分:10 1、“在中设置一个变量来记录共有多少个学生,即共为该生成多少个实例”,这个变量应该是静态的,并且在构造函数中进行加12、“重载输入/输出成员函数以便输入/输出新添加的数据”,不同类型的学生输入...
  • 展开全部1:packagewo;-publicclassStudentText{publicstaticvoidmain(String[]args){32313133353236313431303231363533e59b9ee7ad9431333363386135Students1=newStudent(01,"张三");Students2=newStudent(02,"...
  • 编写一个JAVA程序片断定义一个表示学生student,包括域"学号","班级","姓名","性别","年龄";方法"获得学号","获得班号","获得姓名","获得性别","获得年龄","修改年龄"、程序如下:import java、lang、String;...
  • 编写一个JAVA程序片断定义一个表示学生student,包括域"学号","班级","姓名","性别","年龄";方法"获得学号","获得班号","获得姓名","获得性别","获得年龄","修改年龄".程序如下:import ...
  • (2)编写一个学生类,它的成员变量有考生的name(姓名)、id(考号)、intgretResult(综合成绩).它还有获取学生的综合成绩和体育成绩的方法 (3)编写一个录取类。它的一个方法用于判断学生是否符合录取条件。其中录取条件为...
  • 展开全部importjava.util.Comparator;publicclassStudentimplementsComparable{privateintno;privateStringname;privateStringsex;privateintroomNo;privatedoublescore;publicStudent(intno,String...
  • 实现学生类定义,大学生类的定义,并测试学生类,输出学生信息
  • }再定义一个实现public class Test_1 implements Test {public void getFlunk() {//你要进行的操作,如获取对象,再输出你要的东西呀}}或是定义一个public class Test {void getFlunk(){ }List setStu()...
  • 创建一个表示学生的实体类 ...首先定义一个名为 Student 的类,代码如下:public class Student { // 学生类 }在类中通过属性定义学生、性别和年龄,代码如下:public class Student { public String Name; // 学...
  • 如下所示:public class Student {private int sNo; //学号private String name; //姓名private String sex; //性别private int yu; //语文private int shu; //数学private int wai; //外语public int getsNo() {...
  • 编写一个JAVA程序片断 定义一个表示学生student,包括域"学号","班级","姓名","性别","年龄";方法"获得学号","获得班号","获得姓名","获得性别","获得年龄","修改年龄".程序如下:import java.lang.String;import ...
  • /**编写一个Java应用程序,该程序包括3个类:定义一个学生类,Student有姓名,学32313133353236313431303231363533e59b9ee7ad9431333366306463号,选学的课程列表定义一个课程类:课程名称,课程分...
  • Java是一个纯的面向对象的程序设计语言,它继承了 C++ 语言面向对象技术的核心,Java舍弃了C ++语言中容易引起错误的指针(以引用取代)、运算符重载(operator overloading)、多重继承(以接口取代)等特性,增加了垃圾...
  • 男孩:定义,对象的定义中的方法,构造方法,this关键字,方法的重载,Java中的的访问权限,set和get方法,static关键字~面向对象设计思想设计思想的变化例如:学生行为对于结构化程序设计:起床,洗脸,...
  • 匿名用户 1级 2015-09-28 回答 直接给出具体代码 public class StudentDto implements Serializable { private static final long ... 创建实体主要是参数的命名合理,类型合理以及提供一些必要的方法。
  • /** 编写一个Java应用程序,该程序包括3个类: 定义一个学生类,Student有姓名,学号,选学的课程列表 定义一个课程类:课程名称,课程分数 (1)初始化一个学生,...答:学生类: public class Student{ private ...
  • 本文为大家分享了java泛型类的定义与使用的具体代码,供大家参考,具体内容如下...class Student { //定义学生类public String st = "student";}class Worker { //定义工人类public String wo = "worker";}//定义泛...
  • java设计学生类

    2020-08-26 22:13:13
    设计一个学生类 (1)Student类中包含姓名、成绩两个属性 (2分别给这两个属性定义两个方法,一个方法用于设置值,另一个方法用于获取值。 (3)Student类中定义一个无参的构造方法和一个接收两个参数的构造方法,两个...
  • JAVA学生类Student

    千次阅读 2019-12-09 17:07:58
    学生类Student 编写Java应用程序。首先,定义描述学生的类——Student,包括学号(int)、姓名(String)、年龄(int)等属性;二个方法:Student(int stuNo,String name,int age)用于对对象的初始化,outPut()用于...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 2,047
精华内容 818
关键字:

java定义学生类

java 订阅