成都创新互联网站制作重庆分公司

学生录入Java代码 用java编写学生类

急!急1急!用java编写简单的学生成绩录入程序

这里有一个类

成都创新互联公司服务项目包括临县网站建设、临县网站制作、临县网页制作以及临县网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,临县网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到临县省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!

实现学生学号,数学,语文,英语成绩录入

并且计算平均成绩,按照平均成绩高低输出信息

你可以改改!

//实现简单的学生信息输入输出和初步的成绩排序

public

class

student

{

private

int

id;

//学号

private

int

mathscore;

//数学成绩

private

int

chinscore;

//语文成绩

private

int

forescore;

//外语成绩

public

student()

{

id

=

0;

mathscore

=

0;

chinscore

=

0;

forescore

=

0;

}

public

student(int

newid,

int

newmathscore,

int

newchinsvore,

int

newforescore)

{

id

=

newid;

mathscore

=

newmathscore;

chinscore

=

newchinsvore;

forescore

=

newforescore;

}

public

double

getaveragescore()

{

//求平均成绩

double

averagescore

=

((double)

mathscore

+

chinscore

+

forescore)

/

3;

return

averagescore;

}

public

void

output(student

student)

{

//输出对象的内容

system.out.println("

"

+

student.id

+

"

"

+

student.mathscore

+

"

"

+

student.chinscore

+

"

"

+

student.forescore

+

"

"

+

student.getaveragescore());

}

public

int

max(student

a[],

int

n)

{

//student类对象数组的前n项中的成绩最大值的索引

int

position

=

0;

for

(int

i

=

1;

i

n;

i++)

{

if

(a[i].getaveragescore()

a[position].getaveragescore())

{

//比较平均成绩

position

=

i;

}

}

return

position;

}

public

void

selectsort(student

a[])

{

//student类对象数组的选择排序

for

(int

n

=

a.length;

n

1;

n--)

{

int

i

=

max(a,

n);

student

temp

=

a[i];

a[i]

=

a[n

-

1];

a[n

-

1]

=

temp;

}

}

}

用Java编写学生录入信息的程序

这里有一个类

实现学生学号,数学,语文,英语成绩录入

并且计算平均成绩,按照平均成绩高低输出信息

你可以改改!

//实现简单的学生信息输入输出和初步的成绩排序

public class Student {

private int id; //学号

private int mathScore; //数学成绩

private int chinScore; //语文成绩

private int foreScore; //外语成绩

public Student() {

id = 0;

mathScore = 0;

chinScore = 0;

foreScore = 0;

}

public Student(int newId, int newMathScore, int newChinSvore,

int newForeScore) {

id = newId;

mathScore = newMathScore;

chinScore = newChinSvore;

foreScore = newForeScore;

}

public double getAverageScore() { //求平均成绩

double averageScore = ((double) mathScore + chinScore + foreScore) / 3;

return averageScore;

}

public void output(Student student) { //输出对象的内容

System.out.println(" " + student.id + " " + student.mathScore +

" " + student.chinScore + " "

+ student.foreScore + " " +

student.getAverageScore());

}

public int max(Student a[], int n) { //Student类对象数组的前n项中的成绩最大值的索引

int position = 0;

for (int i = 1; i n; i++) {

if (a[i].getAverageScore() a[position].getAverageScore()) { //比较平均成绩

position = i;

}

}

return position;

}

public void selectSort(Student a[]) { //Student类对象数组的选择排序

for (int n = a.length; n 1; n--) {

int i = max(a, n);

Student temp = a[i];

a[i] = a[n - 1];

a[n - 1] = temp;

}

}

}

如何用Java实现“学生成绩输入”问题?

import java.util.Scanner;\x0d\x0a public class Student{\x0d\x0a public static void main(String[] args){\x0d\x0a Scanner sc = new Scanner(System.in);\x0d\x0a System.out.println("请输入学生的人数....");\x0d\x0a int num = sc.nextInt();\x0d\x0a int[] arr = new int[num];\x0d\x0a double[] chengji_arr = new double[num]; //存放成绩的\x0d\x0a String[] String_arr = new String[num]; //存放姓名的\x0d\x0a String chengjis = "";\x0d\x0a String names = "";\x0d\x0a for(int i = 0; i

回答于 2022-11-16

要求编写一个java程序,输入学生信息,并能保存与显示学生信息。

import java.util.ArrayList;

import java.util.Scanner;import com.sun.org.apache.xpath.internal.Arg;

public class Student {

//两个私有属性

private int no ;

private String name ;

//默认构造函数

public Student(){}

//带参构造函数

public Student(int no,String name){

this.no=no;

this.name=name;

}

//添加学生信息

public void addStudentInfo(ArrayList list){

String flag1="yes";

do{

Student student=new Student();

Scanner in =new Scanner(System.in);

System.out.println("请输入学生学号:");

student.setNo(in.nextInt());

System.out.println("请输入学生姓名:");

student.setName(in.next());

list.add(student);

System.out.println("是否继续添加学生信息(yes/no)?");

flag1=in.next();

} while(flag1.equals("yes"));

}

//读取学生信息

public void showStudentInfo(ArrayListStudent list){

System.out.println(" 学生no: "+" 学生name: ");

for(Student student:list){

System.out.println(" "+student.getNo()+" "+student.getName());

}

}

public int getNo() {

return no;

}

public void setNo(int no) {

this.no = no;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public static void main(String arg[]) {

ArrayListStudent studentList= new ArrayListStudent();

Student student= new Student();

Scanner inn= new Scanner(System.in);

while(true){

System.out.println("----------------- 欢迎使用学生管理系统------------------");

System.out.println("1.输入学生信息");

System.out.println("2.显示学生信息");

System.out.println("0.退出系统");

System.out.println("请选择....");

int nn= inn.nextInt();

switch (nn) {

case 1:

student.addStudentInfo(studentList);

break;

case 2:

System.out.println("学生信息如下:");

student.showStudentInfo(studentList);

break;

case 0:

System.exit(0);

System.out.println("系统退出!");

break;

default:

break;

}

}

} }


本文标题:学生录入Java代码 用java编写学生类
网站链接:http://cxhlcq.com/article/doshogs.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部