十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
如果可以修改,最好把java改成javascript
成都创新互联是专业的邵东网站建设公司,邵东接单;提供成都网站设计、成都网站制作,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行邵东网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!
你的程序没有问题(可能思路有些问题,比如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
创建一个名字为“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;
}
}
Student类:
public class Student {
/**
* 学生姓名
*/
private String name;
/**
* 学生性别
*/
private String sex;
/**
* 学生年龄
*/
private int age;
/**
* 学生成绩。数组中依次是语文、数学、英语成绩。
*/
private int[] grade;
/**
* 必须传入学生姓名、性别、年龄才能创建实例
*
* @param name
* @param sex
* @param age
*/
public Student(String name, String sex, int age) {
this.name = name;
this.sex = sex;
this.age = age;
grade = new int[3];
}
/**
* 说话方法
*
* @param content
*/
public void speak(String content) {
System.out.println(this.name + "说 “" + content + "”");
}
/**
* 打印输出各科成绩及平均分
*/
public void outGrade() {
System.out.println("======成绩单======");
System.out.println("语文:" + grade[0]);
System.out.println("数学:" + grade[1]);
System.out.println("英语:" + grade[2]);
System.out.println("平均分:" + String.format("%.2f", (grade[0] + grade[1] + grade[2]) / 3.0));
}
/**
* 录入学生成绩
*
* @param grade
*/
public void setGrade(int[] grade) {
this.grade = grade;
}
public String getName() {
return name;
}
public String getSex() {
return sex;
}
public int getAge() {
return age;
}
public int[] getGrade() {
return grade;
}
}
其中,那么多的get方法在你这个题目中可能没什么用,但是实际中我们一般都会用get方法来获取实例的某个属性。
测试类:
public class Test {
public static void main(String[] args) {
Student stu = new Student("王冲", "男", 15);
int[] grade = new int[] { 138, 145, 142 };
stu.speak("没有规矩,不成方圆");
stu.setGrade(grade);
stu.outGrade();
}
}
第一张图看不清,我只从第二张图得到第一个学生的信息,另一个学生也是同样的做法。
输出结果:
王冲说 “没有规矩,不成方圆”
======成绩单======
语文:138
数学:145
英语:142
平均分:141.67
1、编写一个java成绩统计程序,输入一个班的java成绩(含姓名和分数),统计出平均分,最高分、最低分,并打印成绩单。由于编程时人数不确定,所以要求使用Vector或ArrayList完成上述程序。1)学生成绩用一个类Mark表示,其成员变量包含考生姓名、成绩。输入的姓名为"end"时,程序结束。
2、主类的名称叫做GradeStatistic,将Mark设计为GradeStatistic的内部类。提示:键盘输入采用Scanner类,实例化Scanner采用下述语句:Scanner sc=new Scanner(System.in);然后通过sc调
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;
}
};
import java.util.Vector;
import java.util.*;
public class Mark {
private static VectorStudent vmark = new VectorStudent();
public static void print(String line) {
System.out.println(line);
}
public static void addStudent(Student s) {
vmark.add(s);
}
public static int getNum() {
return vmark.size();
}
public static int getAverage() {
int sum = 0;
int num = getNum();
for(int i = 0; i num; i ++) {
sum = sum + vmark.get(i).getJavaMark();
}
return sum / num;
}
public static int [] numList() {
int num;
num = getNum();
int [] list = new int[num];
for(int i = 0; i num; i ++) {
list[i] = vmark.get(i).getJavaMark();
}
return list;
}
public static int getHighest() {
int [] temp = numList();
Arrays.sort(temp);
return temp[temp.length -1 ];
}
public static int getLowest() {
int [] temp = numList();
Arrays.sort(temp);
return temp[0];
}
public static void main(String[] args) {
Student s1 = new Student("jimmy" , 88);
Student s2 = new Student("Lucy", 90);
Student s3 = new Student("tiger" , 100);
Mark.addStudent(s1);
Mark.addStudent(s2);
Mark.addStudent(s3);
print("平均分数 : " + Mark.getAverage());
print("最高分 :" + Mark.getHighest());
print("最低分 :" + Mark.getLowest());
for(int i = 0; i Mark.getNum(); i ++) {
print(Mark.getVmark().get(i).toString());
}
}
public static VectorStudent getVmark() {
return vmark;
}
public static void setVmark(VectorStudent vmark) {
Mark.vmark = vmark;
}
}