第三次大作业总结

 

一、前言:总结三次题目集的知识点、题量、难度等情况

  这次三次作业题量少,但是确实综合性考察难度有所提升,本次大作业的知识点主要是:掌握类的继承、多态性使用方法以及接口的应用。

二、设计与分析:重点对题目的提交源码进行分析,可参考SourceMonitor的生成报表内容以及PowerDesigner的相应类图,要有相应的解释和心得(做到有图有真相),本次Blog必须分析的内容如下:

    ①题目集7分析

(7-1)

 

 

Metrics Details For File 'Main.java'
--------------------------------------------------------------------------------------------

Parameter Value
========= =====
Project Directory E:\IntelliJ_IDEA\Progect_java\src\A\
Project Name cardSort
Checkpoint Name Baseline
File Name Main.java
Lines 234
Statements 173
Percent Branch Statements 16.8
Method Call Statements 49
Percent Lines with Comments 0.4
Classes and Interfaces 8
Methods per Class 3.88
Average Statements per Method 3.97
Line Number of Most Complex Method 54
Name of Most Complex Method DealCardList.DealCardList()
Maximum Complexity 8
Line Number of Deepest Block 17
Maximum Block Depth 4
Average Block Depth 2.12
Average Complexity 2.13

--------------------------------------------------------------------------------------------
Most Complex Methods in 8 Class(es): Complexity, Statements, Max Depth, Calls

Card.Card() 1, 1, 2, 0
Card.Card() 1, 0, 0, 0
Card.getShape() 1, 1, 2, 0
Card.setShape() 1, 1, 2, 0
Circle.Circle() 1, 1, 2, 0
Circle.Circle() 1, 0, 0, 0
Circle.getArea() 1, 1, 2, 0
Circle.vaildate() 3, 4, 2, 0
DealCardList.cardSort() 4, 4, 4, 9
DealCardList.DealCardList() 8, 38, 4, 13
DealCardList.DealCardList() 1, 0, 0, 0
DealCardList.getAllArea() 2, 4, 3, 0
DealCardList.showResult() 4, 14, 3, 13
DealCardList.validate() 3, 4, 3, 2
Main.main() 7, 20, 4, 11
Rectangle.getArea() 1, 1, 2, 0
Rectangle.Rectangle 1, 2, 2, 0
Rectangle.vaildate() 4, 4, 2, 0
Shape.getArea() 1, 1, 2, 0
Shape.getShapeName() 1, 1, 2, 0
Shape.setShapeName() 1, 1, 2, 0
Shape.Shape() 1, 1, 2, 0
Shape.Shape() 1, 0, 0, 0
Shape.vaildate() 1, 1, 2, 0
Traperoid.getArea() 1, 1, 2, 0
Traperoid.Traperoid() 1, 3, 2, 0
Traperoid.Traperoid() 1, 0, 0, 0
Traperoid.validate() 5, 4, 2, 0
Triangle.getArea() 1, 3, 2, 0
Triangle.Triangle() 1, 3, 2, 0
Triangle.vaildate() 5, 4, 2, 0

--------------------------------------------------------------------------------------------
Block Depth Statements

0 12
1 38
2 71
3 22
4 30
5 0
6 0
7 0
8 0
9+ 0
--------------------------------------------------------------------------------------------

 

 

