JAVABlog作业3
JAVA题目集7~11总结
一、前言:
最后几次题目集的量变得非常少,但难度上升了很多,基本都是做个系统。
题目集7是菜单计价程序-5是之前菜单计价程序-3的升级;题目集8是新的课程成绩统计程序-1,虽然只是1,但难度不比之前低;题目集9是统计Java程序中关键词的出现次数,主要考察正则表达式并且初次使用map类,难度一般;题目集10的重点是课程成绩统计程序-2,附带了简单的hashmap和多态的题目;题目集的重点是课程成绩统计程序-3,这次附带的arraylist,排序,接口,覆盖也是基本的题目。
二、设计与分析:
1.题目集9 统计Java程序中关键词的出现次数
编写程序统计一个输入的Java源码中关键字(区分大小写)出现的次数。说明如下:
Java中共有53个关键字(自行百度)
从键盘输入一段源码,统计这段源码中出现的关键字的数量
注释中出现的关键字不用统计
字符串中出现的关键字不用统计
统计出的关键字及数量按照关键字升序进行排序输出
未输入源码则认为输入非法
输入格式:
输入Java源码字符串,可以一行或多行,以exit行作为结束标志
输出格式:
当未输入源码时,程序输出Wrong Format
当没有统计数据时,输出为空
当有统计数据时,关键字按照升序排列,每行输出一个关键字及数量,格式为数量\t关键字
(1)代码如下
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String[] keyword = {"abstract", "assert", "boolean", "break", "byte", "case", "catch", "char", "class","const", "continue", "default", "do", "double", "else", "enum", "extends", "false", "final","finally", "float", "for", "goto", "if", "implements", "import", "instanceof", "int", "interface","long", "native", "new", "null", "package", "private", "protected", "public", "return", "short","static", "strictfp", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "true", "try", "void", "volatile", "while"};
StringBuilder list = new StringBuilder();
Map<String, Integer> map = new HashMap<String, Integer>();
int i,j,n;
String a;
for (i=0;;i++){
a = input.nextLine();
if (a.matches("exit")){
if (i==0){
System.out.println("Wrong Format");
System.exit(0);
}
break;
}
list.append(a.replaceAll("//.*","").replaceAll("\".*\"",""));
}
String s= list.toString();
Pattern pattern = Pattern.compile("/\\**(.*?)/");
Matcher matcher = pattern.matcher(s);
while (matcher.find()) {
s = s.replace(matcher.group(), " ");
matcher = pattern.matcher(s);
}
s = s.replace("=", "a");
s.replaceAll("[^a-zA-Z]"," ");
for ( i = 0; i < keyword.length; i++) {
pattern = Pattern.compile("\\b" + keyword[i] + "\\b");
matcher = pattern.matcher(s);
n = 0;
while (matcher.find()) {
n++;
}
if (n != 0) {
map.put(keyword[i], n);
}
}
Set set = map.keySet();
Object[] array = set.toArray();
Arrays.sort(array);
for (Object b : array) {
System.out.println(map.get(b) + "\t" + b);
}
}
}
(2)解释和心得
题目的难点主要还是正则表达式,要正确删除代码中的各种符合和不符合要求的代码,map的使用较为基础并不难。
String[] keyword = {"abstract", "assert", "boolean", "break", "byte", "case", "catch", "char", "class","const", "continue", "default", "do", "double", "else", "enum", "extends", "false", "final","finally", "float", "for", "goto", "if", "implements", "import", "instanceof", "int", "interface","long", "native", "new", "null", "package", "private", "protected", "public", "return", "short","static", "strictfp", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "true", "try", "void", "volatile", "while"};
for ( i = 0; i < keyword.length; i++) {
pattern = Pattern.compile("\\b" + keyword[i] + "\\b");
matcher = pattern.matcher(s);
n = 0;
while (matcher.find()) {
n++;
}
if (n != 0) {
map.put(keyword[i], n);
}
}
计算出现次数是通过将关键词放入数组在循环匹配代码,用map计数。
2.题目集6 菜单计价程序-5
本题在菜单计价程序-3的基础上增加了部分内容,增加的内容用加粗字体标识。
注意不是菜单计价程序-4,本题和菜单计价程序-4同属菜单计价程序-3的两个不同迭代分支。
设计点菜计价程序,根据输入的信息,计算并输出总价格。
输入内容按先后顺序包括两部分:菜单、订单,最后以"end"结束。
菜单由一条或多条菜品记录组成,每条记录一行
每条菜品记录包含:菜名、基础价格 三个信息。
订单分:桌号标识、点菜记录和删除信息、代点菜信息。每一类信息都可包含一条或多条记录,每条记录一行或多行。
桌号标识独占一行,包含两个信息:桌号、时间。
桌号以下的所有记录都是本桌的记录,直至下一个桌号标识。
点菜记录包含:序号、菜名、份额、份数。份额可选项包括:1、2、3,分别代表小、中、大份。
不同份额菜价的计算方法:小份菜的价格=菜品的基础价格。中份菜的价格=菜品的基础价格1.5。小份菜的价格=菜品的基础价格2。如果计算出现小数,按四舍五入的规则进行处理。
删除记录格式:序号 delete
标识删除对应序号的那条点菜记录。
如果序号不对,输出"delete error"
代点菜信息包含:桌号 序号 菜品名称 口味度 份额 份数
代点菜是当前桌为另外一桌点菜,信息中的桌号是另一桌的桌号,带点菜的价格计算在当前这一桌。
程序最后按输入的先后顺序依次输出每一桌的总价(注意:由于有代点菜的功能,总价不一定等于当前桌上的菜的价格之和)。
每桌的总价等于那一桌所有菜的价格之和乘以折扣。如存在小数,按四舍五入规则计算,保留整数。
折扣的计算方法(注:以下时间段均按闭区间计算):
周一至周五营业时间与折扣:晚上(17:00-20:30)8折,周一至周五中午(10:30--14:30)6折,其余时间不营业。
周末全价,营业时间:9:30-21:30
如果下单时间不在营业范围内,输出"table " + t.tableNum + " out of opening hours"
参考以下类的模板进行设计:菜品类:对应菜谱上一道菜的信息。
Dish {
String name;//菜品名称
int unit_price; //单价
int getPrice(int portion)//计算菜品价格的方法,输入参数是点菜的份额(输入数据只能是1/2/3,代表小/中/大份) }
菜谱类:对应菜谱,包含饭店提供的所有菜的信息。
Menu {
Dish[] dishs ;//菜品数组,保存所有菜品信息
Dish searthDish(String dishName)//根据菜名在菜谱中查找菜品信息,返回Dish对象。
Dish addDish(String dishName,int unit_price)//添加一道菜品信息
}
点菜记录类:保存订单上的一道菜品记录
Record {
int orderNum;//序号\
Dish d;//菜品\
int portion;//份额(1/2/3代表小/中/大份)\
int getPrice()//计价,计算本条记录的价格\
}
订单类:保存用户点的所有菜的信息。
Order {
Record[] records;//保存订单上每一道的记录
int getTotalPrice()//计算订单的总价
Record addARecord(int orderNum,String dishName,int portion,int num)//添加一条菜品信息到订单中。
delARecordByOrderNum(int orderNum)//根据序号删除一条记录
findRecordByNum(int orderNum)//根据序号查找一条记录
}
输入格式:
桌号标识格式:table + 序号 +英文空格+ 日期(格式:YYYY/MM/DD)+英文空格+ 时间(24小时制格式: HH/MM/SS)
菜品记录格式:
菜名+英文空格+基础价格
如果有多条相同的菜名的记录,菜品的基础价格以最后一条记录为准。
点菜记录格式:序号+英文空格+菜名+英文空格+份额+英文空格+份数注:份额可输入(1/2/3), 1代表小份,2代表中份,3代表大份。
删除记录格式:序号 +英文空格+delete
代点菜信息包含:桌号+英文空格+序号+英文空格+菜品名称+英文空格+份额+英文空格+分数
最后一条记录以“end”结束。
输出格式:
按输入顺序输出每一桌的订单记录处理信息,包括:
1、桌号,格式:table+英文空格+桌号+”:”
2、按顺序输出当前这一桌每条订单记录的处理信息,
每条点菜记录输出:序号+英文空格+菜名+英文空格+价格。其中的价格等于对应记录的菜品*份数,序号是之前输入的订单记录的序号。如果订单中包含不能识别的菜名,则输出“** does not exist”,**是不能识别的菜名
如果删除记录的序号不存在,则输出“delete error”
最后按输入顺序一次输出每一桌所有菜品的总价(整数数值)格式:table+英文空格+桌号+“:”+英文空格+当前桌的总价
以上为菜单计价系列-3的题目要求,加粗的部分是有调整的内容。本次课题相比菜单计价系列-3新增要求如下:
1、菜单输入时增加特色菜,特色菜的输入格式:菜品名+英文空格+口味类型+英文空格+基础价格+"T"
例如:麻婆豆腐 川菜 9 T
菜价的计算方法:
周一至周五 7折, 周末全价。
特色菜的口味类型:川菜、晋菜、浙菜
川菜增加辣度值:辣度0-5级;对应辣度水平为:不辣、微辣、稍辣、辣、很辣、爆辣;
晋菜增加酸度值,酸度0-4级;对应酸度水平为:不酸、微酸、稍酸、酸、很酸;
浙菜增加甜度值,甜度0-3级;对应酸度水平为:不甜、微甜、稍甜、甜;
例如:麻婆豆腐 川菜 9 T
输入订单记录时如果是特色菜,添加口味度(辣/酸/甜度)值,格式为:序号+英文空格+菜名+英文空格+口味度值+英文空格+份额+英文空格+份数
例如:1 麻婆豆腐 4 1 9
单条信息在处理时,如果口味度超过正常范围,输出"spicy/acidity/sweetness num out of range : "+口味度值,spicy/acidity/sweetness(辣度/酸度/甜度)根据菜品类型择一输出,例如:
acidity num out of range : 5
输出一桌的信息时,按辣、酸、甜度的顺序依次输出本桌菜各种口味的口味度水平,如果没有某个类型的菜,对应的口味(辣/酸/甜)度不输出,只输出已点的菜的口味度。口味度水平由口味度平均值确定,口味度平均值只综合对应口味菜系的菜计算,不做所有菜的平均。比如,某桌菜点了3份川菜,辣度分别是1、3、5;还有4份晋菜,酸度分别是,1、1、2、2,辣度平均值为3、酸度平均值四舍五入为2,甜度没有,不输出。
一桌信息的输出格式:table+英文空格+桌号+:+英文空格+当前桌的原始总价+英文空格+当前桌的计算折扣后总价+英文空格+"川菜"+数量+辣度+英文空格+"晋菜"+数量+酸度+英文空格+"浙菜"+数量+甜度。
如果整桌菜没有特色菜,则只输出table的基本信息,格式如下,注意最后加一个英文空格:
table+英文空格+桌号+:+英文空格+当前桌的原始总价+英文空格+当前桌的计算折扣后总价+英文空格
例如:table 1: 60 36 川菜 2 爆辣 浙菜 1 微甜
计算口味度时要累计本桌各类菜系所有记录的口味度总和(每条记录的口味度乘以菜的份数),再除以对应菜系菜的总份数,最后四舍五入。
注:本题要考虑代点菜的情况,当前桌点的菜要加上被其他桌代点的菜综合计算口味度平均值。
2、考虑客户订多桌菜的情况,输入时桌号时,增加用户的信息:
格式:table+英文空格+桌号+英文空格+":"+英文空格+客户姓名+英文空格+手机号+日期(格式:YYYY/MM/DD)+英文空格+ 时间(24小时制格式: HH/MM/SS)
例如:table 1 : tom 13670008181 2023/5/1 21/30/00
约束条件:客户姓名不超过10个字符,手机号11位,前三位必须是180、181、189、133、135、136其中之一。
输出结果时,先按要求输出每一桌的信息,最后按字母顺序依次输出每位客户需要支付的金额。不考虑各桌时间段的问题,同一个客户的所有table金额都要累加。
输出用户支付金额格式:
用户姓名+英文空格+手机号+英文空格+支付金额
注意:不同的四舍五入顺序可能会造成误差,请按以下步骤累计一桌菜的菜价:
计算每条记录的菜价:将每份菜的单价按份额进行四舍五入运算后,乘以份数计算多份的价格,然后乘以折扣,再进行四舍五入,得到本条记录的最终支付价格。
将所有记录的菜价累加得到整桌菜的价格。
输入格式:
桌号标识格式:table + 序号 +英文空格+ 日期(格式:YYYY/MM/DD)+英文空格+ 时间(24小时制格式: HH/MM/SS)
菜品记录格式:
菜名+口味类型+英文空格+基础价格
如果有多条相同的菜名的记录,菜品的基础价格以最后一条记录为准。
点菜记录格式:序号+英文空格+菜名+英文空格+辣/酸/甜度值+英文空格+份额+英文空格+份数 注:份额可输入(1/2/3), 1代表小份,2代表中份,3代表大份。辣/酸/甜度取值范围见题目中说明。
删除记录格式:序号 +英文空格+delete
代点菜信息包含:桌号+英文空格+序号+英文空格+菜品名称+英文空格+辣/酸/甜度值+英文空格+份额+英文空格+分数
最后一条记录以“end”结束。
输出格式:
按输入顺序输出每一桌的订单记录处理信息,包括:
1、桌号,格式:table+英文空格+桌号+“:”+英文空格
2、按顺序输出当前这一桌每条订单记录的处理信息,
每条点菜记录输出:序号+英文空格+菜名+英文空格+价格。其中的价格等于对应记录的菜品*份数,序号是之前输入的订单记录的序号。如果订单中包含不能识别的菜名,则输出“** does not exist”,**是不能识别的菜名
如果删除记录的序号不存在,则输出“delete error”
之后按输入顺序一次输出每一桌所有菜品的价格(整数数值),
格式:table+英文空格+桌号+“:”+英文空格+当前桌的计算折扣后总价+英文空格+辣度平均值+英文空格+酸度平均值+英文空格+甜度平均值+英文空格
最后按拼音顺序输出每位客户(不考虑客户同名或拼音相同的情况)的支付金额,格式: 用户姓名+英文空格+手机号+英文空格+支付总金额,按输入顺序排列。
(1)代码如下
import javax.management.ListenerNotFoundException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
public class Main {
public static void main(String[] args)throws ParseException {
Scanner input = new Scanner(System.in);
int i, t = 0,x = -1,T = -1, year, month, day, shi, fen, miao, f = 0,y=-1;
String a = null;
Menu menu = new Menu();
Table[] tables = new Table[10];
People[] people = new People[10];
for (; ; ) {
a = input.nextLine();
if (a.equals("end"))
break;
String[] s = a.split(" ");
int l = s.length;
if (!s[0].equals("table")&&t==0) {//菜品
if(menu.t!=-1){
y = -1;
for (int j=0;j<=menu.t;j++){
if(s[0].equals(menu.dishs[j].name)) {
y = j;
break;
}
}
}
if (y!=-1){//菜谱重复
if(l==2)
menu.dishs[y].unit_price = Integer.parseInt(s[1]);
else
menu.dishs[y].unit_price = Integer.parseInt(s[2]);
}
else {
menu.t++;
menu.dishs[menu.t] = new Dish();
if (l == 2) {//普通菜
menu.dishs[menu.t].name = s[0];
menu.dishs[menu.t].unit_price = Integer.parseInt(s[1]);
} else if(l==4){//特价菜
menu.dishs[menu.t].name = s[0];
menu.dishs[menu.t].breed = s[1];
menu.dishs[menu.t].unit_price = Integer.parseInt(s[2]);
menu.dishs[menu.t].special = true;
}
else{
System.out.println("wrong format");
System.out.println("wrong format");
System.exit(0);
}
}
} else {
t = 1;//不再进入菜单
if(s[0].equals("table")) {//桌子
x++;
tables[x] = new Table();
tables[x].order = new Order();
tables[x].num = Integer.parseInt(s[1]);
tables[x].name = s[3];
if (T == -1) {
T++;
people[T] = new People();
people[T].name = s[3];
people[T].phone = s[4];
} else {
int b = 0;
for (int I = 0; I <=T; I++) {
if (s[3].equals(people[I].name))
b = 1;
}
if (b == 0) {
T++;
people[T] = new People();
people[T].name = s[3];
people[T].phone = s[4];
}
}
String[] s1 = s[5].split("/");//年月日的分割
String[] s2 = s[6].split("/");//时分秒的分割
tables[x].num = Integer.parseInt(s[1]);
tables[x].year = Integer.parseInt(s1[0]);
tables[x].month = Integer.parseInt(s1[1]);
tables[x].day = Integer.parseInt(s1[2]);
tables[x].shi = Integer.parseInt(s2[0]);
tables[x].fen = Integer.parseInt(s2[1]);
tables[x].miao = Integer.parseInt(s2[2]);
SimpleDateFormat d = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat d2 = new SimpleDateFormat("u");
Date date = d.parse(s1[0] + "-" + s1[1] + "-" + s1[2]);//日期格式化
int week = Integer.parseInt(d2.format(date));//提取星期几
tables[x].week = week;
}
else {
if (s[1].equals("delete")) {//删除记录
if (tables[x].order.findRecordByNum(Integer.parseInt(s[0])) != -1)
tables[x].order.records[tables[x].order.findRecordByNum(Integer.parseInt(s[0]))].life = 1;//点菜成功删除
else {
tables[x].order.i++;
i = tables[x].order.i;
tables[x].order.records[i] = new Record();
tables[x].order.records[i].d = menu.dishs[0];
tables[x].order.records[i].life = 2;//删除的点菜不存在
}
} else {
//点菜
tables[x].order.i++;
i = tables[x].order.i;
tables[x].order.records[i] = new Record();
tables[x].order.records[i].orderNum = Integer.parseInt(s[0]);
if (menu.searthDish(s[1]) != null) {
tables[x].order.records[i].d = menu.searthDish(s[1]);
if (l == 4) {//普通菜
tables[x].order.records[i].portion = Integer.parseInt(s[2]);
tables[x].order.records[i].num = Integer.parseInt(s[3]);
} else if (l == 5) {//特色菜
tables[x].order.records[i].taste = Integer.parseInt(s[2]);
tables[x].order.records[i].portion = Integer.parseInt(s[3]);
tables[x].order.records[i].num = Integer.parseInt(s[4]);
int c = tables[x].order.records[i].taste;
String b = tables[x].order.records[i].d.breed;
switch (b) {
case "川菜":
if (c > 5 || c < 0)
tables[x].order.records[i].life = 4;
break;
case "晋菜":
if (c > 4 || c < 0)
tables[x].order.records[i].life = 4;
break;
case "浙菜":
if (c > 3 || c < 0)
tables[x].order.records[i].life = 4;
break;
}
}
tables[x].order.records[i].week = tables[x].week;
tables[x].order.records[i].shi = tables[x].shi;
tables[x].order.records[i].fen = tables[x].fen;
} else {//菜品不存在
tables[x].order.records[i].life = 3;
tables[x].order.records[i].name = s[1];
}
}
}
}
}
for (int j=0;j<=x;j++){
if (!tables[j].check()) {
System.out.println("table " + tables[j].num + " out of opening hours");
System.exit(0);
}
else {
System.out.println("table " + tables[j].num + ": ");
for (int p = 0; p <= tables[j].order.i; p++) {
int choice = tables[j].order.records[p].life;
switch (choice) {
case 0:
/*String breed = tables[j].order.records[tables[j].order.i].d.breed;
switch (breed){
case
}*/
System.out.println(tables[j].order.records[p].orderNum + " " + tables[j].order.records[p].d.name + " " + tables[j].order.records[p].ygetPrice());
break;
case 1:
break;
case 2:
System.out.println("delete error;");
break;
case 3:
System.out.println(tables[j].order.records[p].name + " does not exist");
break;
case 4:
switch (tables[j].order.records[p].d.breed) {
case "川菜":
System.out.println("spicy num out of range :" + tables[j].order.records[p].taste);
break;
case "晋菜":
System.out.println("acidity num out of range :" + tables[j].order.records[p].taste);
break;
case "浙菜":
System.out.println("sweetness num out of range :" + tables[j].order.records[p].taste);
break;
}
}
}
}
}
for (int j=0;j<=x;j++){
System.out.print("table " + tables[j].num + ": " + tables[j].order.ygetTotalPrice() + " " + tables[j].order.getTotalPrice());
if (tables[j].order.gettaste1() < 0&&tables[j].order.gettaste2() < 0&&tables[j].order.gettaste3() < 0)
System.out.print(" ");
else {
if (tables[j].order.gettaste1() >= 0) {
System.out.print(" 川菜 " + tables[j].order.tastenum1());
if (tables[j].order.gettaste1() == 0)
System.out.print(" 不辣");
if (tables[j].order.gettaste1() == 1)
System.out.print(" 微辣");
if (tables[j].order.gettaste1() == 2)
System.out.print(" 稍辣");
if (tables[j].order.gettaste1() == 3)
System.out.print(" 辣");
if (tables[j].order.gettaste1() == 4)
System.out.print(" 很辣");
if (tables[j].order.gettaste1() == 5)
System.out.print(" 爆辣");
}
if (tables[j].order.gettaste2() >= 0) {
System.out.print(" 晋菜 " + tables[j].order.tastenum2());
if (tables[j].order.gettaste2() == 0)
System.out.print(" 不酸");
if (tables[j].order.gettaste2() == 1)
System.out.print(" 微酸");
if (tables[j].order.gettaste2() == 2)
System.out.print(" 稍酸");
if (tables[j].order.gettaste2() == 3)
System.out.print(" 酸");
if (tables[j].order.gettaste2() == 4)
System.out.print(" 很酸");
}
if (tables[j].order.gettaste3() >= 0) {
System.out.print(" 浙菜 " + tables[j].order.tastenum3());
if (tables[j].order.gettaste3() == 0)
System.out.print(" 不甜");
if (tables[j].order.gettaste3() == 1)
System.out.print(" 微甜");
if (tables[j].order.gettaste3() == 2)
System.out.print(" 稍甜");
if (tables[j].order.gettaste3() == 3)
System.out.print(" 甜");
}
}
System.out.println("");
}
people[T+1] = new People();
for (int j=0;j<=T;j++){//将顾客排序
for (int q=j+1;q<=T;q++){
if(people[j].name.compareTo(people[q].name)>0) {
people[T+1] = people[j];
people[j] = people[q];
people[q] = people[T+1];
}
}
}
for (int j=0;j<=T;j++){
for (int q=0;q<=x;q++){
if (tables[q].name.equals(people[j].name))
people[j].cost = people[j].cost+tables[q].order.getTotalPrice();
}
if(people[j].check()) {
System.out.println("wrong format");
System.exit(0);
}
System.out.println(people[j].name+" "+people[j].phone+" "+people[j].cost);
}
}
}
class Dish {
String name;//菜品名称
int unit_price; //单价
int life=0;//
boolean special = false;//是否为特价菜
String breed;//品种
public Dish(){
}
int getPrice(int portion){
int s = 0;
if(portion==1)
s = unit_price*1;
if (portion==2)
s = (int) Math.round(unit_price*1.5);
if(portion==3)
s = unit_price*2;
return s;
}//计算菜品价格的方法,输入参数是点菜的份额(输入数据只能是1/2/3,代表小/中/大份)
}
class Menu {
Dish[] dishs = new Dish[10];//菜品数组,保存所有菜品信息
int t=-1;
public Menu(){
}
Dish searthDish(String dishName) {
for (int i = 0;i <= t; i++) {
if (dishName.equals(dishs[i].name)) {
return dishs[i];
}
}
return null;
}
//根据菜名在菜谱中查找菜品信息,返回Dish对象。
}
class Record {
int orderNum;//序号
Dish d;//菜品
int taste = -1;//口味度
int portion;//份额(1/2/3代表小/中/大份)
int num;//数量
int week;//星期几
int shi;
int fen;
int miao;
int life = 0;//初始为0,删除为1,删除不存在为2,菜品不存在为3,特色菜味道超标为4
String name;//不存在的菜品名字
public Record(){
}
int getPrice(){
int s=1;
if(d.special==true) {//特价菜订单价格
if (week <= 5 && week >= 1)
s = (int)Math.round(d.getPrice(portion) * num * 0.7);
else
s = (int) Math.round(d.getPrice(portion) * num);
}
else{//普通菜订单价格
if(week <= 5 && week >= 1) {
if ((shi >= 17 && shi < 20) || (shi == 20 && fen <= 30))
s = (int) Math.round(d.getPrice(portion) * num * 0.8);
else
s = (int) Math.round(d.getPrice(portion) * num * 0.6);
}
else
s = (int) Math.round(d.getPrice(portion) * num);
}
return s;
}//计价,计算本条记录的价格
int ygetPrice(){
int s=1;
s = (int) Math.round(d.getPrice(portion) * num);
return s;
}
}
class Order {
Record[] records = new Record[100];//保存订单上每一道的记录
int i=-1,s=0;//s为点菜数
int year;
int month;
int day;
public Order(){
}
int getTotalPrice(){
int num = 0;
for(s=0;s<=i;s++){
if(records[s].life==0)
num = num + records[s].getPrice();
}
return num;
}//计算订单的总价
int ygetTotalPrice(){
int num = 0;
for(s=0;s<=i;s++){
if(records[s].life==0)
num = num + records[s].ygetPrice();
}
return num;
}//计算订单的原总价
int gettaste1() {
double num = 0;
int x = 0;
for (s = 0; s <= i; s++) {
if (records[s].d.special) {
if (records[s].life == 0 && records[s].d.breed.equals("川菜")) {
num = num + records[s].taste*records[s].num;
x=x+records[s].num;
}
}
}
if(x!=0)
num = (int) Math.round(num/x);
else
num = -1;
return (int)num;
}
int tastenum1(){
int x = 0;
for (s = 0; s <= i; s++) {
if (records[s].d.special) {
if (records[s].life == 0 && records[s].d.breed.equals("川菜")) {
x=x+records[s].num;
}
}
}
return x;
}
int gettaste2() {
double num = 0;
int x=0;
for (s = 0; s <= i; s++) {
if (records[s].d.special) {
if (records[s].life == 0 && records[s].d.breed.equals("晋菜")) {
num = num + records[s].taste*records[s].num;
x = x+records[s].num;
}
}
}
if(x!=0)
num = (int) Math.round(num/x);
else
num = -1;
return (int)num;
}
int tastenum2(){
int x = 0;
for (s = 0; s <= i; s++) {
if (records[s].d.special) {
if (records[s].life == 0 && records[s].d.breed.equals("晋菜")) {
x=x+records[s].num;
}
}
}
return x;
}
int gettaste3() {
double num = 0;
int x=0;
for (s = 0; s <= i; s++) {
if (records[s].d.special) {
if (records[s].life == 0 && records[s].d.breed.equals("浙菜")) {
num = num + records[s].taste*records[s].num;
x = x+records[s].num;
}
}
}
if(x!=0)
num = (int) Math.round(num/x);
else
num = -1;
return (int)num;
}
int tastenum3(){
int x = 0;
for (s = 0; s <= i; s++) {
if (records[s].d.special) {
if (records[s].life == 0 && records[s].d.breed.equals("浙菜")) {
x=x+records[s].num;
}
}
}
return x;
}
public void delARecordByOrderNum(int orderNum){
for (s=0;s<=i;s++){
if(records[s].orderNum==orderNum){
records[s].life = 1;
}
}
}//根据序号删除一条记录
public int findRecordByNum(int orderNum){
for (s=0;s<=i;s++){
if (records[s].orderNum==orderNum)
return s;
}
return -1;
}//根据序号查找一条记录
}
class Table {
Order order;
int num;
int year;
int month;
int day;
int shi;
int fen;
int miao;
int week;
int t=0;
String name;
public Table(){
}
boolean check(){
if(week<6){
if((shi>=17&&shi<=19)||(shi<14&&shi>10))
return true;
else if((shi==20||shi==14)&&fen<=30)
return true;
else if(shi==10&&fen>=30)
return true;
else
return false;
}
else {
if (shi>=10&&shi<=20)
return true;
else if (shi==21&&fen<=30)
return true;
else if(shi==9&&fen>=30)
return true;
else
return false;
}
}
}
class People{
String name;
String phone;
int cost;
public People(){
}
boolean check(){
if(!phone.matches("{11}"))
return false;
if(phone.matches("[181]||[180]||[189]||[133]||[135||[136]"))
return true;
else
return false;
}
}
(2)解释和心得
这次虽然比菜单计价程序-4看起来难,多了口味度,但其实是简单了不是,错误的情况少了很多,口味度看起来麻烦,其实和算价钱一样,不是什么大问题。
class Record {
int orderNum;//序号
Dish d;//菜品
int taste = -1;//口味度
int portion;//份额(1/2/3代表小/中/大份)
int num;//数量
int week;//星期几
我是直接在Record类加了成员teste用于记录口味度
int gettaste1() {
double num = 0;
int x = 0;
for (s = 0; s <= i; s++) {
if (records[s].d.special) {
if (records[s].life == 0 && records[s].d.breed.equals("川菜")) {
num = num + records[s].taste*records[s].num;
x=x+records[s].num;
}
}
}
if(x!=0)
num = (int) Math.round(num/x);
else
num = -1;
return (int)num;
}
int tastenum1(){
int x = 0;
for (s = 0; s <= i; s++) {
if (records[s].d.special) {
if (records[s].life == 0 && records[s].d.breed.equals("川菜")) {
x=x+records[s].num;
}
}
}
return x;
}
int gettaste2() {
double num = 0;
int x=0;
for (s = 0; s <= i; s++) {
if (records[s].d.special) {
if (records[s].life == 0 && records[s].d.breed.equals("晋菜")) {
num = num + records[s].taste*records[s].num;
x = x+records[s].num;
}
}
}
if(x!=0)
num = (int) Math.round(num/x);
else
num = -1;
return (int)num;
}
int tastenum2(){
int x = 0;
for (s = 0; s <= i; s++) {
if (records[s].d.special) {
if (records[s].life == 0 && records[s].d.breed.equals("晋菜")) {
x=x+records[s].num;
}
}
}
return x;
}
int gettaste3() {
double num = 0;
int x=0;
for (s = 0; s <= i; s++) {
if (records[s].d.special) {
if (records[s].life == 0 && records[s].d.breed.equals("浙菜")) {
num = num + records[s].taste*records[s].num;
x = x+records[s].num;
}
}
}
if(x!=0)
num = (int) Math.round(num/x);
else
num = -1;
return (int)num;
}
int tastenum3(){
int x = 0;
for (s = 0; s <= i; s++) {
if (records[s].d.special) {
if (records[s].life == 0 && records[s].d.breed.equals("浙菜")) {
x=x+records[s].num;
}
}
}
return x;
}
再在order类编写计算方法。
(3)题目集11(7-2)课程成绩统计程序-2
课程成绩统计程序-3在第二次的基础上修改了计算总成绩的方式,
要求:修改类结构,将成绩类的继承关系改为组合关系,成绩信息由课程成绩类和分项成绩类组成,课程成绩类组合分项成绩类,分项成绩类由成绩分值和权重两个属性构成。
完成课程成绩统计程序-2、3两次程序后,比较继承和组合关系的区别。思考一下哪一种关系运用上更灵活,更能够适应变更。
题目最后的参考类图未做修改,大家根据要求自行调整,以下内容加粗字体显示的内容为本次新增的内容。
某高校课程从性质上分为:必修课、选修课、实验课,从考核方式上分为:考试、考察、实验。
考试的总成绩由平时成绩、期末成绩分别乘以权重值得出,比如平时成绩权重0.3,期末成绩权重0.7,总成绩=平时成绩0.3+期末成绩0.7。
考察的总成绩直接等于期末成绩
实验的总成绩等于课程每次实验成绩乘以权重后累加而得。
课程权重值在录入课程信息时输入。(注意:所有分项成绩的权重之和应当等于1)
必修课的考核方式必须为考试,选修课可以选择考试、考察任一考核方式。实验课的成绩必须为实验。
1、输入:
包括课程、课程成绩两类信息。
课程信息包括:课程名称、课程性质、考核方式、分项成绩数量、每个分项成绩的权重。
考试课信息格式:课程名称+英文空格+课程性质+英文空格+考核方式+英文空格+平时成绩的权重+英文空格+期末成绩的权重
考察课信息格式:课程名称+英文空格+课程性质+英文空格+考核方式
实验课程信息格式:课程名称+英文空格+课程性质+英文空格+考核方式+英文空格+分项成绩数量n+英文空格+分项成绩1的权重+英文空格+。。。+英文空格+分项成绩n的权重
实验次数至少4次,不超过9次
课程性质输入项:必修、选修、实验
考核方式输入选项:考试、考察、实验
考试/考查课程成绩信息包括:学号、姓名、课程名称、平时成绩(可选)、期末成绩
考试/考查课程成绩信息格式:学号+英文空格+姓名+英文空格+课程名称+英文空格+平时成绩+英文空格+期末成绩
实验课程成绩信息包括:学号、姓名、课程名称、每次成绩{在系列-2的基础上去掉了(实验次数),实验次数要和实验课程信息中输入的分项成绩数量保持一致}
实验课程信息格式:学号+英文空格+姓名+英文空格+课程名称+英文空格+第一次实验成绩+...+英文空格+最后一次实验成绩
以上信息的相关约束:
1)成绩是整数,不包含小数部分,成绩的取值范围是【0,100】
2)学号由8位数字组成
3)姓名不超过10个字符
4)课程名称不超过10个字符
5)不特别输入班级信息,班级号是学号的前6位。
2、输出:
输出包含三个部分,包括学生所有课程总成绩的平均分、单门课程总成绩平均分、班级所有课程总成绩平均分。
为避免四舍五入误差,
计算单个成绩时,分项成绩乘以权重后要保留小数位,计算总成绩时,累加所有分项成绩的权重分以后,再去掉小数位。
学生总成绩/整个班/课程平均分的计算方法为累加所有符合条件的单个成绩,最后除以总数。
1)学生课程总成绩平均分按学号由低到高排序输出
格式:学号+英文空格+姓名+英文空格+总成绩平均分
如果某个学生没有任何成绩信息,输出:学号+英文空格+姓名+英文空格+"did not take any exams"
2)单门课程成绩按课程名称的字符顺序输出
课程成绩输出格式:课程名称+英文空格+总成绩平均分
如果某门课程没有任何成绩信息,输出:课程名称+英文空格+"has no grades yet"
3)班级所有课程总成绩平均分按班级由低到高排序输出
格式:班级号+英文空格+总成绩平均分
如果某个班级没有任何成绩信息,输出:班级名称+英文空格+ "has no grades yet"
异常情况:
1)如果解析某个成绩信息时,课程名称不在已输入的课程列表中,输出:学号+英文空格+姓名+英文空格+":"+课程名称+英文空格+"does not exist"
2)如果解析某个成绩信息时,输入的成绩数量和课程的考核方式不匹配,输出:学号+英文空格+姓名+英文空格+": access mode mismatch"
以上两种情况如果同时出现,按第一种情况输出结果。
3)如果解析某个课程信息时,输入的课程性质和课程的考核方式不匹配,输出:课程名称+" : course type & access mode mismatch"
4)格式错误以及其他信息异常如成绩超出范围等,均按格式错误处理,输出"wrong format"
5)若出现重复的课程/成绩信息,只保留第一个课程信息,忽略后面输入的。
6)如果解析实验课程信息时,输入的分项成绩数量值和分项成绩权重的个数不匹配,输出:课程名称+" : number of scores does not match"
7)如果解析考试课、实验课时,分项成绩权重值的总和不等于1,输出:课程名称+" : weight value error"
信息约束:
1)成绩平均分只取整数部分,小数部分丢弃
(1)代码如下
import java.util.*;
import java.text.*;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
CourseSelection courseSelection = new CourseSelection();
Course course = new Course();
Student student = new Student();
Score score = new Score();
Class classes = new Class();
ArrayList<Class> classArrayList = new ArrayList<>();
ArrayList<String> list = new ArrayList<>();
String a;
int i,j,k,q=0,sum;
double n=0;
float f=0;
while (true){
q=0;
a = input.nextLine();
for (int x=1;x<list.size();x++){
if (list.contains(a))
q=1;
}
if (q!=0)
continue;
list.add(a);
if(a.matches("end"))
break;
String[] s = a.split(" ");
int size = s.length;
if(!s[0].matches("[0-9]*")) {//课程
q = 0;
for (int x = 0; x < courseSelection.courseArrayList.size(); x++) {
if (courseSelection.courseArrayList.get(x).name.equals(s[0]))
q = 1;
}
if (q != 0)
continue;
course = new Course();
course.name = s[0];
course.attribute = s[1];
course.method = s[2];
if (s[1].matches("实验") && (Integer.parseInt(s[3]) > 9 || Integer.parseInt(s[3]) < 4)) {
System.out.println("wrong format");
continue;
}
if ((s[1].matches("必修") && !s[2].matches("考试")) ||(s[1].matches("考察")&&s[2].matches("实验")) ||(s[1].matches("实验") && !s[2].matches("实验"))) {
System.out.println(s[0] + " : course type & access mode mismatch");
continue;
}
if (s[1].matches("必修")){
if (Double.parseDouble(s[3])+Double.parseDouble(s[4])!=1) {
System.out.println(s[0] + " : weight value error");
continue;
}
}
if (s[1].matches("实验")){
if (Integer.parseInt(s[3])!=s.length-4) {//实验次数和权重数不等
System.out.println(s[0] + " : number of scores does not match");
continue;
}
for (i=4;i<s.length;i++){
n += Double.parseDouble(s[i]);
}
if (n!=1) {//权重不等于1
System.out.println(s[0] + " : weight value error");
continue;
}
}
if (s[1].matches("必修")){
course.score0weight = Float.parseFloat(s[3]);
course.score1weight = Float.parseFloat(s[4]);
}
if (s[1].matches("实验")){
for (i=4;i<s.length;i++)
course.arrayList.add(Float.parseFloat(s[i]));
}
courseSelection.courseArrayList.add(course);
}
else {//学生和分数
f=0;
q=0;
student = new Student();
score = new Score();
classes = new Class();
student.id = s[0];
student.classes = s[0].substring(0,6);
student.name = s[1];
score.id = s[0];
score.name = s[1];
score.course = s[2];
for (i=0;i<courseSelection.scoreArrayList.size();i++){
if (s[0].matches(courseSelection.scoreArrayList.get(i).id)&&s[1].matches(courseSelection.scoreArrayList.get(i).name)&&s[2].matches(courseSelection.scoreArrayList.get(i).course))
q=1;
}
if (q!=0)
break;
if (s[0].length()!=8||s[1].length()>10){
System.out.println("wrong format");
continue;
}
if (size>4) {//检查成绩是否超过范围
for (i=3;i<size;i++) {
if (Integer.parseInt(s[i])>100||Integer.parseInt(s[i])<0) {
System.out.println("wrong format");
q=1;
}
}
if (size>5&&size<7){
System.out.println("wrong format");
q=1;
}
if (q!=0)
continue;
}
for (i =0;i<classArrayList.size();i++){//查找班级是否存在,存在时的位置classArrayList.get(i),
if(classArrayList.get(i).classname.matches(s[0].substring(0,6)))
break;
}
if (i== classArrayList.size()||classArrayList.size()==0) {//班级不存在
classes.classname = s[0].substring(0,6);
classArrayList.add(classes);
}
for (j=0;j<courseSelection.studentArrayList.size();j++){//寻找学生在学生数组的位置
if (courseSelection.studentArrayList.get(j).id.matches(s[0]))
break;
}
if (j==courseSelection.studentArrayList.size()||courseSelection.studentArrayList.size()==0) {//学生之前没出现
courseSelection.studentArrayList.add(student);
classArrayList.get(i).ClassStuent.add(s[0]);
}
for (k=0;k<courseSelection.courseArrayList.size();k++){//寻找输入课程在课程数组的位置
if (courseSelection.courseArrayList.get(k).name.equals(s[2]))
break;
}
if (k==courseSelection.courseArrayList.size()) {//课程不存在
System.out.println(s[2] + " does not exist");
break;
}
else {//课程存在
if ((courseSelection.courseArrayList.get(k).method.matches("考试")&&size!=5)||(courseSelection.courseArrayList.get(k).method.matches("实验")&&s.length-3!=courseSelection.courseArrayList.get(k).arrayList.size())) {//输入的成绩数量和课程的考核方式不匹配
System.out.println(s[0] + " " + s[1] + " : access mode mismatch");
continue;
}
else if (courseSelection.courseArrayList.get(k).method.matches("考察")&&size==5) {
System.out.println(s[0] + " " + s[1] + " : access mode mismatch");
continue;
}
/*else if (courseSelection.courseArrayList.get(k).method.matches("实验")&&(size<8||size>13)){
System.out.println(s[0] + " " + s[1] + " : access mode mismatch");
break;
}*/
else {
if (size==4)//考察
score.score2 = Integer.parseInt(s[3]);
else if (size==5){//考试
score.score1 = Float.parseFloat(s[3])*courseSelection.courseArrayList.get(k).score0weight;
score.score2 = Float.parseFloat(s[4])*courseSelection.courseArrayList.get(k).score1weight;
}
else {//实验
for (int x = 3; x < size; x++)
f = f + Integer.parseInt(s[x])*courseSelection.courseArrayList.get(k).arrayList.get(x-3);
score.score2 = (int)f;
}
}
}
courseSelection.scoreArrayList.add(score);
}
}
for (i=0;i<courseSelection.studentArrayList.size();i++){//按学号给学生数组排序
for (j=i+1;j<courseSelection.studentArrayList.size();j++){
if (courseSelection.studentArrayList.get(i).id.compareTo(courseSelection.studentArrayList.get(j).id)>0) {
Collections.swap(courseSelection.studentArrayList, i, j);
}
}
}
Collator collator= Collator.getInstance(Locale.CHINA);
for (i=0;i<courseSelection.courseArrayList.size();i++){//按名字给课程数组排序
for (j=i+1;j<courseSelection.courseArrayList.size();j++){
if (collator.compare(courseSelection.courseArrayList.get(i).name, courseSelection.courseArrayList.get(j).name)>0)
Collections.swap(courseSelection.courseArrayList,i,j);
}
}
for (i=0;i<courseSelection.scoreArrayList.size();i++){//将成绩数组的所以分数加到学生
for (j=0;j<courseSelection.studentArrayList.size();j++) {
if (courseSelection.scoreArrayList.get(i).id.equals(courseSelection.studentArrayList.get(j).id)) {
break;
}
}
courseSelection.studentArrayList.get(j).score= courseSelection.studentArrayList.get(j).score+courseSelection.scoreArrayList.get(i).score1+courseSelection.scoreArrayList.get(i).score2;
courseSelection.studentArrayList.get(j).numm++;
}
for (i=0;i<courseSelection.studentArrayList.size();i++){//将学生总分转换为平均总分
if (courseSelection.studentArrayList.get(i).numm!=0) {
courseSelection.studentArrayList.get(i).score = courseSelection.studentArrayList.get(i).score / courseSelection.studentArrayList.get(i).numm;
}
}
for (i=0;i<classArrayList.size();i++){//计算班级平均分
for (j=0;j<courseSelection.studentArrayList.size();j++){
if (classArrayList.get(i).classname.matches(courseSelection.studentArrayList.get(j).classes))
classArrayList.get(i).score += courseSelection.studentArrayList.get(j).score;
}
classArrayList.get(i).score /= classArrayList.get(i).ClassStuent.size();
}
for (i=0;i<courseSelection.courseArrayList.size();i++){//计算课程平均分
for (j=0;j<courseSelection.scoreArrayList.size();j++){
if(courseSelection.courseArrayList.get(i).name.matches(courseSelection.scoreArrayList.get(j).course)){
courseSelection.courseArrayList.get(i).score0+=courseSelection.scoreArrayList.get(j).score1;
courseSelection.courseArrayList.get(i).score1+=courseSelection.scoreArrayList.get(j).score2;
courseSelection.courseArrayList.get(i).num++;
}
}
if(courseSelection.courseArrayList.get(i).score0!=0) {
courseSelection.courseArrayList.get(i).score1 = courseSelection.courseArrayList.get(i).score1/courseSelection.courseArrayList.get(i).num;
courseSelection.courseArrayList.get(i).score0 = courseSelection.courseArrayList.get(i).score0/courseSelection.courseArrayList.get(i).num;
courseSelection.courseArrayList.get(i).score2 += courseSelection.courseArrayList.get(i).score0 * 0.3 ;
courseSelection.courseArrayList.get(i).score2 +=courseSelection.courseArrayList.get(i).score1 * 0.7 ;
}
else {
if (courseSelection.courseArrayList.get(i).num!=0) {
courseSelection.courseArrayList.get(i).score2 = courseSelection.courseArrayList.get(i).score1 / courseSelection.courseArrayList.get(i).num;
courseSelection.courseArrayList.get(i).score1 = courseSelection.courseArrayList.get(i).score1/courseSelection.courseArrayList.get(i).num;
}
}
}
for (i=0;i<classArrayList.size();i++){//按班级从高到低排序
for (j=i+1;j<classArrayList.size();j++){
if (classArrayList.get(i).classname.compareTo(classArrayList.get(j).classname)>0)
Collections.swap(classArrayList,i,j);
}
}
for (i=0;i<courseSelection.studentArrayList.size();i++){//输出学生
if (courseSelection.studentArrayList.get(i).numm==0) {
System.out.println(courseSelection.studentArrayList.get(i).id + " " + courseSelection.studentArrayList.get(i).name + " did not take any exams");
continue;
}
System.out.println(courseSelection.studentArrayList.get(i).id+" "+courseSelection.studentArrayList.get(i).name+" "+(int)courseSelection.studentArrayList.get(i).score);
}
for (i=0;i<courseSelection.courseArrayList.size();i++){//输出课程
System.out.print(courseSelection.courseArrayList.get(i).name+" ");
if (courseSelection.courseArrayList.get(i).score2==0){//课程没有分数
System.out.println("has no grades yet");
}
else {
if (courseSelection.courseArrayList.get(i).method.matches("考试"))
System.out.print(courseSelection.courseArrayList.get(i).score0 + " ");
if (!courseSelection.courseArrayList.get(i).method.matches("实验"))
System.out.println(courseSelection.courseArrayList.get(i).score1 + " " + courseSelection.courseArrayList.get(i).score2);
else
System.out.println(courseSelection.courseArrayList.get(i).score2);
}
}
for (i=0;i<classArrayList.size();i++){//输出班级
if (classArrayList.get(i).score==0){
System.out.println(classArrayList.get(i).classname+" has no grades yet");
}
else
System.out.println(classArrayList.get(i).classname+" "+classArrayList.get(i).score);
}
}
public static class Score {//成绩
String id;//成绩的主人的学号
String name;
String course;//什么科目的成绩
float score1 = 0;//平时成绩
float score2 = 0;//期末成绩
public Score(){
}
}
public static class Student {
String id;//学号
String name;//名字
String classes;//班级
float score=0;//总分
int numm=0;
public Student(){
}
}
public static class Class {//班级
String classname;
ArrayList<String> ClassStuent = new ArrayList<>();//学生学号
int score=0;
public Class(){
}
}
public static class Course {//课程
String name;//课程名称
String attribute;//选修还是必修
String method;//考核方式
int num;//学生人数
int score0=0;//平时成绩
float score0weight;
int score1=0;//期末成绩
float score1weight;
ArrayList<Float> arrayList= new ArrayList<>();//实验权重
int score2=0;//总成绩
public Course(){
}
}
public static class CourseSelection {//选课
ArrayList<Student> studentArrayList = new ArrayList<>();
ArrayList<Course> courseArrayList = new ArrayList<>();
ArrayList<Score> scoreArrayList = new ArrayList<>();
public CourseSelection(){
}
}
public static class Examination extends Score {//必修成绩
int finalscore;//期末成绩
int dailyscore;//平时成绩
int finalweight;
int dailyweight;
public Examination(){
}
}
public static class experiment {
}
public static class Investigate extends Score {//考察成绩
int score;
public Investigate(){
}
}
}
(2)解释与心得
3相比2主要多了权重,计算和错误也主要是增加这个相关
if (s[1].matches("实验")){
if (Integer.parseInt(s[3])!=s.length-4) {//实验次数和权重数不等
System.out.println(s[0] + " : number of scores does not match");
continue;
}
for (i=4;i<s.length;i++){
n += Double.parseDouble(s[i]);
}
if (n!=1) {//权重不等于1
System.out.println(s[0] + " : weight value error");
continue;
}
}
记录实验课程时要考虑权重之和
public static class Course {//课程
String name;//课程名称
String attribute;//选修还是必修
String method;//考核方式
int num;//学生人数
int score0=0;//平时成绩
float score0weight;
int score1=0;//期末成绩
float score1weight;
ArrayList<Float> arrayList= new ArrayList<>();//实验权重
考试的成绩权重就两个可以直接创建2个float类来记录,实验的成绩权重个数不定,最好不用数组来记录,用arraylist记录会更方便。
三.踩坑心得
在题目集9 统计Java程序中关键词的出现次数中,不知道为什么我要加个s = s.replace("=", "a");才对,只有等于号要,这个不知道出什么问题了。课程成绩统计程序-2中,因为这时候实验没有权重,我没用单独增加成员,直接把实验的成绩和必修的考试放一起,这样虽然在课程成绩统计程序-2中更简单,但在课程成绩统计程序-3中却行不通,要重写,很麻烦。
四.改进建议
课程成绩统计程序在检查完所以输入数据后才开始计算,可以边检查边计算。
五.总结
经过多次的设计程序题,对结构的掌握更加透彻了,更加深入的了解了正则表达式,而且正则表达式不只有matcher,pattern也很有用,学到了map和arrarylist等非常有用的数组和队列和很多方便的排序方法。
课程评价
教学理念:讲的东西非常有用不只是为了考试,而是编程理念,对未来编程也会很有帮助。教学方法:我不喜欢一味的讲,所以还是很喜欢这种边讲边练的方法,很适合我。教学组织:网上有网课可以方便自己预习和复习,感觉很好。教学过程:老师题目的布置逐层深入和学习方向的引导,很适合大学的自学氛围,虽然大学讲究自学,但老师的教学方式太过放养了。像构造系统的稍微讲一讲,虽然不同的人构建方式不同,不要求详细讲,但给些提示和思路,有些时候就是自己想不到,同学也起不来作用,即使多练也很难有所长进。教学模式:学习的重点抓的很好,节奏很舒服
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律