「java做成绩单」java成绩代码

博主:adminadmin 2023-03-17 04:14:10 483

今天给各位分享java做成绩单的知识,其中也会对java成绩代码进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

求JAVA源代码

import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;

public class GradeStatistic {

public static void main(String[] args) {

GradeStatistic gs = new GradeStatistic();

ListMark list = new ArrayListMark();

float sum = 0;

while(true){

Scanner sc = new Scanner(System.in);

System.out.print("Please input student name: ");

String name = sc.nextLine();

if(name.equals("end")){

break;

}

System.out.print("Please input student score: ");

float score = sc.nextFloat();

sum += score;

list.add(gs.new Mark(name, score));

}

float max = list.get(0).getScore();

float min = list.get(0).getScore();

for(Mark mark: list){

if(max mark.getScore()){

max = mark.getScore();

}

if(min mark.getScore()){

min = mark.getScore();

}

}

float average = sum / list.size();

System.out.println("Average is: " + average);

System.out.println("Max is: " + max);

System.out.println("Min is: " + min);

}

private class Mark{

private String name;

private float score;

public Mark(String name, float score){

this.name = name;

this.score = score;

}

public String getName() {

return name;

}

public float getScore() {

return score;

}

}

}

----------------------

Please input student name: Zhang san

Please input student score: 100

Please input student name: Li Si

Please input student score: 91

Please input student name: Ec

Please input student score: 35

Please input student name: ma qi

Please input student score: 67

Please input student name: end

Average is: 73.25

Max is: 100.0

Min is: 35.0

Java急急急

package org.czj._04;

import java.io.*;

public class BufferedReaderDemo01 {

    public static void main(String args[]) throws Exception {

        BufferedReader buf = null; // 声明对象

        FileInputStream fis = new FileInputStream("D:" + File.separator + "score.txt");

        buf = new BufferedReader(new InputStreamReader(fis)); // 将字节流变为字符流

        // 第1步、使用File类找到一个文件

        File f= new File("d:" + File.separator + "scoreAnalysis.txt") ;    // 声明File对象

        // 第2步、通过子类实例化父类对象

        Writer out = null ;    // 准备好一个输出的对象

        out = new FileWriter(f,true)  ;    // 通过对象多态性,进行实例化

        String str = null; // 接收输入内容

        while ((str = buf.readLine())!=null) {

            System.out.println(str);

            double score=getTotalScore(str);

            str+="总分数:"+score;

            out.write(str+"\r\n") ;                        // 将内容输出,保存文件

        }

        // 第4步、关闭输出流

        out.flush() ;    // 强制性清空缓冲区中的内容

         out.close() ;        

    }

    

    public static double getTotalScore(String s){

        

        String newStr=s.replaceAll("[^0-9.]", "_");

        String [] score=newStr.split("_");

        double sum=0;

        for (String str : score) {

            try {

                sum+=Float.parseFloat(str);

            } catch (NumberFormatException e) {}

        }

        return sum;

    }

};

JAVA编程题!

//把你的那个表作成test3.txt放到D盘根,跑程序就好了

import java.io.BufferedReader;

import java.io.FileInputStream;

import java.io.InputStreamReader;

import java.util.ArrayList;

import java.util.Collections;

import java.util.Iterator;

import java.util.List;

public class MyTest3 {

List stuInfoList = new ArrayList();

public MyTest3(){

printResult();

}

public void readFile() {

try {

BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("d:\\test3.txt")));

String line = "";

int i=0;

while ((line = br.readLine()) != null) {

if(i++0){ //略过头上的汉字行

StudentInfo student = new StudentInfo(line.split(" "));

stuInfoList.add(student);

}

}

} catch (Exception e) {

e.printStackTrace();

}

}

class StudentInfo implements Comparable{

public int stuId;

public double pings;

public double qizhong;

public double qimo;

public double bishi;

public double zhongFeng;

public StudentInfo(){};

public StudentInfo(String[] info){

this.stuId = Integer.parseInt(info[0]);

this.pings = Integer.parseInt(info[1]);

this.qizhong = Integer.parseInt(info[2]);

this.qimo = Integer.parseInt(info[3]);

this.bishi = Integer.parseInt(info[4]);

this.zhongFeng = pings*0.1+qizhong*0.25+qimo*0.15+bishi*0.5;

}

public String getPingJunFeng(int size){

return pings/size +" "+qizhong/size+" "+qimo/size+" "+bishi/size+" "+zhongFeng/size;

}

public String toString(){

return stuId + " " +pings + " "+qizhong+" "+qimo+" "+bishi+" "+zhongFeng;

}

public int compareTo(Object arg0) {

StudentInfo info = (StudentInfo)arg0;

return (int)(info.zhongFeng-this.zhongFeng);

}

}

