当前位置:首页 » 编程语言 » java学生类

java学生类

发布时间: 2022-07-27 08:59:09

java创建一个学生类


publicclassTest{

publicstaticvoidmain(String[]args){
ArrayList<Student>studentList=newArrayList<>();
studentList.add(newStudent("张三","class1","Java",85));
studentList.add(newStudent("周乐儿","class1","C#",79));
studentList.add(newStudent("王涛","class2","C#",52));
studentList.add(newStudent("李明","class2","Java",48));
//===========================================================================
System.out.println("姓名 班级名 课程名 考试成绩");
for(Studentstudent:studentList){
System.out.println(student);
}
//===========================================================================
floatclass1SumScore=0;
intclass1StudentCount=0;
for(Studentstudent:studentList){
if(student.isClass1()){
class1SumScore+=student.getScore();
class1StudentCount++;
}
}
System.out.println(" class1班的总分:"+class1SumScore+" 平均分:"+class1SumScore/class1StudentCount);
//===========================================================================
floatjavaScore=0;
floatjavaStudentCount=0;
floatcSharpScore=0;
floatcSharpStudentCount=0;
for(Studentstudent:studentList){
if(student.isJava()){
javaScore+=student.getScore();
javaStudentCount++;
}elseif(student.isCSharp()){
cSharpScore+=student.getScore();
cSharpStudentCount++;
}
}
System.out.println(" Java课程的平均分:"+javaScore/javaStudentCount+" C#课程的平均分:"+cSharpScore/cSharpStudentCount);
}
}

classStudent{
privateStringname;
privateStringclassName;
privateStringcourseName;
privateintscore;

publicStudent(Stringname,StringclassName,StringcourseName,intscore){
this.name=name;
this.className=className;
this.courseName=courseName;
this.score=score;
}

publicbooleanisClass1(){
return"class1".equals(className);
}

publicbooleanisJava(){
return"Java".equals(courseName);
}

publicbooleanisCSharp(){
return"C#".equals(courseName);
}

publicStringgetName(){
returnname;
}

publicStringgetClassName(){
returnclassName;
}

publicStringgetCourseName(){
returncourseName;
}

publicintgetScore(){
returnscore;
}

@Override
publicStringtoString(){
returnname+" "+className+" "+courseName+" "+score;
}
}

❷ java编写程序创建学生类

年龄、性别等 方法:爱好方法等等 2.创建2个学生子类

❸ JAVA创建一个学生类

public class Student {
private String id;
private String name;
private int age;
private String sex;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
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 String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
}
public class StudentToDo {
/**
* 吃饭方法
*/
public void eat(Student student){
System.out.println("id"+student.getId()+"年龄为"+student.getAge()+"性别是"+student.getSex()+"姓名叫"+student.getName()+"的学生在吃饭");
}
/**
* 打豆豆方法
*/
public void play(Student student){
System.out.println("id"+student.getId()+"年龄为"+student.getAge()+"性别是"+student.getSex()+"姓名叫"+student.getName()+"的学生在打豆豆");
}
}
public class Test {
public static void main(String[] args) {
StudentToDo studentToDo = new StudentToDo();
Student student = new Student();
student.setId("1");
student.setAge(15);
student.setName("张三");
student.setSex("男");
studentToDo.eat(student);
studentToDo.play(student);
}
}

❹ JAVA程序编写一个学生类Student

Public Class Student{
Public long id;
Public String name;
Public int age;
Public boolean sex;
Public long phone;
Public Student(long i,String n,int a,boolean s,long p){
this.id = i;
this.name = n;
this.age = a;
this.sex = s;
this.phone = p;
}
Public int getage(){
return this.age;
}
Public long getphone(){
return this.phone;
}
Public String toString(){
return this.name;
}
Public static void main(String[]args){
Student student = new Student(01,"李明",20,true,13xxx);
System.out.println(student.age());
System.out.println(student.getphone());
System.out.println(student.toString());
}
}

❺ 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创建一个具体的学生类

