面向对象程序设计题目集总结blog3

发布时间 2023-06-27 23:04:10作者: 临枫、

一、前言

  本次是第三次对面向对象程序设计题目集的总结分析博客。

 

  • 关于知识点

    本次的题目集所体现的知识点重点考虑设计问题,许多题目不提供类图,或者只提供一个参考框架(只有类和类之间的关系),题目的代码量也较于前几次提升了不少。题目集七注重类的设计,通过三道设计图形类题目,逐步实现继承、多态、接口的实现。第三题是在第二题的基础上添加新的需求,增加了一个工具类并使用arraylist将对象添加进去,实现找最值、排序、求和等功能,排序可以使用comparable的接口来实现。题目集八是设计卡片分组游戏,第二题也是直接在第一题的基础上进行增加功能。题目集九是实现对代码中的关键字的提取和计数。题目集十-十二中主要是学生成绩统计程序以及一些set、list、map集合容器的训练。

 

  • 关于题量

    题量比较适中,但是花费的时间并不少,需要对题目有透彻的理解和较好的理解类之间的关系并设计类。

 

  • 关于难度

    本次的学生成绩统计程序难度较大且需要花费较多的时间,写这类题的时候还是需要有清醒的头脑,弄清类之间的关系。除此之外,如何设计出方法来实现题目的需求是十分关键的,方法的调用和方法体内容需要符合要求,而且还要考虑面向对象的设计原则。综合考虑,想写出一份良好的代码是不容易的。

 

二、设计与分析

  • 题目集七 7-3 图形继承、多态、接口及集合框架

在“图形继承与多态”题目的基础上,编程实现如下面类图所示功能。

ClassDiagram.jpg

说明如下:

  • AbstractShape为抽象类,getArea()方法含义为求图形面积,show()方法含义为输出图形信息。该类需实现Comparable接口,以便可以对图形面积进行比较大小或排序
  • Rectangle为矩形类,属性为宽度width和长度length,为AbstractShape类的子类
  • Box为立方体类,属性为宽度width、长度length和高度height,为Rectangle类的子类,其求面积方法为求其表面积
  • Circle为圆类,属性为半径radius,为AbstractShape类的子类
  • Ball为圆球类,属性为半径radius,为Circle类的子类,其求面积方法为求其表面积
  • ShapeUtil为图形工具类,其中的方法说明如下:
    • init()方法功能为初始化,即用户可以循环输入多个图形对象并添加进list中
    • shapeSort()方法为对list中的对象按面积大小进行升序排序操作
    • Max()方法为返回list中面积值最大的对象
    • Min()方法为返回list中面积值最小的对象
    • getSumArea()方法返回list中所有对象的面积之和
    • show()方法为输出相关信息,具体参见输出示例

题目要求:
运行程序,首先在主方法中调用ShapeUtil类的init()方法进行图形对象初始化,用户循环输入要进行的操作(choice∈[1,4]),其含义如下:

  1. 创建Circle对象,并加入到list
  2. 创建Rectangle对象,并加入到list
  3. 创建Ball对象,并加入到list
  4. 创建Box对象,并加入到list

示例代码如下:

public void init() {                
        int choice = Main.input.nextInt();

        while (choice >= 1 && choice <= 4) {
            switch (choice) {            
            case 1:
                ...
                list.add(Circle对象);
                choice = Main.input.nextInt();
                break;
            case 2:
                ...
                list.add(Rectangle对象);
                choice = Main.input.nextInt();
                break;
            case 3:
                ...
                list.add(Ball对象);
                choice = Main.input.nextInt();
                break;
            case 4:
                ...
                list.add(Box对象);
                choice = Main.input.nextInt();
                break;
            default:
                return;
            }
        }
        
    }

注意:由于程序中有两个类要用到Scanner类的对象input,因此必须把input对象定义在Main类中,并定义为静态对象,示例代码如下:

public class Main {
    public static Scanner input = new Scanner(System.in);
    ...
}

接下来,在主方法中用户循环输入要进行的操作(choice∈[1,4]),其含义如下:

  1. 获取list中的面积最大图形并输出该对象信息
  2. 获取list中的面积最小图形并输出该对象信息
  3. 求取list中所有图形对象的面积之和
  4. 对list中所有的图形对象按照面积大小升序排序,并输出排序后的对象信息

具体输出可参考输出格式及样例

输入格式:

循环输入图形类型(1~4)及图形属性信息,以输入0结束
用户输入操作选择(1~4),各输入之间可以空格或回车分隔

输出格式:

操作选项1输出:

MAX:Type:图形类名,Area:最大图形面积值

 

操作选项2输出:

Min:Type:图形类名,Area:最小图形面积值
 

操作选项3输出:

Sum of area:所有图形面积值
 

操作选项4输出(按面积从小到大依次输出):

The sorted shape:
Type:图形类名,Area:该图形面积值
Type:图形类名,Area:该图形面积值
...
 

注:输出面积值均保留两位小数

评分标准:


  • 首次提交的最高分源码为得分源码并参加查重
  • 有语法错误无法运行判定为无效代码
  • 无法通过所有测试点判定为无效代码
  • 程序设计不符合题目已给类图设计要求判定为无效代码

输入样例1:

在这里给出一组输入。例如:

1
2.3
2
3.6
5.2
3
5.2
4
6.56
3.21
6.47
1
0.5
0
1

输出样例1:

在这里给出相应的输出。例如:

 
MAX:Type:Ball,Area:339.79

输入样例2:

在这里给出一组输入。例如:

 
1
2.3
2
3.6
5.2
3
5.2
4
6.56
3.21
6.47
1
0.5
0
2

输出样例2:

在这里给出相应的输出。例如:

MIN:Type:Circle,Area:0.79
 

输入样例3:

在这里给出一组输入。例如:

1
2.3
2
3.6
5.2
3
5.2
4
6.56
3.21
6.47
1
0.5
0
3

 

输出样例3:

在这里给出相应的输出。例如:

Sum of area:544.46
 

输入样例4:

在这里给出一组输入。例如:

1
2.3
2
3.6
5.2
3
5.2
4
6.56
3.21
6.47
1
0.5
0
4
 