package A;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Main {
//在Main类中定义一个静态Scanner对象,这样在其它类中如果想要使用该对象进行输入,则直接
//使用Main.input.next…即可(避免采坑)
public static Scanner input = new Scanner(System.in);
public static void main(String[] args){
int l =0,q=1;
for (;q<15;){
q++;
}
ArrayList<Integer> list = new ArrayList<Integer>();
int num = input.nextInt();
while(num != 0){
if(num < 0 || num > 4){
System.out.println("Wrong Format");
System.exit(0);
}
list.add(num);
num = input.nextInt();
}
int l1 =0,q1=1;
for (;q1<15;){
q1++;
}
DealCardList dealCardList = new DealCardList(list);
if(!dealCardList.validate()){
System.out.println("Wrong Format");
System.exit(0);
}
dealCardList.showResult();
input.close();
}
}
class Card{
Shape shape;
Card(){
}
Card(Shape shape){
this.shape=shape;
}
public Shape getShape() {
return shape;
}
public void setShape(Shape Shape) {
this.shape=shape;
}
}
class DealCardList{
ArrayList<Card> cardList=new ArrayList<Card>();
DealCardList(){
}
DealCardList(ArrayList<Integer> list){
int l1 =0,q2=1;
for (;q2<15;){
q2++;
l1++;
}
for(int i=0;i<list.size();i++)
{
l1+=2;
if(list.get(i)==1)
{
double r=Main.input.nextDouble();
Circle circle=new Circle(r);
Card card=new Card(circle);
card.getShape().setShapeName("Circle");
cardList.add(card);
}
if(list.get(i)==2) {
double a=Main.input.nextDouble();
double b=Main.input.nextDouble();
Rectangle rectangle=new Rectangle(a,b);
Card card=new Card(rectangle);
card.getShape().setShapeName("Rectangle");
cardList.add(card);
}
int d = 1;
for(int l=0;l<3;l++){
d= d+3;
}
if(list.get(i)==3) {
double a=Main.input.nextDouble();
double b=Main.input.nextDouble();
double c=Main.input.nextDouble();
Triangle triangle=new Triangle(a,b,c);
Card card=new Card(triangle);
card.getShape().setShapeName("Triangle");
cardList.add(card);
}
if(list.get(i)==4) {
double a=Main.input.nextDouble();
double b=Main.input.nextDouble();
double c=Main.input.nextDouble();
Traperoid traperoid=new Traperoid(a,b,c);
Card card=new Card(traperoid);
card.getShape().setShapeName("Trapezoid");
cardList.add(card);
}
}
}
public boolean validate() {
for (Card card: cardList){
if (!card.getShape().vaildate())
return false;
}
return true;
}
public void cardSort() {
for(int k=0;k<cardList.size();k++)
for(int i=k+1;i<cardList.size();i++)
{
if(cardList.get(k).getShape().getArea()<cardList.get(i).getShape().getArea())
Collections.swap(cardList, k, i);
}
}
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:");
int l3 =0,p=1;
for (;p<15;){
p++;
l3--;
}
for(int i=0;i<cardList.size();i++)
System.out.print(cardList.get(i).getShape().getShapeName()+":"+String.format("%.2f",cardList.get(i).getShape().getArea())+" ");
System.out.println();
System.out.println("The sorted list:");
cardSort();
for(int i=0;i<cardList.size();i++)
System.out.print(cardList.get(i).getShape().getShapeName()+":"+String.format("%.2f",cardList.get(i).getShape().getArea())+" ");
System.out.println();
System.out.println("Sum of area:"+String.format("%.2f",getAllArea()));
}
}
class Shape {
private String shapeName;
Shape(){
}
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 vaildate() {
return true;
}
}
class Circle extends Shape{
private double radius;
Circle(){
}
Circle(double radius){
this.radius=radius;
}
public double getArea() {
return Math.PI*radius*radius;
}
public boolean vaildate() {
if(radius>0)
return true;
else return false;
}
}
class Rectangle extends Shape{
private double width,length;
Rectangle (double width,double length){
this.width=width;
this.length=length;
}
public double getArea() {
return width*length;
}
public boolean vaildate() {
if(width>0&&length>0)
return true;
else return false;
}
}
class Triangle extends Shape{
double side1,side2,side3;
Triangle(double side1,double side2,double side3){
this.side1=side1;
this.side2=side2;
this.side3=side3;
}
public double getArea() {
double c=(side1+side2+side3)/2;
double s=Math.sqrt(c*(c-side1)*(c-side2)*(c-side3));
return s;
}
public boolean vaildate() {
if(side1+side2>side3&&side1+side3>side2&&side2+side3>side1)
return true;
else
return false;
}
}
class Traperoid extends Shape{
private double topSide,bottomSide,height;
Traperoid(){
}
Traperoid(double topSide,double bottomSide,double height){
this.bottomSide=bottomSide;
this.height=height;
this.topSide=topSide;
}
public double getArea() {
return (topSide+bottomSide)*height/2;
}
public boolean validate() {
if(topSide>0&&bottomSide>0&&height>0)
return true;
else return false;
}
}

(7-2)两道题目的递进式设计分析总结

  

 

 

Metrics Details For File 'Main.java'
--------------------------------------------------------------------------------------------

Parameter Value
========= =====
Project Directory E:\IntelliJ_IDEA\Progect_java\src\A\
Project Name cardSort
Checkpoint Name Baseline
File Name Main.java
Lines 234
Statements 173
Percent Branch Statements 16.8
Method Call Statements 49
Percent Lines with Comments 0.4
Classes and Interfaces 8
Methods per Class 3.88
Average Statements per Method 3.97
Line Number of Most Complex Method 54
Name of Most Complex Method DealCardList.DealCardList()
Maximum Complexity 8
Line Number of Deepest Block 17
Maximum Block Depth 4
Average Block Depth 2.12
Average Complexity 2.13