public void printResult(){

readFile();

System.out.println("学号 平时 期中 期末 笔试 总评分");

for(Iterator it=stuInfoList.iterator();it.hasNext();){

System.out.println(it.next());

}

System.out.println("-----------80分以上---------------\r\n学号 总评分");

for(Iterator it=stuInfoList.iterator();it.hasNext();){

StudentInfo info = (StudentInfo)it.next();

if(info.zhongFeng=80)

System.out.println(info.stuId + " "+info.zhongFeng);

}

System.out.println("-----------没有及格---------------\r\n学号 总评分");

for(Iterator it=stuInfoList.iterator();it.hasNext();){

StudentInfo info = (StudentInfo)it.next();

if(info.zhongFeng60)

System.out.println(info.stuId + " "+info.zhongFeng);

}

Collections.sort(stuInfoList);

System.out.println("-----------排序之后---------------\r\n学号 平时 期中 期末 笔试 总评分");

for(Iterator it=stuInfoList.iterator();it.hasNext();){

System.out.println(it.next());

}

StudentInfo pinjunfeng = new StudentInfo();

for(Iterator it=stuInfoList.iterator();it.hasNext();){

StudentInfo info = (StudentInfo)it.next();

pinjunfeng.bishi+=info.bishi;

pinjunfeng.pings+=info.pings;

pinjunfeng.qimo+=info.qimo;

pinjunfeng.qizhong+=info.qizhong;

pinjunfeng.zhongFeng+=info.zhongFeng;

}

System.out.println("-----------平均分---------------\r\n平时 期中 期末 笔试 总评分");

System.out.println(pinjunfeng.getPingJunFeng(stuInfoList.size()));

}

public static void main(String[] args) throws Exception {

new MyTest3();

}

}

这两道题代码怎么写java?

创建一个名字为“ReportCard”的类,然后用下边的内容全部替换掉,你会成为全班最亮的仔。

import java.util.HashMap;

/**

* 学生成绩单

*/