输出样例4:

在这里给出相应的输出。例如:

The sorted shape:
Type:Circle,Area:0.79
Type:Circle,Area:16.62
Type:Rectangle,Area:18.72
Type:Box,Area:168.54
Type:Ball,Area:339.79
源码:
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
class Main {
    public static Scanner input = new Scanner(System.in);
    public static void main(String[] args) {
        ShapeUtil shapeUtil = new ShapeUtil();
        shapeUtil.init();
        shapeUtil.show();
    }

}

class Rectangle extends AbstractShape {
    private double width;
    private double length;

    public Rectangle() {
    }

    public Rectangle(double width, double length) {
        this.width = width;
        this.length = length;
    }

    public double getWidth() {
        return width;
    }

    public void setWidth(double width) {
        this.width = width;
    }

    public double getLength() {
        return length;
    }

    public void setLength(double length) {
        this.length = length;
    }

    @Override
    public double getArea() {
        return getLength() * getWidth();
    }//计算矩形的面积

    @Override
    public void show() {
        System.out.println("Type:Rectangle,Area:" + String.format("%.2f", getArea()));
    }//输出格式
}

class Box extends Rectangle {
    private double height;

    public Box() {
    }

    public Box(double width, double length, double height) {
        super(width, length);
        this.height = height;
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }

    @Override
    public double getArea() {
        return (super.getArea() + super.getLength() * getHeight() + super.getWidth() * getHeight()) * 2;
    }//计算长方体的面积

    @Override
    public void show() {
        System.out.println("Type:Box,Area:" + String.format("%.2f", getArea()));
    }//输出格式
}

class Circle extends AbstractShape{
    private double radius;

    public Circle() {
    }

    public Circle(double radius) {
        this.radius = radius;
    }

    public double getRadius() {
        return radius;
    }

    public void setRadius(double radius) {
        this.radius = radius;
    }

    @Override
    public double getArea() {
        return Math.PI * Math.pow(getRadius(), 2);
    }//计算圆的面积

    @Override
    public void show() {
        System.out.println("Type:Circle,Area:" + String.format("%.2f", getArea()));
    }//输出格式
}

class Ball extends Circle {
    public Ball() {

    }

    public Ball(double radius) {
        super(radius);
    }

    @Override
    public double getArea() {
        return super.getArea() * 4;
    }//计算球的表面积

    @Override
    public void show() {
        System.out.println("Type:Ball,Area:" + String.format("%.2f", getArea()));
    }//输出格式
}

abstract class AbstractShape implements Comparable<AbstractShape> {
    public double getArea() {
        return 0.0;
    }

    public void show() {
    }

    public int compareTo (AbstractShape shape) {
        return Double.compare(getArea(), shape.getArea());
    }//进行面积的比较
}

class ShapeUtil {
    private ArrayList<AbstractShape> list = new ArrayList<>();

    public ShapeUtil() {
    }

    public void init() {
        int choice = Main.input.nextInt();
        while (choice >= 1 && choice <= 4) {
            switch (choice) {
                case 1:
                    Circle circle = new Circle();
                    double radius = Main.input.nextDouble();//获取圆的半径
                    if (radius > 0) {
                        circle.setRadius(radius);//设置圆的半径
                    } else {
                        System.out.print("Wrong Format");
                    }
                    list.add(circle);//添加对象
                    choice = Main.input.nextInt();
                    break;
                case 2:
                    Rectangle rectangle = new Rectangle();
                    double width = Main.input.nextDouble();
                    double length = Main.input.nextDouble();
                    if (width > 0 && length > 0) {
                        rectangle.setWidth(width);
                        rectangle.setLength(length);//设置矩形的长和宽
                    } else {
                        System.out.print("Wrong Format");
                    }
                    list.add(rectangle);//添加对象
                    choice = Main.input.nextInt();
                    break;
                case 3:
                    Ball ball = new Ball();
                    double radius1 = Main.input.nextDouble();
                    if (radius1 > 0) {
                        ball.setRadius(radius1);//设置球的半径
                    } else {
                        System.out.print("Wrong Format");
                    }
                    list.add(ball);//添加对象
                    choice = Main.input.nextInt();
                    break;
                case 4:
                    Box box = new Box();
                    double width1 = Main.input.nextDouble();
                    double length1 = Main.input.nextDouble();
                    double height = Main.input.nextDouble();
                    if (width1 > 0 && length1 > 0 && height > 0) {
                        box.setWidth(width1);
                        box.setLength(length1);
                        box.setHeight(height);//设置长方体的长宽高
                    } else {
                        System.out.print("Wrong Format");
                    }
                    list.add(box);//添加对象
                    choice = Main.input.nextInt();
                    break;
                case 0:
                    break;//输入0推出循环
                default:
                    System.out.println("Wrong Format");
                    return;
            }
        }
    }

    public void shapeSort() {
        Collections.sort(list);//根据面积进行排序
    }

    public AbstractShape Max() {
        return list.get(list.size() - 1);
    }

    public AbstractShape Min() {
        return list.get(0);
    }

    public double getSumArea() {
        double sum = 0;
        for (AbstractShape shape : list) {
            sum += shape.getArea();
        }
        return sum;//计算总面积
    }

    public void show() {
        int choices = Main.input.nextInt();
        shapeSort();
        if (choices == 1) {
            System.out.print("MAX:");
            Max().show();
        } else if (choices == 2) {
            System.out.print("MIN:");
            Min().show();
        } else if (choices == 3) {
            System.out.print("Sum of area:" + String.format("%.2f", getSumArea()));
        } else if (choices == 4) {
            System.out.println("The sorted shape:");
            for (AbstractShape shape : list) {
                shape.show();
            }
        } else {
            System.out.print("Wrong Format");
        }//输出格式
    }
}

powerdesigner生成类图:

 

sourcemonitor代码分析:

 从sourcemonitor上显示的来看,部分指标还是超出了合理的范围。本道题主要是图形类的题目,输入图形的数据进行计算总面积、排序、找最值等功能。Rectangle、Box、Circle和Ball类继承自AbstractShape类,并重写其中的计算面积、show方法。同时设计出ShapeUtil类作为一个工具类实现题目所需的功能,利用arraylist进行存储对象。在AbstractShape类上实现了comparable的接口,进行对面积的比较。