--------------------------------------------------------------------------------------------
Most Complex Methods in 8 Class(es): Complexity, Statements, Max Depth, Calls

Card.Card() 1, 1, 2, 0
Card.Card() 1, 0, 0, 0
Card.getShape() 1, 1, 2, 0
Card.setShape() 1, 1, 2, 0
Circle.Circle() 1, 1, 2, 0
Circle.Circle() 1, 0, 0, 0
Circle.getArea() 1, 1, 2, 0
Circle.vaildate() 3, 4, 2, 0
DealCardList.cardSort() 4, 4, 4, 9
DealCardList.DealCardList() 8, 38, 4, 13
DealCardList.DealCardList() 1, 0, 0, 0
DealCardList.getAllArea() 2, 4, 3, 0
DealCardList.showResult() 4, 14, 3, 13
DealCardList.validate() 3, 4, 3, 2
Main.main() 7, 20, 4, 11
Rectangle.getArea() 1, 1, 2, 0
Rectangle.Rectangle 1, 2, 2, 0
Rectangle.vaildate() 4, 4, 2, 0
Shape.getArea() 1, 1, 2, 0
Shape.getShapeName() 1, 1, 2, 0
Shape.setShapeName() 1, 1, 2, 0
Shape.Shape() 1, 1, 2, 0
Shape.Shape() 1, 0, 0, 0
Shape.vaildate() 1, 1, 2, 0
Traperoid.getArea() 1, 1, 2, 0
Traperoid.Traperoid() 1, 3, 2, 0
Traperoid.Traperoid() 1, 0, 0, 0
Traperoid.validate() 5, 4, 2, 0
Triangle.getArea() 1, 3, 2, 0
Triangle.Triangle() 1, 3, 2, 0
Triangle.vaildate() 5, 4, 2, 0

--------------------------------------------------------------------------------------------
Block Depth Statements