//学生类
public class Student{
private String stu_id;
private String stu_name;
private float math;
private float chinese;
private float computer;

public void setStu_id(String stu_id){
this.stu_id=stu_id;
}
public String getStu_id(){
return stu_id;
}
public void setStu_name(String stu_name){
this.stu_name=stu_name;
}
public String getStu_name(){
return stu_name;
}
public void setMath(float math){
this.math=math;
}
public float getMath(){
return math;
}
public void setChinese(float chinese){
this.chinese=chinese;
}
public float getChinese(){
return chinese;
}
public void setComputer(float computer){
this.computer=computer;
}
public float getComputer(){
return computer;
}

}

//主方法的类
public class Start{
public static void main(String[] args){
Student stu1=new Student();
stu1.setStu_id("No1");
stu1.setStu_name("张三");
stu1.setMath(89.5f);
stu1.setChinese(70f);
stu1.setComputer(98f);
Student stu2=new Student();
stu2.setStu_id("No2");
stu2.setStu_name("李四");
stu2.setMath(79.5f);
stu2.setChinese(90f);
stu2.setComputer(68f);
float stu1Sum = stu1.getMath()+stu1.getChinese()+stu1.getComputer();
float stu2Sum = stu2.getMath()+stu2.getChinese()+stu2.getComputer();
if(stu1Sum > stu2Sum){
System.out.println ("总分最高分为:"+stu1Sum);
System.out.println ("学号:"+stu1.getStu_id());
System.out.println ("姓名:"+stu1.getStu_name());
System.out.println ("数学:"+stu1.getMath());
System.out.println ("语文:"+stu1.getChinese());
System.out.println ("计算机:"+stu1.getComputer());
}else if(stu1Sum < stu2Sum){
System.out.println ("总分最高分为:"+stu2Sum);
System.out.println ("学号:"+stu2.getStu_id());
System.out.println ("姓名:"+stu2.getStu_name());
System.out.println ("数学:"+stu2.getMath());
System.out.println ("语文:"+stu2.getChinese());
System.out.println ("计算机:"+stu2.getComputer());
}else{
System.out.println ("总分一样高为:"+stu1Sum);
System.out.println ("学号:"+stu1.getStu_id());
System.out.println ("姓名:"+stu1.getStu_name());
System.out.println ("数学:"+stu1.getMath());
System.out.println ("语文:"+stu1.getChinese());
System.out.println ("计算机:"+stu1.getComputer());
System.out.println ("学号:"+stu2.getStu_id());
System.out.println ("姓名:"+stu2.getStu_name());
System.out.println ("数学:"+stu2.getMath());
System.out.println ("语文:"+stu2.getChinese());
System.out.println ("计算机:"+stu2.getComputer());
}
}
}

希望对你有帮助!

❼ java作业求设计一个学生类

不难,就是费时间

❽ 在java中编写程序,定义一个学生类

代码如下:

package exam2;

import java.util.ArrayList;

import java.util.List;

/**

编写一个Java应用程序,该程序包括3个类:

定义一个学生类,Student有姓名,学号,选学的课程列表

定义一个课程类:课程名称,课程分数

(1)初始化一个学生,选择了三门课程,并添加到学生的属性中

(2)实现统计学生的总分功能

1.正确编写2个类(5分)

2.统计学生的总分功能(5分)

*/

public class Test {

public static void main(String[] args) {

List<Course> courses = new ArrayList<>();

// 初始化3门课程及分数

Course course1 = new Course("java", 80);

Course course2 = new Course("Math", 60);

Course course3 = new Course("English", 90);

// 课程对象添加到集合

courses.add(course1);

courses.add(course2);

courses.add(course3);

// 初始化学生对象

Student student = new Student("tom", "2015101", courses);

// student.setStuid("2015101");

// student.setStuname("tom");

// student.setCourses(courses);

// System.out.println(student);

// (2)实现统计 学生 的总分功能

int sum = sumScore(courses);

System.out.println(student.getStuname() + "学生总分:" + sum);

}

private static int sumScore(List<Course> courses) {

int sum = 0;

// 用课程对象,来获取课程的分数

for (Course course : courses) {

sum += course.getScore();

}

return sum;

}

}