题目集八中的图形卡片分组游戏类似上题,对各种图形计算面积并排序等,只是添加了一个归类的功能,将同一类型的图形放置在一起输出。

 

  • 题目集八 7-2 图形卡片分组游戏

 

 

掌握类的继承、多态性使用方法以及接口的应用。 具体需求参考作业指导书。

 

2021-OO第07次作业-2指导书V1.0.pdf

 

输入格式:

 

  • 在一行上输入一串数字(1~4,整数),其中,1代表圆形卡片,2代表矩形卡片,3代表三角形卡片,4代表梯形卡片。各数字之间以一个或多个空格分隔,以“0”结束。例如:1 3 4 2 1 3 4 2 1 3 0
  • 根据第一行数字所代表的卡片图形类型,依次输入各图形的相关参数,例如:圆形卡片需要输入圆的半径,矩形卡片需要输入矩形的宽和长,三角形卡片需要输入三角形的三条边长,梯形需要输入梯形的上底、下底以及高。各数据之间用一个或多个空格分隔。

 

输出格式:

 

  • 如果图形数量非法(<=0)或图形属性值非法(数值<0以及三角形三边不能组成三角形),则输出Wrong Format
  • 如果输入合法,则正常输出,所有数值计算后均保留小数点后两位即可。输出内容如下:

 

  1. 排序前的各图形类型及面积,格式为[图形名称1:面积值1图形名称2:面积值2 …图形名称n:面积值n ],注意,各图形输出之间用空格分开,且输出最后存在一个用于分隔的空格,在结束符“]”之前;
  2. 输出分组后的图形类型及面积,格式为[圆形分组各图形类型及面积][矩形分组各图形类型及面积][三角形分组各图形类型及面积][梯形分组各图形类型及面积],各组内格式为图形名称:面积值。按照“Circle、Rectangle、Triangle、Trapezoid”的顺序依次输出;
  3. 各组内图形排序后的各图形类型及面积,格式同排序前各组图形的输出;
  4. 各组中面积之和的最大值输出,格式为The max area:面积值

 

输入样例1:

 

在这里给出一组输入。例如:

 

1 5 3 2 0

 

输出样例1:

 

在这里给出相应的输出。例如:

 

Wrong Format

 

输入样例2:

 

在这里给出一组输入。例如:

 

4 2 1 3 0
3.2 2.5 0.4 2.3 1.4 5.6 2.3 4.2 3.5

 

输出样例2:

 

在这里给出相应的输出。例如:

 

The original list:
[Trapezoid:1.14 Rectangle:3.22 Circle:98.52 Triangle:4.02 ]
The Separated List:
[Circle:98.52 ][Rectangle:3.22 ][Triangle:4.02 ][Trapezoid:1.14 ]
The Separated sorted List:
[Circle:98.52 ][Rectangle:3.22 ][Triangle:4.02 ][Trapezoid:1.14 ]
The max area:98.52

 

输入样例3:

 

在这里给出一组输入。例如:

 

2 1 2 1 1 3 3 4 4 1 1 1 2 1 0
2.3 3.5 2.5 4.5 2.1 2.6 8.5 3.2 3.1 3.6 8.5 7.5 9.1245 6.5 3.4 10.2 11.2 11.6 15.4 5.8 2.13 6.2011 2.5 6.4 18.65

 

输出样例3:

 

在这里给出相应的输出。例如:

 

The original list:
[Rectangle:8.05 Circle:19.63 Rectangle:9.45 Circle:21.24 Circle:226.98 Triangle:4.65 Triangle:29.80 Trapezoid:50.49 Trapezoid:175.56 Circle:105.68 Circle:14.25 Circle:120.81 Rectangle:16.00 Circle:1092.72 ]
The Separated List:
[Circle:19.63 Circle:21.24 Circle:226.98 Circle:105.68 Circle:14.25 Circle:120.81 Circle:1092.72 ][Rectangle:8.05 Rectangle:9.45 Rectangle:16.00 ][Triangle:4.65 Triangle:29.80 ][Trapezoid:50.49 Trapezoid:175.56 ]
The Separated sorted List:
[Circle:1092.72 Circle:226.98 Circle:120.81 Circle:105.68 Circle:21.24 Circle:19.63 Circle:14.25 ][Rectangle:16.00 Rectangle:9.45 Rectangle:8.05 ][Triangle:29.80 Triangle:4.65 ][Trapezoid:175.56 Trapezoid:50.49 ]
The max area:1601.31

 

输入样例4:

 

在这里给出一组输入。例如:

 

1 1 3 0
6.5 12.54 3.6 5.3 6.4

 

输出样例4:

 

在这里给出相应的输出。例如:

 

The original list:
[Circle:132.73 Circle:494.02 Triangle:9.54 ]
The Separated List:
[Circle:132.73 Circle:494.02 ][][Triangle:9.54 ][]
The Separated sorted List:
[Circle:494.02 Circle:132.73 ][][Triangle:9.54 ][]
The max area:626.75

源码:
import java.util.*;

public class Main {
    //在Main类中定义一个静态Scanner对象,这样在其它类中如果想要使用该对象进行输入,则直接
    //使用Main.input.next…即可(避免采坑)
    public static Scanner input = new Scanner(System.in);

    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<Integer>();
        int num = input.nextInt();
        if (num == 0) {
            System.out.print("Wrong Format");
            System.exit(0);
        }
        while (num != 0) {
            if (num < 0 || num > 4) {
                System.out.println("Wrong Format");
                System.exit(0);
            }
            list.add(num);
            num = input.nextInt();
        }
        newDealCardList dealCardList = new newDealCardList(list);
        if (!dealCardList.validate()) {
            System.out.println("Wrong Format");
            System.exit(0);
        }
        dealCardList.showResult();
        input.close();
    }
}

abstract class Shape {
    private String shapeName;

    public Shape() {
    }

    public Shape(String shapeName) {
        this.shapeName = shapeName;
    }

    public String getShapeName() {
        return shapeName;
    }