0 12
1 38
2 71
3 22
4 30
5 0
6 0
7 0
8 0
9+ 0
--------------------------------------------------------------------------------------------

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){
int l =0,q=1;
for (;q<15;){
q++;
}
ArrayList<Integer> list = new ArrayList<Integer>();
int num = input.nextInt();
while(num != 0){
if(num < 0 || num > 4){
System.out.println("Wrong Format");
System.exit(0);
}
list.add(num);
num = input.nextInt();
}
int l1 =0,q1=1;
for (;q1<15;){
q1++;
}
DealCardList dealCardList = new DealCardList(list);
if(!dealCardList.validate()){
System.out.println("Wrong Format");
System.exit(0);
}
dealCardList.showResult();
input.close();
}
}
class Card implements Comparable<Card>{
Shape shape;
Card(){
}
Card(Shape shape){
this.shape=shape;
}
public Shape getShape() {
return shape;
}
public void setShape(Shape Shape) {
this.shape=shape;
}

@Override
public int compareTo(Card o) {
if (this.shape.getArea()> o.shape.getArea()){
return -1;
}else if (this.shape.getArea() < o.shape.getArea()){
return 1;
}else
return 0;
}
}
class DealCardList{
double[] areaMax=new double[4];
ArrayList<Card> cardList=new ArrayList<Card>();
DealCardList(){
}
DealCardList(ArrayList<Integer> list){
int l1 =0,q2=1;
for (;q2<15;){
q2++;
l1++;
}
for(int i=0;i<list.size();i++)
{
l1+=2;
if(list.get(i)==1)
{
double r=Main.input.nextDouble();
Circle circle=new Circle(r);
Card card1=new Card(circle);
card1.getShape().setShapeName("Circle");
cardList.add(card1);
}
if(list.get(i)==2) {
double a=Main.input.nextDouble();
double b=Main.input.nextDouble();
Rectangle rectangle=new Rectangle(a,b);
Card card=new Card(rectangle);
card.getShape().setShapeName("Rectangle");
cardList.add(card);
}
int d = 1;
for(int l=0;l<3;l++){
d= d+3;
}
if(list.get(i)==3) {
double a=Main.input.nextDouble();
double b=Main.input.nextDouble();
double c=Main.input.nextDouble();
Triangle triangle=new Triangle(a,b,c);
Card card=new Card(triangle);
card.getShape().setShapeName("Triangle");
cardList.add(card);
}
if(list.get(i)==4) {
double a=Main.input.nextDouble();
double b=Main.input.nextDouble();
double c=Main.input.nextDouble();
Traperoid traperoid=new Traperoid(a,b,c);
Card card=new Card(traperoid);
card.getShape().setShapeName("Trapezoid");
cardList.add(card);
}
}
}
public boolean validate() {
for (Card card: cardList){
if (card.getShape().vaildate())
return true;
}
return false;
}
public void showCircleARea(){
areaMax[0] = 0;
for (Card card : cardList){
if (card.getShape().getShapeName().equals("Circle")){
System.out.printf(card.getShape().getShapeName()+":%.2f ",card.getShape().getArea());
areaMax[0] += card.getShape().getArea();
}
}
}
public void showRectangleArea(){
areaMax[1] = 0;
for (Card card : cardList){
if (card.getShape().getShapeName().equals("Rectangle")){
System.out.printf(card.getShape().getShapeName()+":%.2f ",card.getShape().getArea());
areaMax[1] += card.getShape().getArea();
}
}
}
public void showTriangleArea(){
areaMax[2] = 0;
for (Card card : cardList){
if (card.getShape().getShapeName().equals("Triangle")){
System.out.printf(card.getShape().getShapeName()+":%.2f ",card.getShape().getArea());
areaMax[2] += card.getShape().getArea();
}
}
}
public void showTraperoidArea() {
areaMax[3] = 0;
for (Card card : cardList) {
if (card.getShape().getShapeName().equals("Trapezoid")) {
System.out.printf(card.getShape().getShapeName()+":%.2f ",card.getShape().getArea());
areaMax[3] += card.getShape().getArea();
}
}
}
//从大到小输出圆的数据
public void CircleSort(){
TreeSet<Card> kp = new TreeSet<>(cardList);
System.out.print("[");
for (Card a:kp){
if(a.getShape().getShapeName().equals("Circle")){
System.out.printf(a.getShape().getShapeName()+":%.2f ",a.getShape().getArea());
}
}
System.out.print("]");
}
//从大到小输出矩形的数据
public void RectangleSort(){
TreeSet<Card> kp = new TreeSet<>(cardList);
System.out.print("[");
for (Card a:kp){
if(a.getShape().getShapeName().equals("Rectangle")){
System.out.printf(a.getShape().getShapeName()+":%.2f ",a.getShape().getArea());
}
}
System.out.print("]");
}
//从大到小输出三角形的数据
public void Trianglesort(){
TreeSet<Card> kp = new TreeSet<>(cardList);
System.out.print("[");
for (Card a:kp){
if(a.getShape().getShapeName().equals("Triangle")){
System.out.printf(a.getShape().getShapeName()+":%.2f ",a.getShape().getArea());
}
}
System.out.print("]");
}
//从大到小输出梯形的数据
public void TraperoidSort(){
TreeSet<Card> kp = new TreeSet<>(cardList);
System.out.print("[");
for (Card a:kp){
if(a.getShape().getShapeName().equals("Trapezoid")){
System.out.printf(a.getShape().getShapeName()+":%.2f ",a.getShape().getArea());
}
}
System.out.println("]");
}

 

public void showResult() {
System.out.println("The original list:");
int l3 =0,p=1;
for (;p<15;){
p++;
l3--;
}
System.out.print("[");
for(int i=0;i<cardList.size();i++)
System.out.print(cardList.get(i).getShape().getShapeName()+":"+String.format("%.2f",cardList.get(i).getShape().getArea())+" ");
System.out.println("]");
System.out.println("The Separated List:");
System.out.print("[");showCircleARea();System.out.print("]");
System.out.print("[");showRectangleArea();System.out.print("]");
System.out.print("[");showTriangleArea();System.out.print("]");
System.out.print("[");showTraperoidArea();System.out.print("]");
System.out.println();
System.out.println("The Separated sorted List:");
CircleSort();RectangleSort();Trianglesort();TraperoidSort();
Arrays.sort(areaMax);
System.out.println("The max area:"+String.format("%.2f",areaMax[3]));
}
}
class Shape {
private String shapeName;
Shape(){
}
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 vaildate() {
return true;
}
}
class Circle extends Shape{
private double radius;
Circle(){
}
Circle(double radius){
this.radius=radius;
}
public double getArea() {
return Math.PI*radius*radius;
}
public boolean vaildate() {
if(radius>0)
return true;
else return false;
}
}
class Rectangle extends Shape{
private double width,length;
Rectangle (double width,double length){
this.width=width;
this.length=length;
}
public double getArea() {
return width*length;
}
public boolean vaildate() {
if(width>0&&length>0)
return true;
else return false;
}
}
class Triangle extends Shape{
double side1,side2,side3;
Triangle(double side1,double side2,double side3){
this.side1=side1;
this.side2=side2;
this.side3=side3;
}
public double getArea() {
double c=(side1+side2+side3)/2;
double s=Math.sqrt(c*(c-side1)*(c-side2)*(c-side3));
return s;
}
public boolean vaildate() {
if(side1+side2>side3&&side1+side3>side2&&side2+side3>side1)
return true;
else
return false;
}
}
class Traperoid extends Shape{
private double topSide,bottomSide,height;
Traperoid(){
}
Traperoid(double topSide,double bottomSide,double height){
this.bottomSide=bottomSide;
this.height=height;
this.topSide=topSide;
}
public double getArea() {
return (topSide+bottomSide)*height/2;
}
public boolean validate() {
if(topSide>0&&bottomSide>0&&height>0)
return true;
else return false;
}
}

②题目集8和题目集9两道ATM机仿真题目的设计思路分析总结

 

 

 

 

三、采坑心得:对源码的提交过程中出现的问题及心得进行总结,务必做到详实,拿数据、源码及测试结果说话,切忌假大空

关于圆形继承题目较为简单,主要考察的是类的继承以及类的复用等。第三阶段的作业主要是对编程思想以及简单的数据结构的考察,考察了开闭原则

开闭原则(OCP)是面向对象设计中“可复用设计”的基石,是面向对象设计中最重要的原则之一,其它很多的设计原则都是实现开闭原则的一种手段。

开闭原则的定义: 一个软件实体如类,模块和函数应该对扩展开放,对修改关闭。

遵循开闭原则设计出的模块具有两个主要特征:

(1)对于扩展是开放的(Open for extension)。这意味着模块的行为是可以扩展的。当应用的需求改变时,我们可以对模块进行扩展,使其具有满足那些改变的新行为。也就是说,我们可以改变模块的功能。

(2)对于修改是关闭的(Closed for modification)。对模块行为进行扩展时,不必改动模块的源代码,能够很好的保证之前的测试,不会应为改动代码而出现新的bug.

开闭原则的定义已经明确地告诉我们,软件实体应该对扩展开放,对修改关闭,其信念是说一个软件实体应该通过扩展来实现变化,而不是通过修改已有的代码来实

四、改进建议:对相应题目的编码改进给出自己的见解,做到可持续改进

面向对象不需要太多的技巧性,而面向过程则需要较强的技巧性,面向对象能实现代码很好的复用性,当是在某些场合下又会下显得较为啰嗦,面向对象的三大支柱,继承,封装,范式,是其实现面向对象的基石,所以我们在学习中要深刻的理解,才能为自己今后的编程带来一定的益处。

五、总结:对本阶段三次题目集的综合性总结,学到了什么,哪些地方需要进一步学习及研究,对教师、课程、作业、实验、课上及课下组织方式等方面的改进建议及意见。

这三次的Java大作业的知识点我认为主要还是主要在各种数据的处理方面。第一次大作业主要为基本数据的运算和数字大小的排序,还有字符串的处理这三大处理;第二次的大作业是字符串的处理和日期的处理这两个方面,而这次的三四五题思想基本一样,最主要考察的还是对不同月份的思考,需要考虑不同的方面,对基本的逻辑能力有一定的考察;第三次的大作业就不再是前两次的简单的数据处理了,考察了我们对面向对象的思考了,不再只是写在一个主类了,不只是考察我们的基本写一些代码的问题了,更多的是考察我们对面向对象这一实质的思考,利用数据的私有和不同类之间的关联了。

说实话这三次题量并不是那么多,毕竟每次的大作业给了我们一个星期的时间,在平时利用空余时间也可随时敲敲code。前两次的大作业都还好,都能够将所有的测试点给通过,而不是一堆的让人崩溃的绿色(PTA测试点不通过的情况),并且可以提前完成。但是到了最后的一次的大作业,明显难度就上升了好多,说实话十天的时间是够的,但是不知道我为什么就是没有写出来最后一题(可能自己的思维逻辑不够严谨强大吧,也可能就是自己比较懒,嘿嘿,以后一定更加努力)一元多项式求导(类设计)。

在接下来的学习,我认为最主要的是如何正确的理解这一语言的思考方式,只要路是对的,就不怕路远。

posted @ 2021-12-18 13:07  物联网小新  阅读(67)  评论(0)    收藏  举报