package exam2;

import java.util.List;

public class Student {

// 定义一个学生类,Student有姓名,学号,选学的课程列表

private String stuname;

private String stuid;

private List<Course> courses;

public Student() {

}

public Student(String stuname, String stuid, List<Course> courses) {

this.stuname = stuname;

this.stuid = stuid;

this.courses = courses;

}

public String getStuname() {

return stuname;

}

public void setStuname(String stuname) {

this.stuname = stuname;

}

public String getStuid() {

return stuid;

}

public void setStuid(String stuid) {

this.stuid = stuid;

}

public List<Course> getCourses() {

return courses;

}

public void setCourses(List<Course> courses) {

this.courses = courses;

}

@Override

public String toString() {

return "学生姓名=" + stuname + ",学号=" + stuid + ", 课程=" + courses;

}

}

package exam2;

public class Course {

//定义一个课程类:课程名称,课程分数

private String cname;

private int score;

public Course() {

}

public Course(String cname, int score) {

this.cname = cname;

this.score = score;

}

public String getCname() {

return cname;

}

public void setCname(String cname) {

this.cname = cname;

}

public int getScore() {

return score;

}

public void setScore(int score) {

this.score = score;

}

@Override

public String toString() {

return "[课程名称=" + cname + ", 课程分数=" + score + "]";

}

}

/*

运行:

tom学生总分:230

*/

(8)java学生类扩展阅读:

Public语句说明

1.Public语句声明的变量在所有应用程序的所有没有使用OptionPrivate Mole的模块的任何过程中都是可用的;若该模块使用了OptionPrivate Mole,则该变量只是在其所属工程中是公用的。

2.使用Public语句可以声明变量的数据类型。例如,下面的语句声明了一个Integer类型的变量。

3.Public NumberOfEmployees As Integer 也可以使用Public语句来声明变量的对象类型。下面的语句为工作表的新实例声明了一个变量。

参考资料:网络-Public 语句



❾ JAVA 学生类

class
Students
{
private
String
xuehao;
private
String
name;
private
String
riqi;
public
void
setxuehao(String
xuehao)
{
this.xuehao=xuehao;
}
public
void
setname(String
name)
{
this.name=name;
}
public
void
setriqi(DEtime
riqi)
{
this.riqi=riqi.getTime();
}
public
String
getname()
{
return
name;
}
public
String
getriqi()
{
return
riqi;
}
public
String
getxuehao()
{
return
xuehao;
}
}
class
DEtime
{
int
year;
int
month;
int
day;
public
String
getTime()
{
return
year+"-"+month+"-"+day;
}
}
class
Test
{
Students
student=new
Students();
student.setxuehao("001");
student.setname("shine");
DEtime
time=new
DEtime();
time.year="2009";
time.month="01";
time.day="01";
Student.setriqi(time);
System.out.println("student学生的学号是"+student.getxuehao());
System.out.println("student学生的姓名是"+student.getname());
System.out.println("student学生的出生日期是"+student.getriqi());
}
因为
我忘记了
时间的表达方式
暂且用
String
来代替下把
不过
在日常生活中
我们都是用String
来做
更为简单!

热点内容
日志打印怎么在编译器中看 发布:2025-01-24 22:44:21 浏览:462
安卓手机哪里调屏幕常亮 发布:2025-01-24 22:44:15 浏览:545
linux下安装vmware 发布:2025-01-24 22:44:10 浏览:297
苹果6密码忘记怎么办啊 发布:2025-01-24 22:38:46 浏览:832
微博android 发布:2025-01-24 22:38:40 浏览:531
安卓自带的剪辑软件哪个好用 发布:2025-01-24 22:15:22 浏览:391
centosyumphpfpm 发布:2025-01-24 22:14:19 浏览:154
反编译看不懂代码 发布:2025-01-24 22:04:52 浏览:139
zip4j加密 发布:2025-01-24 21:57:57 浏览:455
安卓录屏功能在哪里找到 发布:2025-01-24 21:55:24 浏览:651