第二次blog
前言
数学的问题很大,使得PTA的大作业写的并不是很舒服
小总结
把代码比作盖楼的话:
期中考试的题比较舒服,把三道题放一起就知道这是要盖大楼,题之间是循序渐进的,所以每道题还要兼顾可拓展性,于是越写越顺。
而大作业就很难受了,最开始并不知道这是要盖大楼,于是用小平房的代码水了过去,可是楼总是要盖的,于是每次都得拆掉小平房,重新打地基,重新盖房子。
设计与分析
题目集8-9
第一题
代码
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); double x1 = in.nextDouble(), y1 = in.nextDouble(), x2 = in.nextDouble(), y2 = in.nextDouble(); String colour = in.next(); Point p1 = new Point(x1, y1), p2 = new Point(x2, y2); Line l1 = new Line(p1, p2, colour); l1.display(); } } class Point { private double x, y; public Point(double x, double y) { this.x = x; this.y = y; } public void display() { Point p = new Point(x, y); InputWrong.OutNumLimit(p); String s = String.format("(%.2f,%.2f)", x, y); System.out.println(s); } public double getX() { return x; } public double getY() { return y; } public void setX(double x) { this.x = x; } public void setY(double y) { this.y = y; } } class Line { private Point p1, p2; private String colour; public Line(Point p1, Point p2, String colour) { this.p1 = p1; this.p2 = p2; this.colour = colour; } public double getDistance() { return Math.sqrt((p1