    public void setShapeName(String shapeName) {
        this.shapeName = shapeName;
    }

    public double getArea() {
        return 0.0;
    }

    public boolean validate() {
        return true;
    }

    public String toString() {
        return shapeName + ":" + String.format("%.2f", getArea());
    }//输出格式
}

class Circle extends Shape {
    private double radius;

    public Circle() {
    }

    public Circle(double radius) {
        this.radius = radius;
    }

    public double getRadius() {
        return radius;
    }

    public void setRadius(double radius) {
        this.radius = radius;
    }

    public double getArea() {
        return Math.PI * radius * radius;
    }//计算圆面积
}

class Rectangle extends Shape {
    private double width;
    private double length;

    public Rectangle() {
    }

    public Rectangle(double width, double length) {
        this.width = width;
        this.length = length;
    }

    public double getWidth() {
        return width;
    }

    public void setWidth(double width) {
        this.width = width;
    }

    public double getLength() {
        return length;
    }

    public void setLength(double length) {
        this.length = length;
    }

    @Override
    public double getArea() {
        return getLength() * getWidth();
    }//计算矩形面积

    @Override
    public boolean validate() {
        return getWidth() > 0 && getLength() > 0;
    }//判断有效性
}

class Triangle extends Shape {
    private double side1;
    private double side2;
    private double side3;

    public Triangle() {
    }

    public Triangle(double side1, double side2, double side3) {
        this.side1 = side1;
        this.side2 = side2;
        this.side3 = side3;
    }

    @Override
    public double getArea() {
        double p = (side1 + side2 + side3) / 2;//求半周长
        return Math.sqrt(p * (p - side1) * (p - side2) * (p - side3));
    }//已知三角形三边,利用海伦公式计算面积

    @Override
    public boolean validate() {
        return side1 + side2 > side3 && side1 + side3 > side2 && side2 + side3 > side1;
    }//三角形有效性,任意两边之和大于第三边
}

class Trapezoid extends Shape {
    private double topSide;
    private double bottomSide;
    private double height;

    public Trapezoid() {
    }

    public Trapezoid(double topSide, double bottomSide, double height) {
        this.topSide = topSide;
        this.bottomSide = bottomSide;
        this.height = height;
    }

    @Override
    public double getArea() {
        return (topSide + bottomSide) * height / 2;
    }//梯形面积,上底加下底之和乘以高除以二

    @Override
    public boolean validate() {
        return topSide > 0 && bottomSide > 0 && height > 0;
    }//判断有效性
}

class Card implements Comparable<Card> {
    private Shape shape;

    public Card() {
    }

    public Card(Shape shape) {
        this.shape = shape;
    }

    public Shape getShape() {
        return shape;
    }

    public void setShape(Shape shape) {
        this.shape = shape;
    }

    @Override
    public int compareTo(Card card) {
        return Double.compare(card.getShape().getArea(), shape.getArea());
    }//比较面积
}

class DealCardList {
    protected ArrayList<Card> cardList = new ArrayList<Card>();

    public DealCardList() {
    }

    public DealCardList(ArrayList<Integer> list) {
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).equals(1)) {
                Card card1 = new Card(new Circle(Main.input.nextDouble()));
                cardList.add(card1);
                card1.getShape().setShapeName("Circle");
            } else if (list.get(i).equals(2)) {
                Card card2 = new Card(new Rectangle(Main.input.nextDouble(), Main.input.nextDouble()));
                cardList.add(card2);
                card2.getShape().setShapeName("Rectangle");
            } else if (list.get(i).equals(3)) {
                Card card3 = new Card(new Triangle(Main.input.nextDouble(), Main.input.nextDouble(), Main.input.nextDouble()));
                cardList.add(card3);
                card3.getShape().setShapeName("Triangle");
            } else if (list.get(i).equals(4)) {
                Card card4 = new Card(new Trapezoid(Main.input.nextDouble(), Main.input.nextDouble(), Main.input.nextDouble()));
                cardList.add(card4);
                card4.getShape().setShapeName("Trapezoid");
            }
        }//添加对象
    }

    public boolean validate() {
        boolean validate = true;
        for (Card card : cardList) {
            if (!card.getShape().validate()) {
                validate = false;
                break;
            }
        }
        return validate;
    }//当任意一个不满足有效性就停止循环,判断为无效

    public void cardSort() {
        Collections.sort(cardList);
    }//面积排序

    public double getAllArea() {
        double sum = 0;
        for (Card card : cardList) {
            sum += card.getShape().getArea();
        }
        return sum;
    }//计算面积之和

    public void showResult() {
        System.out.println("The original list:");
        for (Card card : cardList) {
            System.out.print(card.getShape().toString() + " ");
        }
        System.out.println();
        System.out.println("The sorted list:");
        cardSort();
        for (Card card : cardList) {
            System.out.print(card.getShape().toString() + " ");
        }
        System.out.println();
        System.out.println("Sum of area:" + String.format("%.2f", getAllArea()));
    }//输出
}

class newDealCardList extends DealCardList {
    private final double[] AllArea = {0.0, 0.0, 0.0, 0.0};

    public newDealCardList(ArrayList<Integer> list) {
        super(list);
    }

    public void circleCard() {
        System.out.print("[");
        for (Card card : cardList) {
            if (card.getShape().getShapeName().equals("Circle")) {
                System.out.print(card.getShape().toString() + " ");
            }
        }
        System.out.print("]");
    }//圆分组

    public void triangleCard() {
        System.out.print("[");
        for (Card card : cardList) {
            if (card.getShape().getShapeName().equals("Triangle")) {
                System.out.print(card.getShape().toString() + " ");
            }
        }
        System.out.print("]");
    }//三角形分组

    public void rectangleCard() {
        System.out.print("[");
        for (Card card : cardList) {
            if (card.getShape().getShapeName().equals("Rectangle")) {
                System.out.print(card.getShape().toString() + " ");
            }
        }
        System.out.print("]");
    }//矩形分组

    public void trapezoidCard() {
        System.out.print("[");
        for (Card card : cardList) {
            if (card.getShape().getShapeName().equals("Trapezoid")) {
                System.out.print(card.getShape().toString() + " ");
            }
        }
        System.out.print("]");
    }//梯形分组

    public void setAllArea() {
        for (Card card : cardList) {
            if (card.getShape().getShapeName().equals("Circle")) {
                AllArea[0] += card.getShape().getArea();
            } else if (card.getShape().getShapeName().equals("Triangle")) {
                AllArea[1] += card.getShape().getArea();
            } else if (card.getShape().getShapeName().equals("Rectangle")) {
                AllArea[2] += card.getShape().getArea();
            } else if (card.getShape().getShapeName().equals("Trapezoid")) {
                AllArea[3] += card.getShape().getArea();
            }
        }
    }//计算每组面积和

    public double maxArea() {
        setAllArea();
        double max = 0.0;
        for (int i = 0; i < 4; i++) {
            if (AllArea[i] > max) {
                max = AllArea[i];
            }
        }
        return max;
    }//找出面积最大值

    @Override
    public void showResult() {
        System.out.println("The original list:");
        System.out.print("[");
        for (Card card : cardList) {
            System.out.print(card.getShape().toString() + " ");
        }
        System.out.println("]");
        System.out.println("The Separated List:");
        circleCard();
        rectangleCard();
        triangleCard();
        trapezoidCard();
        System.out.println();
        System.out.println("The Separated sorted List:");
        cardSort();
        circleCard();
        rectangleCard();
        triangleCard();
        trapezoidCard();
        System.out.println();
        System.out.print("The max area:" + String.format("%.2f", maxArea()));
    }//输出格式
}
View Code

    类图

 sourcemonitor代码分析:

 

 代码的Avg Depth(平均深度)较高,代码的平均深度就是函数中分支嵌套的层数

 

 这两处用了较多的分支嵌套,上面的第一个方法是输入后创造对象,下面的方法是各自计算每个图形的总面积。

此题大体上不算复杂,类之间的关系比较明确。与上题相比,只是在每个类型的卡片的分类上会有些复杂。

  • 题目集九 7-1 统计Java程序中关键词的出现次数

    编写程序统计一个输入的Java源码中关键字(区分大小写)出现的次数。说明如下:

    • Java中共有53个关键字(自行百度)
    • 从键盘输入一段源码,统计这段源码中出现的关键字的数量
    • 注释中出现的关键字不用统计
    • 字符串中出现的关键字不用统计
    • 统计出的关键字及数量按照关键字升序进行排序输出
    • 未输入源码则认为输入非法

    输入格式:

    输入Java源码字符串,可以一行或多行,以exit行作为结束标志

    输出格式:

    • 当未输入源码时,程序输出Wrong Format
    • 当没有统计数据时,输出为空
    • 当有统计数据时,关键字按照升序排列,每行输出一个关键字及数量,格式为数量\t关键字

    输入样例:

    在这里给出一组输入。例如:

    //Test public method
    public HashMap(int initialCapacity) {
            this(initialCapacity, DEFAULT_LOAD_FACTOR);
        }
        public HashMap(int initialCapacity, float loadFactor) {
            if (initialCapacity < 0)
                throw new IllegalArgumentException("Illegal initial capacity: " +
                                                   initialCapacity);
            if (initialCapacity > MAXIMUM_CAPACITY)
                initialCapacity = MAXIMUM_CAPACITY;
            if (loadFactor <= 0 || Float.isNaN(loadFactor))
                throw new IllegalArgumentException("Illegal load factor: " +
                                                   loadFactor);
            this.loadFactor = loadFactor;
            this.threshold = tableSizeFor(initialCapacity);
        }
    exit

    输出样例:

    在这里给出相应的输出。例如:

    1	float
    3	if
    2	int
    2	new
    2	public
    3	this
    2	throw

源码:

import java.util.*;

public class Main {

    public static void main(String[] args) {
        boolean flag = false;
        String[] keywords = {"abstract", "assert", "boolean",
                "break", "byte", "case", "catch", "char", "class", "const",
                "continue", "default", "do", "double", "else", "enum",
                "extends", "for", "final", "finally", "float", "goto",
                "if", "implements", "import", "instanceof", "int",
                "interface", "long", "native", "new", "package", "private",
                "protected", "public", "return", "short", "static",
                "strictfp", "super", "switch", "synchronized", "this",
                "throw", "throws", "transient", "try", "void", "volatile",
                "while", "true", "false", "null"};
        Map<String, Integer> keywordMap = new HashMap<>();
        ArrayList<String> arrayList = new ArrayList<>();
        Scanner input = new Scanner(System.in);
        String code = input.next();
        while (!code.equals("exit")) {
            boolean flag2 = false;
            arrayList.add(code);
            if (code.matches("/\\*.*$") && !code.matches(".*?\\*/")) {
                flag2 = true;
            } else if (code.matches("/\\*.*$") && code.matches(".*?\\*/")) {
                code = "";
            }
            while (flag2) {
                code = input.nextLine();
                if (code.matches(".*?\\*/")) {
                    code = "";
                    break;
                }
            }
            if(!code.isEmpty()) {
                String[] s = removeComment(code).split(" ");
                for (String str : s) {
                    String str1 = str;
                    for (String str2 : keywords) {
                        if (str.equals(str2)) {
                            flag = true;
                            str1 = str;
                        }
                    }
                    if (flag) {
                        if (keywordMap.containsKey(str1)) {
                            keywordMap.put(str1, keywordMap.get(str1) + 1);
                        } else {
                            keywordMap.put(str1, 1);
                        }
                    }
                    flag = false;
                }
            }
            code = input.nextLine();
        }
        if (arrayList.isEmpty()) {
            System.out.print("Wrong Format");
        }
        boolean flag1 = false;//判断是否有统计数据时,没有输出为空
        Map<String, Integer> treeMap = new TreeMap<>(keywordMap);
        for (Map.Entry<String, Integer> entry : treeMap.entrySet()) {
            if (entry.getValue() != 0) {
                flag1 = true;
                System.out.println(entry.getValue() + "\t" + entry.getKey());
            }
        }
        if (!flag1) {
            System.exit(0);
        }
    }

    public static String removeComment(String str) {
        String s;
        s = str.replaceAll("(?<=//).*$", "");
        s = s.replaceAll("\".*?\"", "");
        s = s.replaceAll("[+\\-*/%&|^!~=><]+", "q");
        s = s.replaceAll("\\W", " ");
        s = s.trim();
        return s;
    }
}
View Code

因为没有设计多个类,代码的结构比较混乱。实现的功能就是寻找代码中的关键字并进行计数,但是要注意去掉字符以及注释中的关键字。

 

  • 题目集十 7-1 课程成绩统计程序-1

某高校课程从性质上分为:必修课、选修课,从考核方式上分为:考试、考察。

考试的总成绩由平时成绩、期末成绩分别乘以权重值得出,比如平时成绩权重0.3,期末成绩权重0.7,总成绩=平时成绩*0.3+期末成绩*0.7。

考察的总成绩直接等于期末成绩

必修课的考核方式必须为考试,选修课可以选择考试、考察任一考核方式。

1、输入:

包括课程、课程成绩两类信息。

课程信息包括:课程名称、课程性质、考核方式(可选,如果性质是必修课,考核方式可以没有)三个数据项。

课程信息格式:课程名称+英文空格+课程性质+英文空格+考核方式

课程性质输入项:必修、选修

考核方式输入选项:考试、考察

课程成绩信息包括:学号、姓名、课程名称、平时成绩(可选)、期末成绩

课程信息格式:学号+英文空格+姓名+英文空格+课程名称+英文空格+平时成绩+英文空格+期末成绩

以上信息的相关约束:

1)平时成绩和期末成绩的权重默认为0.3、0.7

2)成绩是整数,不包含小数部分,成绩的取值范围是【0,100】

3)学号由8位数字组成

4)姓名不超过10个字符

5)课程名称不超过10个字符

6)不特别输入班级信息,班级号是学号的前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)若出现重复的课程/成绩信息,只保留第一个课程信息,忽略后面输入的。

信息约束:

1)成绩平均分只取整数部分,小数部分丢弃

参考类图:


image.png

输入样例1:

仅有课程。例如:

java 必修 考试
数据结构 选修 考试
形式与政治 选修 考察
end
 

输出样例1:

在这里给出相应的输出。例如:

java has no grades yet
数据结构 has no grades yet
形式与政治 has no grades yet
 

输入样例2:

单门考试课程 单个学生。例如:

java 必修 考试
20201103 张三 java 20 40
end
 

输出样例2:

在这里给出相应的输出。例如:

20201103 张三 34
java 20 40 34
202011 34
 

输入样例3:

单门考察课程 单个学生。例如:

java 选修 考察
20201103 张三 java 40
end
 

输出样例3:

在这里给出相应的输出。例如:

20201103 张三 40
java 40 40
202011 40
 

输入样例4:

考试课程 单个学生 不匹配的考核方式。例如:

java 必修 考试
20201103 张三 java 20
end
 

输出样例4:

在这里给出相应的输出。例如:

20201103 张三 : access mode mismatch
20201103 张三 did not take any exams
java has no grades yet
202011 has no grades yet
 

输入样例5:

单门课程,单个学生,课程类型与考核类型不匹配。例如:

java 必修 考察
20201103 张三 java 40
end
 

输出样例5:

在这里给出相应的输出。例如:

java : course type & access mode mismatch
java does not exist
20201103 张三 did not take any exams
202011 has no grades yet
 

输入样例6:

单门课程,多个学生。例如:

java 选修 考察
20201103 李四 java 60
20201104 王五 java 60
20201101 张三 java 40
end
 

输出样例6:

在这里给出相应的输出。例如:

20201101 张三 40
20201103 李四 60
20201104 王五 60
java 53 53
202011 53
 

输入样例7:

单门课程,单个学生,课程类型与考核类型不匹配。例如:

形式与政治 必修 考试
数据库 选修 考试
java 选修 考察
数据结构 选修 考察
20201103 李四 数据结构 70
20201103 李四 形式与政治 80 90
20201103 李四 java 60
20201103 李四 数据库 70 78
end
 

输出样例7:

在这里给出相应的输出。例如:

20201103 李四 73
java 60 60
数据结构 70 70
数据库 70 78 75
形式与政治 80 90 87
202011 73
 

输入样例8:

单门课程,单个学生,成绩越界。例如:

数据结构 选修 考察
20201103 李四 数据结构 101
end
 

输出样例8:

在这里给出相应的输出。例如:

wrong format
数据结构 has no grades yet
 

输入样例9:

多门课程,多个学生,多个成绩。例如:

形式与政治 必修 考试
数据库 选修 考试
java 选修 考察
数据结构 选修 考察
20201205 李四 数据结构 70
20201103 李四 形式与政治 80 90
20201102 王五 java 60
20201211 张三 数据库 70 78
end
 

输出样例9:

在这里给出相应的输出。例如:

20201102 王五 60

20201103 李四 87
20201205 李四 70
20201211 张三 75
java 60 60
数据结构 70 70
数据库 70 78 75
形式与政治 80 90 87
202011 73
202012 72

这题设计较为复杂,学生有学号、姓名、成绩等属性,课程分为必修和选修,两种计算方式有所不同,在系列二中就是增加了一个实验,最终分数是取每次实验成绩的平均值。系列三则是改变了计算实验成绩的方式,给每次的实验分数赋予了权重,最终成绩按权重来进行计算。最终的输出是每位学生的成绩、各门课程的平均成绩还有班级的平均分,班级号是学生学号的前六位。

 

import java.util.*;
import java.text.*;

class Main {
    public static void main(String []args) {
        Scanner input = new Scanner(System.in);
        StudentAll studentAll = new StudentAll();
        allCourse allCourse = new allCourse();
        Scores cj = new Scores();
        String s = input.nextLine();
        String[] str = s.split(" ");
        //必修1,选修2/考试1,考察2
        while (!(str[0].equals("end"))) {
            if (isNumeric(str[0])) {
                if (str[0].length() != 8 || str[1].length() > 10)
                    System.out.println("wrong format");
                else if (str.length == 4 && !isNumeric(str[3]))
                    System.out.println("wrong format");
                else if (str.length == 5 && !isNumeric(str[3]) && !isNumeric(str[3]))
                    System.out.println("wrong format");
                else if (str.length == 4 && (Integer.parseInt(str[3]) < 0 || Integer.parseInt(str[3]) > 100))
                    System.out.println("wrong format");
                else if (str.length == 5 && (Integer.parseInt(str[3]) < 0 || Integer.parseInt(str[3]) > 100) && (Integer.parseInt(str[4]) < 0 || Integer.parseInt(str[4]) > 100))
                    System.out.println("wrong format");
                else {
                    studentAll.addStudent(str[0], str[1]);
                    course course = allCourse.findCourse(str[2]);
                    if (course == null)
                        System.out.println(str[2] + " " + "does not exist");
                    else {
                        if ((course.form == 1 && (str.length != 5)) || (course.form == 2 && (str.length != 4)))
                            System.out.println(str[0] + " " + str[1] + " : access mode mismatch");
                        else {
                            int q = cj.findScore(str[0], str[1], str[2]);
                            if (q == 0) {
                                if (course.form == 1) {
                                    cj.compulsory(str[0], str[1], course, Integer.parseInt(str[3]), Integer.parseInt(str[4]));
                                    studentAll.ifHasScore();
                                } else if (course.form == 2) {
                                    cj.elective(str[0], str[1], course, Integer.parseInt(str[3]));
                                    studentAll.ifHasScore();
                                }
                            }
                        }
                    }
                }
            } else {
                if (str.length == 2 || str.length == 3) {
                    if (str[0].length() > 10)
                        System.out.println("wrong format");
                    else {
                        if (str.length == 3) {
                            if (str[1].equals("必修") && str[2].equals("考察"))
                                System.out.println(str[0] + " : course type & access mode mismatch");
                            else if ((str[1].equals("必修") && str[2].equals("考试")) || (str[1].equals("选修") && (str[2].equals("考试") || (str[2].equals("考察"))))) {
                                course ke = allCourse.findCourse(str[0]);
                                if (ke == null) {
                                    allCourse.addCourse(str[0], str[1], str[2]);
                                }
                            } else
                                System.out.println("wrong format");
                        } else if (str.length == 2) {
                            if (str[1].equals("选修"))
                                System.out.println("wrong format");
                            else if (str[1].equals("必修")) {
                                course ke = allCourse.findCourse(str[0]);
                                if (ke == null) {
                                    allCourse.addCourse(str[0], str[1], "考试");
                                }
                            } else
                                System.out.println("wrong format");
                        }
                    }
                } else
                    System.out.println("wrong format");
            }
            s = input.nextLine();
            str = s.split(" ");
        }
        studentAll.studentSort(cj);
        allCourse.sort(cj);
        studentAll.classScoreSelection();
    }

    public static boolean isNumeric(String str) {
        for (int i = str.length(); --i >= 0; ) {
            if (!Character.isDigit(str.charAt(i))) {
                return false;
            }
        }
        return true;
    }
}

class Student {
    protected String num;
    protected String name;
    protected int flag = 0;
    protected int score;

    public Student() {

    }

    public Student(String num, String name) {
        this.num = num;
        this.name = name;
    }
}

class StudentAll {
    protected Student[] stu = new Student[20];
    protected int sum = 0;

    public void addStudent(String num, String name) {
        int i;
        if (sum == 0) {
            stu[0] = new Student(num, name);
            sum++;
        } else {
            for (i = 0; i < sum; i++) {
                if (num.equals(stu[i].num) && name.equals(stu[i].name))
                    break;
            }
            if (i == sum)
                stu[sum++] = new Student(num, name);
        }
    }

    public void ifHasScore() {
        stu[sum - 1].flag = 1;
    }

    public void studentSort(Scores cj) {
        for (int i = 0; i < sum - 1; i++) {
            for (int j = i + 1; j < sum; j++) {
                if ((stu[i].num).compareTo(stu[j].num) > 0) {
                    Student t = stu[i];
                    stu[i] = stu[j];
                    stu[j] = t;
                }
            }
        }
        cj.studentScores(stu, sum);
    }

    public void classScoreSelection() {
        ClassSelection classSelection = new ClassSelection();
        classSelection.selection(stu, sum);
        classSelection.classScore();
    }
}

class Class {
    protected String classNumber;
    protected Student[] stu;
    protected int num;

    public Class(String classNumber, Student[] stu, int a) {
        this.classNumber = classNumber;
        this.stu = stu;
        this.num = a;
    }
    public int isClassScore(Class classes) {
        for(int i=0;i<classes.num;i++)
        {
            if(classes.stu[i].flag!=0)
                return 1;
        }
        return 0;
    }
    public int classesScore(Class classes) {
        int m = 0;
        for(int i = 0; i < classes.num; i++)
        {
            if(classes.stu[i].score != 0)
            {
                m = m + classes.stu[i].score;
            }
        }
        return m / classes.num;
    }
}

class ClassSelection {
    Class[] classes = new Class[20];
    String[] strings = new String[20];
    Student[][] students = new Student[20][20];
    int[] num = new int[20];
    int c = 0;

    public void selection(Student[] stu, int a) {
        for (int i = 0; i < a; i++) {
            int j;
            String str = stu[i].num.substring(0, 6);
            if (c == 0) {
                strings[c] = str;
                students[c][num[c]] = stu[i];
                num[c] = num[c] + 1;
                c++;
            } else {
                for (j = 0; j < c; j++) {
                    if (str.equals(strings[j])) {
                        students[j][num[j]] = stu[i];
                        num[j] = num[j] + 1;
                        break;
                    }
                }
                if (j == c) {
                    strings[c] = str;
                    students[c][num[c]] = stu[i];
                    num[c] = num[c] + 1;
                    c++;
                }
            }
        }
        for (int i = 0; i < c; i++) {
            classes[i] = new Class(strings[i], students[i], num[i]);
        }
    }

    public void classScore() {
        for(int i = 0; i < c; i++)
        {
            if(classes[i].isClassScore(classes[i]) == 0)
                System.out.println(classes[i].classNumber + " " + "has no grades yet");
            else
            {
                System.out.println(classes[i].classNumber + " " + classes[i].classesScore(classes[i]));
            }
        }
    }
}