public class ReportCard {

public static void main(String[] args) {

ReportCard reportCard = new ReportCard("张三", "070602213");

reportCard.set("语文", 80.0);

reportCard.set("数学", 59.5);

reportCard.set("英语", 66.0);

reportCard.set("java", 80, 99.0);

reportCard.set("数据库", 80, 66.0);

reportCard.set("毛概", null);

System.out.println(reportCard.getStudentName() + "语文分数:" + reportCard.get("语文"));

System.out.println(reportCard.getStudentName() + "数学考核结果:" + (reportCard.isPassed("数学") ? "合格" : "不合格"));

System.out.println(reportCard.getStudentName() + "期末是否挂科:" + (reportCard.isAllPassed() ? "否" : "是"));

}

// 学生姓名

private String studentName;

// 学生学号

private String studentNumber;

// 成绩单

private HashMapString, CourseResult cards = new HashMap();

public ReportCard() {

}

public ReportCard(String studentName, String studentNumber) {

this.studentName = studentName;

this.studentNumber = studentNumber;

}

public Double get(String courseName){

CourseResult courseResult = cards.get(courseName);

return courseResult == null ? Double.NaN : courseResult.getStudentScore();

}

public void set(String courseName, Double studentScore){

CourseResult courseResult = new CourseResult(courseName, studentScore);

cards.put(courseName, courseResult);

}

public void set(String courseName, double passMark, Double studentScore){

CourseResult courseResult = new CourseResult(courseName, passMark, studentScore);

cards.put(courseName, courseResult);

}

public boolean isPassed(String courseName){

return cards.get(courseName).isPassed();

}

public boolean isAllPassed(){

for(CourseResult cr : cards.values()){

if ( ! cr.isPassed()) {

return false;

}

}

return true;

}

public String getStudentName() {

return studentName;

}

public String getStudentNumber() {

return studentNumber;

}

public void setStudentName(String studentName) {

this.studentName = studentName;

}

public void setStudentNumber(String studentNumber) {

this.studentNumber = studentNumber;

}

/**

* 课程

*/

class Course{

// 课程名称

protected String courseName;

// 及格分

protected double passMark = 60;

public Course(String courseName, Double passMark) {

this.courseName = courseName;

if ( passMark != null) {

this.passMark = passMark;

}

}

}

/**

* 课程成绩

*/

class CourseResult extends Course{

// 学生成绩

private Double studentScore;

public CourseResult(String courseName, Double studentScore) {

this(courseName, null, studentScore);

}

public CourseResult(String courseName, Double passMark, Double studentScore) {

super(courseName, passMark);

this.studentScore = studentScore == null ? Double.NaN : studentScore;

}

public boolean isPassed(){

return studentScore = passMark;

}

public String getCourseName() {

return courseName;

}

public double getPassMark() {

return passMark;

}

public Double getStudentScore() {

return studentScore;

}

}

编写一程序,用哈希表实现学生成绩单的存储与查询

import java.util.Hashtable;

声明引用了吗?

给你完整代码

学生类Student,代码如下:

class Student{

private String no;

private String name;

private Integer score;

public String getNo() {

return no;

}

public void setNo(String no) {

this.no = no;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public Integer getScore() {

return score;

}

public void setScore(Integer score) {

this.score = score;

}

public String toString(){

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

}

}

主类HashTest,代码如下:

import javax.swing.*;

import java.util.Vector;

import java.util.Hashtable;

import java.awt.*;

import java.awt.event.ActionListener;

import java.awt.event.ActionEvent;

public class HashTest extends JFrame {

JLabel lblsearchbyidorname;

JTextField txfidorname;

JButton btnsearchbyidorname;

JTable reader;

JButton btnadd;

JButton btndelete;

Hashtable ht;

Vector colnames;

JLabel lblno;

JLabel lblname;

JLabel lblscore;

JTextField addno;

JTextField addname;

JTextField addscore;

Vector data;

public HashTest() throws HeadlessException {

super("学生成绩管理");

ht = new Hashtable();

lblsearchbyidorname = new JLabel("学号:");

txfidorname = new JTextField(20);

lblno = new JLabel("学号");

lblname = new JLabel("姓名");

lblscore = new JLabel("分数");

addno = new JTextField(10);

addname = new JTextField(12);

addscore = new JTextField(10);

btnsearchbyidorname = new JButton("查找--");

btnadd = new JButton("新增");

btndelete = new JButton("删除");

colnames = new Vector();

colnames.add("学号");

colnames.add("姓名");

colnames.add("成绩");

data = new Vector();

reader = new JTable(new ReaderTableModel(data,colnames));

reader.setPreferredSize(new Dimension(700,260));

JPanel pnlsearch = new JPanel();

pnlsearch.add(lblsearchbyidorname);

pnlsearch.add(txfidorname);

pnlsearch.add(btnsearchbyidorname);

pnlsearch.add(btndelete);

JScrollPane scptable = new JScrollPane(reader,

ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,

ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);

JPanel pnladd = new JPanel();

pnladd.add(lblno);

pnladd.add(addno);

pnladd.add(lblname);

pnladd.add(addname);

pnladd.add(lblscore);

pnladd.add(addscore);

pnladd.add(btnadd);

reader.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

ScoreHandler sh = new ScoreHandler();

btnadd.addActionListener(sh);

btndelete.addActionListener(sh);

btnsearchbyidorname.addActionListener(sh);

Container c = getContentPane();

c.add(pnlsearch,BorderLayout.NORTH);

c.add(scptable,BorderLayout.CENTER);

c.add(pnladd,BorderLayout.SOUTH);

setSize(600,400);

setVisible(true);

}

public static void main(String[] args) {

new HashTest();

}

class ScoreHandler implements ActionListener{

public void actionPerformed(ActionEvent e) {

JButton btn = (JButton)e.getSource();

if(btn == btnsearchbyidorname){

Object obj = ht.get(txfidorname.getText().trim());

if(obj == null){

JOptionPane.showMessageDialog(null,"没有找到!");

}else{

JOptionPane.showMessageDialog(null,"查询结果如下:\n" + obj.toString());

}

}else if(btn == btnadd){

Student stu = new Student();

stu.setName(addname.getText().trim());

stu.setNo(addno.getText().trim());

stu.setScore(Integer.valueOf(addscore.getText().trim()));

ht.put(stu.getNo(),stu);

addDataToTable(stu);

addname.setText("");

addno.setText("");

addscore.setText("");

}else if(btn == btndelete){

int index = reader.getSelectedRow();

if (index == -1){

JOptionPane.showMessageDialog(null,"你没有选择学生!");

}else{

String no = (String)reader.getValueAt(index,0);

Student stu = (Student)ht.remove(no);

JOptionPane.showMessageDialog(null,"学生成绩删除!\n" + stu.toString());

data.remove(index);

reader.repaint();

}

}

}

}

public void addDataToTable(Student stu){

Vector temp = new Vector();

temp.add(stu.getNo());

temp.add(stu.getName());

temp.add(stu.getScore());

data.add(temp);

reader.repaint();

}

}

java中用if做成绩单

如果可以修改,最好把java改成javascript

你的程序没有问题(可能思路有些问题,比如90怎么可能是优秀跟良好的)就是多了一个分号

html

head

title程序结构3SWITCH/title

/head

body

script language="javascript"

function c(form)

{var a=form.cnumber.value;

//{这里去掉

if(a=90a=100)

{document.write("优秀");}

if(a=80a=90)

{document.write("良好");}

if(a=70a=80)

{document.write("中等");}

if(a=60a=70)

{document.write("及格");}

if(a=60){document.write("不及格");}

}

/script

form

input name="cnumber" type="text" /br /

input name="button" type="button" onclick="c(form)" value="提交" /

/form

/body

/html

关于java做成绩单和java成绩代码的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。