重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

java有答案的代码 java实现答题代码

这两道题代码怎么写java?

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

成都创新互联是专业的和政网站建设公司,和政接单;提供网站设计制作、成都网站建设,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行和政网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

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;

}

}

给段最简单的java代码 让我新手看一下

最简单的java代码肯定就是这个了,如下:

public class MyFirstApp

{

public static void main(String[] args)

{

System.out.print("Hello world");

}

}

“hello world”就是应该是所有学java的新手看的第一个代码了。如果是零基础的新手朋友们可以来我们的java实验班试听,有免费的试听课程帮助学习java必备基础知识,有助教老师为零基础的人提供个人学习方案,学习完成后有考评团进行专业测试,帮助测评学员是否适合继续学习java,15天内免费帮助来报名体验实验班的新手快速入门java,更好的学习java!

java练习题求完整代码

按照题目要求编写的用javaBean规范设计的学生类Student的Java程序如下

需要创建user.java.test包,把Student.java文件和Test.java文件放入包中,编译Student.java文件并且编译运行Test.java文件得到运行结果

Student.java文件代码如下

package user.java.test;

import java.io.Serializable;

public class Student implements Serializable{

private static final long serialVersionUID = 1L;

private String no;

private String name;

private double score;

public Student(){}

public Student(String no,String name,double score){

this.no=no;

this.name=name;

this.score=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 double getScore(){ return score;}

public void setScore(double score){ this.score=score;}

public String toString(){

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

}

public static double getAvg(Student[] sArray){

double sum=0,avg;

for(int i=0;isArray.length;i++){

sum=sum+sArray[i].getScore();

}

avg=sum/sArray.length;

return avg;

}

}

Test.java文件代码如下

package user.java.test;

public class Test{

public static void main(String[] args){

Student[] sArray=new Student[5];

sArray[0]=new Student("001","张三",89.5);

sArray[1]=new Student("002","李四",82.5);

sArray[2]=new Student("003","王五",93);

sArray[3]=new Student("004","赵六",73.5);

sArray[4]=new Student("005","孙七",66);

System.out.println("这些学生的平均分:"+Student.getAvg(sArray));

for(int i=0;isArray.length;i++){

System.out.println(sArray[i].toString());

}

}

}

java练习题求解希望有完整代码

运行代码

具体的代码如下:

import java.util.HashMap;

public class SearchDemo {

public HashMapInteger,Integer countMap(char[] arr){

HashMap countMap = new HashMapInteger, Integer();

for (int i = 0; i arr.length; i++) {

if(!countMap.containsKey(arr[i])){

countMap.put(arr[i],1);

}else{

int value = (int)countMap.get(arr[i]) + 1;

countMap.put(arr[i],value);

}

}

return countMap;

}

public static void main(String[] args) {

char[] arr={'A','1','R','!','e','','A','5','A','g','#','D'};

int count = new SearchDemo().countMap(arr).get('A');

System.out.println("其中'A'字符的个数是:" + count);

}

}

运行结果


网站题目:java有答案的代码 java实现答题代码
链接分享:http://cqcxhl.com/article/doopech.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP