《Java》期末课程设计

《Java》期末课程设计,第1张

import java.io.BufferedReader

import java.io.InputStreamReader

public class QuestionOne {

/**

* 编程将从键盘输入文本中的子字符串“word”替换为字符串“world”, 并删除所有的子字符串“this”。

* 序程要求:程序中要包含有注释,对于使用的变量和方法的功能要加以说明。

*/

public static void main(String[] args) {

BufferedReader reader = new BufferedReader(new InputStreamReader(

System.in))

String message = null// 存储用户输入的字符串

try {

while ((message = reader.readLine()) != null) {

// 打印处理前的字符串

System.out.println("输入的字符串为:" + message)

// 把 word 替换为 world

message = message.replaceAll("word", "world")

// 把 this 替换为 空

message = message.replaceAll("this", "")

// 打印处理后的字符串

System.out.println("处理后为:" + message)

}

} catch (Exception e) {

e.printStackTrace()

System.out.println("出现异常,程序退出!")

}

}

}

fieldname是java中合法标识符。

根据《JAVA程序设计》期末考试复习题,fieldname是java中合法标识符

标识,同“标志”汉语词汇,意思是标示识别。用来识别的记号。

import java.math.BigDecimal

public class JavaCourse {

private String sName//学生姓名

private String sId //学号

private int testGrade //测试成绩

private int regularGrade//平时成绩

private int endOfTermGrade//期末成绩

private int totalGrade //总成绩

public final double TR= 0.3

public final double RR= 0.3

public final double ER= 0.4

public JavaCourse() {

}

public JavaCourse(String sName, String sId, int testGrade, int regularGrade, int endOfTermGrade) {

this.sName = sName

this.sId = sId

this.testGrade = testGrade

this.regularGrade = regularGrade

this.endOfTermGrade = endOfTermGrade

}

public String getsName() {

return sName

}

public void setsName(String sName) {

this.sName = sName

}

public String getsId() {

return sId

}

public void setsId(String sId) {

this.sId = sId

}

public int getTestGrade() {

return testGrade

}

public void setTestGrade(int testGrade) {

this.testGrade = testGrade

}

public int getRegularGrade() {

return regularGrade

}

public void setRegularGrade(int regularGrade) {

this.regularGrade = regularGrade

}

public int getEndOfTermGrade() {

return endOfTermGrade

}

public void setEndOfTermGrade(int endOfTermGrade) {

this.endOfTermGrade = endOfTermGrade

}

public int getTotalGrade() {

return totalGrade

}

@Override

public String toString() {

return "JavaCourse{" +

"sName='" + sName + '\'' +

", sId='" + sId + '\'' +

", testGrade=" + testGrade +

", regularGrade=" + regularGrade +

", endOfTermGrade=" + endOfTermGrade +

'}'

}

public void showTotalGrad() {

//double四舍五入(0.5->1)转int类型

totalGrade = Integer.parseInt(new BigDecimal((testGrade * TR + regularGrade * RR + endOfTermGrade * ER)).setScale(0, BigDecimal.ROUND_HALF_UP).toString())

System.out.println("课程的总成绩:" + totalGrade)

}

}

public class DemoTest02 {

public static void main(String[] args) {

JavaCourse student1 = new JavaCourse()

student1.setsName("小张")

student1.setsId("10086")

student1.setTestGrade(85)

student1.setRegularGrade(90)

student1.setEndOfTermGrade(86)

System.out.println(student1.toString())

student1.showTotalGrad()

JavaCourse student2 = new JavaCourse("老王","10010",60,80,45)

System.out.println(student2.toString())

student2.showTotalGrad()

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/7745043.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-09
下一篇 2023-04-09

发表评论

登录后才能评论

评论列表(0条)

保存