class course {
    protected String courseName;
    protected int form;
    protected int examForm;
    protected int flag = 0;

    public course() {

    }

    public course(String name, int form, int examForm) {
        this.courseName = name;
        this.form = form;
        this.examForm = examForm;
    }
}

class allCourse {
    protected course[] courses = new course[20];
    protected int num = 0;

    public void addCourse(String name, String form, String examForm) {
        int x = 0;
        int f = 0;
        if (form.equals("必修")) {
            x = 1;
        } else if (form.equals("选修")) {
            x = 2;
        }
        if (examForm.equals("考试")) {
            f = 1;
        } else if (examForm.equals("考察")) {
            f = 2;
        }
        courses[num] = new course(name, x, f);
        num++;
    }

    public course findCourse(String name) {
        for (int i = 0; i < num; i++) {
            if (name.equals(courses[i].courseName))
                return courses[i];
        }
        return null;
    }

    public void sort(Scores cj) {
        Collator collator = Collator.getInstance(Locale.CHINA);
        for (int i = 0; i < num - 1; i++) {
            for (int j = i + 1; j < num; j++) {
                if (collator.compare(courses[i].courseName, courses[j].courseName) > 0) {
                    course t = courses[i];
                    courses[i] = courses[j];
                    courses[j] = t;
                }
            }
        }
        cj.score(courses, num);
    }
}

class Select {
    protected Student stu;
    protected course course;
    protected int scores;
    protected int daily;
    protected int exam;

    public Select(Student stu, course course, int daily, int exam, int scores) {
        this.stu = stu;
        this.course = course;
        this.daily = daily;
        this.exam = exam;
        this.scores = scores;
    }

    public void courseScore(int flag) {
        course.flag = flag;
    }

    public void studentScore(int flag) {
        stu.flag = flag;
    }
}

class Scores {
    protected Select[] selects = new Select[20];
    protected int num = 0;

    public void compulsory(String sum, String name, course kec, int x, int y) {
        double z = x * 0.3 + y * 0.7;
        int t = (int) (z);
        Student stu = new Student(sum, name);
        selects[num] = new Select(stu, kec, x, y, t);
        selects[num].courseScore(1);
        selects[num].studentScore(1);
        num++;
    }

    public void elective(String sum, String name, course kec, int x) {
        Student stu = new Student(sum, name);
        selects[num] = new Select(stu, kec, 0, x, x);
        selects[num].courseScore(1);
        selects[num].studentScore(1);
        num++;
    }

    public void studentScores(Student[] stu, int a) {
        int[] scj = new int[20];
        int[] c = new int[20];
        for (int i = 0; i < a; i++) {
            for (int j = 0; j < num; j++) {
                if ((stu[i].num.equals(selects[j].stu.num)) && (stu[i].name.equals(selects[j].stu.name))) {
                    scj[i] = scj[i] + selects[j].scores;
                    c[i]++;
                }
            }
        }
        for (int i = 0; i < a; i++) {
            int t = scj[i] / c[i];
            stu[i].score = t;
            if (stu[i].flag == 0)
                System.out.println(stu[i].num + " " + stu[i].name + " did not take any exams");
            else {
                System.out.println(stu[i].num + " " + stu[i].name + " " + t);
            }
        }
    }

    public void score(course[] courses, int a) {
        int[] dailyScore = new int[a];
        int[] examScore = new int[a];
        int[] kcj = new int[a];
        int[] c = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
        for (int i = 0; i < a; i++) {
            for (int j = 0; j < num; j++) {
                if (courses[i].courseName.equals(selects[j].course.courseName)) {
                    if (courses[i].form == 1)
                        dailyScore[i] = dailyScore[i] + selects[j].daily;
                    examScore[i] = examScore[i] + selects[j].exam;
                    kcj[i] = kcj[i] + selects[j].scores;
                    c[i]++;
                }
            }
        }
        for (int i = 0; i < a; i++) {
            if (courses[i].flag == 0)
                System.out.println(courses[i].courseName + " has no grades yet");
            else if (courses[i].flag == 1) {
                if (courses[i].form == 1)
                    System.out.println(courses[i].courseName + " " + (int) (dailyScore[i] / (1.0 * c[i])) + " " + (examScore[i] / (c[i])) + " " + (kcj[i] / (c[i])));
                else if (courses[i].form == 2)
                    System.out.println(courses[i].courseName + " " + (int) (examScore[i] / (c[i] * 1.0)) + " " + (kcj[i] / (c[i])));

            }
        }
    }

    public int findScore(String str1, String str2, String str3) {
        for (int i = 0; i < num; i++) {
            if (str1.equals(selects[i].stu.num) && str2.equals(selects[i].stu.name) && str3.equals(selects[i].course.courseName))
                return 1;
        }
        return 0;
    }
}
View Code

 

 

 

三、踩坑心得

 

四、改进建议

  部分代码未能实现单一职责原则、迪米特法则、开闭原则,结构较为混乱,运用了多个循环和if条件语句,使得代码的复杂度大大提升,代码的可读性也因此降低。例如:在统计Java程序中关键词的出现次数题目中未能完全做到模块化设计。同时,代码扩展性较低,整体来说代码的提升空间很大。

五、总结

  本学期的面向对象课程已经结束,在这10-16周主要是针对于设计理念和原则以及一些集合容器的学习和使用,强化面向对象封装、继承、多态这三大特性。但是在之后的学习当中,还是要深化设计理念,尽量做到符合设计原则。本课程的线上与线下相结合的教学模式、边讲边练的教学方式以及课程过程中采取的翻转课堂较好。同时也与生活中的实例相结合,例如雨刷系统以及后续的JavaFx动画实现,让学生更好地巩固所学知识,并将理论应用于实际项目中。但对于在PTA或者实验中遇到的问题反馈较少,可以适当提供一些思路或者细节上的提示,能在代码质量、设计思路等方面的提升,而不是面向过程、结果编程。在时间允许的情况下,可以给学生提供更多类似翻转课堂、小组合作的课程内容,引导学生并提高其自学能力和集体感,使学生更多的参与到课堂当中。