ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

题目集4~6的总结性blog

2021-04-27 17:03:13  阅读:125  来源: 互联网

标签:总结性 题目 int double month blog year public day


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

前三次作业多数为类的基本应用,简单的继承和多态的应用。题量不大难度也不大。但是比较考验同学的细心程度和对知识点的全面理解,不然很可疑能因为一个较小的误区导致代码无法正常运行。

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

    ①题目集4(7-2)、题目集5(7-4)两种日期类聚合设计的优劣比较

这题我还是有较大的发言权的,题4的7-2聚合一当时我是做了很久的,除了Main类它还细分了Year、Month、Day等多个类,而且每个类中的函数至少三个。属性也基本雷同。光是建辅类的框架我就弄了一个上午(当时也是因为并不太熟悉类的基本用法,刚刚接触),写完之后我就觉得真的太麻烦了(其实在写的过程就觉得了),真的太麻烦了,很多重复冗余的代码,一层一层的重复套用,就像老太太的裹脚布一样,又臭又长!最后,在美接触题57-4之前,我就自己自觉的抛开了题目的要求,改成了聚合二的写法,把Year、Month、Day归结于Dateutil,删除了多余的东西,也是直接过了测试点。虽然没按要求来,但是pta还是笨的,测试点全过了,它哪知道你用的什么方法。(当然,这个做法并不好,我没有煽动后来人投机取巧的意思。手动笑哭)。

所以总的来说,其实我上面也算说的很明白了:聚合二较聚合一,更加精炼,删除了冗余的代码,使代码更加漂亮并且有逻辑!

    ②题目集4(7-3)、题目集6(7-5、7-6)三种渐进式图形继承设计的思路与技术运用(封装、继承、多态、接口等)

 题4的7-3是图形继承设计较为简单的一题了,它粗浅的运用了继承和封装的知识点。继承使代码更为精炼且具有延展性,不需要在相同的代码上重复粘贴,也使代码在原功能上增加功能来得更为方便。封装则使代码的隐蔽性、安全性加强。减少了一些不安全措施更改已有的代码。是java面向对象基础并且优于其他代码的闪光点之一。

题6的7-5、7-6更多是对多态和接口的应用,接口可以被编写的多个程序重复调用,可以节省电脑的存储空间,并且使用接口可以减少电脑代码运行时出现的错误,在运行多个程序时,也能更有效率的进行。多态则和继承类似,对于代码的延展性有比较大的帮助。总是是题47-3代码的一次优化与进步!

    ③对三次题目集中用到的正则表达式技术的分析总结

(1).在其他的语言中(如Perl),一个反斜杠 \ 就足以具有转义的作用,而在 Java 中正则表达式中则需要有两个反斜杠才能被解析为其他语言中的转义作用。也可以简单的理解在 Java 的正则表达式中,两个 \\ 代表其他语言中的一个 \,这也就是为什么表示一位数字的正则表达式是 \\d,而表示一个普通的反斜杠是 \\\\。

(2).public boolean find()用于查找该模式匹配的输入序列的下一个子序列。

(3).Pattern和Matcher的用法。

(4).matches和lookingat方法。

(5).replaceFirst和replaceAll方法。

(6).还有以exit结束多行输入字符串使用到的动态stringbuffer等等。

    ④题目集5(7-4)中Java集合框架应用的分析总结

集合框架定义了几种算法,可用于集合和映射。这些算法被定义为集合类的静态方法。

首先可以了解一下map和hasmap。说一个大实话,在做题57-4之前我都不知道map是什么?可以想象到,一个连概念都不清晰的人是怎么把它运用到pta上的嘛?

最后,我经过千辛万苦(好吧,可能并不至于),终于弄清楚了一些基础的概念。

map,你可以把它理解成一个数据字典,你给每个数据对象可以制定个代号,比如编码或者是名字,或者是数据库里的主键值,然后用它做索引把数据放进map里,下次你可以直接用代号从map里取出这个数据,而不用像数组、列表那样要从头到尾查找一遍。

而hasmap,简单的说,

HashMap 是 Map 接口的常用实现类(Map是一个接口),是一个键值对集合。 除此之外还有arraylist和linklist的用法,都顺便了解了一下。

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

题4 7-2

import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int num = in.nextInt();

if(num==1||num==2||num==3){
if(num==1){
int year = in.nextInt();
int month = in.nextInt();
int day = in.nextInt();
int n = in.nextInt();

DateUtil dateUtil = new DateUtil(year,month,day);
if(dateUtil.checkInputValidity(year,month,day)){
dateUtil.getNextNDays(n);
}
else{
System.out.println("Wrong Format");
}
}
if(num==2){
int year = in.nextInt();
int month = in.nextInt();
int day = in.nextInt();
int n = in.nextInt();

DateUtil dateUtil = new DateUtil(year,month,day);
if(dateUtil.checkInputValidity(year,month,day)){
dateUtil.getPreviousNDays(n);
}
else{
System.out.println("Wrong Format");
}
}
if(num==3){
int year = in.nextInt();
int month = in.nextInt();
int day = in.nextInt();

int anotherYear = in.nextInt();
int anotherMonth = in.nextInt();
int anotherDay = in.nextInt();

DateUtil fromDate = new DateUtil(year, month, day);
DateUtil toDate = new DateUtil(anotherYear, anotherMonth, anotherDay);

if (fromDate.checkInputValidity(year,month,day) && toDate.checkInputValidity(anotherYear,anotherMonth,anotherDay)) {
System.out.println(fromDate.getDaysofDates(toDate));
} else {
System.out.println("Wrong Format");
}
}
}
else{
System.out.println("Wrong Format");
}
}
}
class DateUtil{
private int year;
private int month;
private int day;

public DateUtil(){

}
public DateUtil(int year,int month,int day){
this.year = year;
this.month = month;
this.day = day;
}

public void setYear(int year) {
this.year = year;
}
public void setMonth(int month) {
this.month = month;
}
public void setDay(int day) {
this.day = day;
}
public int getYear() {
return year;
}
public int getMonth() {
return month;
}
public int getDay() {
return day;
}

public boolean checkInputValidity(int year,int month,int day){
if((year>=1900&&year<=2050)&&(month>=1&&month<=12)&&(day>=1&&day<=getDayOfMonth(year,month))){
return true;
}
return false;
}
public boolean isLeapYear(int year)
{
if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0){
return true;
}
return false;
}

public int getDayOfMonth(int year,int month){
int mon[]={31,28,31,30,31,30,31,31,30,31,30,31};
int days = mon[month-1];
if(month==2&&isLeapYear(year)){
days = 29;
}
return days;
}
public void getNextNDays(int n){
int year = this.year;
int month = this.month;
int day = this.day;

for (int i = 0; i < n; i++) {
day++;
if (day > getDayOfMonth(year, month)) {
day = 1;
month++;
if (month > 12) {
month = 1;
year++;
}
}
}
System.out.println(year+"-"+month+"-"+day);
}

public void getPreviousNDays(int n){
int year = this.year;
int month = this.month;
int day = this.day;
for (int i = 0; i < n; i++) {
day--;
while (day < 1) {
month--;
if (month < 1) {
month = 12;
year--;
}
day += getDayOfMonth(year, month);
}
}
System.out.println(year+"-"+month+"-"+day);
}

public boolean compareDates(DateUtil date)
{
if (this.year > date.year) return true;
if (this.year == date.year) {
if (this.month > date.month) return true;
if (this.month == date.month) {
if (this.day >= date.day) return true;
}
}
return false;
}

public boolean equalTwoDates(DateUtil date)
{
if (date != null) {
if (year == date.year && month == date.month && day == date.day) {
return true;
}
}
return false;
}

private static final int[] mon = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
public int getDaysofDates(DateUtil date)
{
DateUtil dateUtil1 = this; // 小
DateUtil dateUtil2 = date; // 大
if (this.compareDates(date)) {
dateUtil1 = date;
dateUtil2 = this;
}

int days;
int leapYearNum = 0;
for (int i = dateUtil1.getYear(); i < dateUtil2.getYear(); i++) {
if (isLeapYear(i)) {
leapYearNum++;
}
}

days = 365 * (dateUtil2.getYear() - dateUtil1.getYear()) + leapYearNum;

int d1 = mon[dateUtil1.getMonth() - 1] + dateUtil1.getDay() + (dateUtil1.getMonth() > 2 && isLeapYear(dateUtil1.getYear()) ? 1 : 0);
int d2 = mon[dateUtil2.getMonth() - 1] + dateUtil2.getDay() + (dateUtil2.getMonth() > 2 && isLeapYear(dateUtil2.getYear()) ? 1 : 0);
return days - d1 + d2;
}

/*
public int getDaysofDates(int year,int month,int day){
int y1 = this.year;
int m1 = this.month;
int d1 = this.day;

int y2 = year;
int m2 = month;
int d2 = day;

long t1 = time(d1,m1,y1);
long t2 = time(d2,m2,y2);

long t3 = Math.abs(t1-t2);
int t = (int)(t3/(24*60));

return t;
}
public long time(int d0,int m0,int y0){
long t=0;
int cnt=0;
int mon[]={0,31,58,90,120,151,181,212,243,273,304,334};

for(int i=1; i<=y0 ;i++){
if((y0%4==0&&y0%100!=0)||y0%400==0){
cnt++;
}
}

if((y0%4==0&&y0%100!=0)||y0%400==0){
if((m0==2&&d0==29)||m0>2) {
t = (((y0 - 1) * 365) + cnt) * 24 * 60 * 60 + (mon[m0] + d0) * 24 * 60 + 24 * 60;
}
else{
t = (((y0-1)*365)+cnt)*24*60*60+(mon[m0]+d0)*24*60;
}
}
else{
t = (((y0-1)*365)+cnt)*24*60*60+(mon[m0]+d0)*24*60;
}
return t;
}
*/

}

总结:做这题第三个getdayofmonths()的时候,我脑子真是算是一团浆糊,后面通过百度是让我用点想法了,开始我是打算把每一个具体的天到0000年经过的秒数都计算出来减去另一天经过的秒数再除以一天的秒数,但实操起来并不容易,还要注意平闰年。但是呢,我好不容易弄完了,有出现问题了,运行的结果并不是我要求的。就很烦吧。后面就改成了现在所用的这个方法吧。总而言之,烦!之前那个方法弄了我好几天,最后却付之东流了,哎~

7-3

import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int num = in.nextInt();

if(num==1||num==2||num==3||num==4){

if (num == 1) {
double r = in.nextDouble();
if (r <= 0) {
System.out.println("Wrong Format");
}
else {
Circle circle = new Circle();
double S = circle.getArea(r);
System.out.printf("Circle's area:%.2f\n",S);
}
}
if (num == 2) {
double w = in.nextDouble();
double l = in.nextDouble();
if (w<=0||l<=0) {
System.out.println("Wrong Format");
}
else {
Rectangle rectangle = new Rectangle();
double S = rectangle.getArea(w, l);
System.out.printf("Rectangle's area:%.2f\n",S);
}
}
if (num == 3) {
double r = in.nextDouble();
if(r<=0) {
System.out.println("Wrong Format");
}

else {
Ball ball = new Ball();
double S = ball.getArea(r);
double V = ball.getVolume(r);
System.out.printf("Ball's surface area:%.2f\n",S);
System.out.printf("Ball's volume:%.2f\n",V);
}
}
if (num == 4) {
double w = in.nextDouble();
double l = in.nextDouble();
double h = in.nextDouble();
if (w<=0||l<=0||h<=0) {
System.out.println("Wrong Format");
}
else {
Box box = new Box();
double S = box.getArea(w, l, h);
double V = box.getVolume(w, l, h);
System.out.printf("Box's surface area:%.2f\n",S);
System.out.printf("Box's volume:%.2f\n",V);
}
}
}
else{
System.out.println("Wrong Format");
}

}
}
class Shape{
public Shape(){
System.out.println("Constructing "+"Shape");
}
public double getArea(double r){
return 0.0;
}
public double getArea(double w,double l){
return 0.0;
}
public double getArea(double w,double l,double h){
return 0.0;
}
}
class Circle extends Shape{
private double radius;

public Circle(){
System.out.println("Constructing "+"Circle");
}
public void setRadius(double radius){
this.radius = radius;
}
public double getRadius(){
return radius;
}

public double getArea(double r){
return Math.PI*r*r;
}

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

public Rectangle(){
System.out.println("Constructing "+"Rectangle");
}
public void setWidth(double width){
this.width = width;
}
public double getWidth(){
return width;
}
public void setLength(double length){
this.length = length;
}
public double getLength(){
return length;
}

public double getArea(double w,double l){
return w*l;
}

}
class Ball extends Circle{
public Ball(){
System.out.println("Constructing "+"Ball");
}

public double getArea(double r){
return Math.PI*r*r*4;
}
public double getVolume(double r){
return Math.PI*r*r*r*(4/3.0);
}

}
class Box extends Rectangle{
private double height;
public Box(){
System.out.println("Constructing "+"Box");
}
public double getArea(double w,double l,double h){
return 2*w*l+2*w*h+2*l*h;
}
public double getVolume(double w,double l,double h){
return w*l*h;
}
}

总结:这题呢,就很简单了,简单的继承与封装。自己看看吧。

 题5 7-4

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {

public static void main(String[] args) {
Scanner in = new Scanner(System.in);
StringBuilder ss = new StringBuilder();
Map<String, Integer> map=new HashMap<String, Integer>();

String []key= { "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"

};

String str = in.nextLine();
String ending = "exit";
int j = 0;

boolean flag = str.matches(ending);
while (flag == false) {
ss.append(str);
ss.append("\n");
str = in.nextLine();
flag = str.matches(ending);
}

String[] everyline = ss.toString().split("\n");
int count=0;
String s=ss.toString();
// System.out.println(s);
Pattern p=Pattern.compile("\"(.*?)\"");
Matcher m=p.matcher(s);
while(m.find()){
s=s.replace(m.group()," ");
p=Pattern.compile("\"(.*?)\"");
m=p.matcher(s);
}
p=Pattern.compile("/\\**(.*?)/");
m=p.matcher(s);
while(m.find()){
s=s.replace(m.group()," ");
// p=Pattern.compile("/\\*(.*?)\\*/");
m=p.matcher(s);
}
// System.out.println(s);
if(s.isEmpty())
{System.out.println("Wrong Format");
System.exit(0);
}
s=s.replace("["," ");
s=s.replace("]"," ");
s=s.replace("-","a");
s=s.replace("*","a");
s=s.replace("/","a");
s=s.replace("+","a");
s=s.replace(">","a");
s=s.replace("=","a");
s=s.replace("!","a");
s=s.replace(":","a");
s=s.replace("\\","a");
s= s.replaceAll("[^a-zA-Z]", " ");

String []s1=s.split("[ ' ']");
for(int i=0;i<s1.length;i++)
{
for( j=0;j<key.length;j++)
if(s1[i].equals(key[j]))
{
map.put(key[j], 0);
}
}
for( int i = 0;i<s1.length;i++)
{
for( j=0;j<key.length;j++)
if(s1[i].equals(key[j]))
{ count=map.get(key[j]);
map.put(key[j], count+1);
}
}
Set set=map.keySet();
Object[] arr=set.toArray();
Arrays.sort(arr);
for(Object k:arr){
System.out.println(map.get(k)+"\t"+k);
}
}
}

总结:这题呢,我也明人不说暗话了,我在网上看的,理解完了后,改了其中一小点就交到pta上了。可以说是抄袭吧,但是里面很多知识点老师并没有讲,却要我们在一星期内自学完后再应用于题目上。还不顾及我们其他科目也要学习,四级马上就要考试等总总因素,未免强人所难。当然每个学院都存在大神多方面都兼顾到了,在这里也只能膜拜一下了,但是我不是。

7-5

import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int num = in.nextInt();

if(num==1||num==2||num==3){
if(num==1){
int year = in.nextInt();
int month = in.nextInt();
int day = in.nextInt();
int n = in.nextInt();

DateUtil dateUtil = new DateUtil(year,month,day);
if(dateUtil.checkInputValidity(year,month,day)){
System.out.print(year+"-"+month+"-"+day+" next "+n+" days is:");
dateUtil.getNextNDays(n);
}
else{
System.out.println("Wrong Format");
}
}
if(num==2){
int year = in.nextInt();
int month = in.nextInt();
int day = in.nextInt();
int n = in.nextInt();

DateUtil dateUtil = new DateUtil(year,month,day);
if(dateUtil.checkInputValidity(year,month,day)){
System.out.print(year+"-"+month+"-"+day+" previous "+n+" days is:");
dateUtil.getPreviousNDays(n);
}
else{
System.out.println("Wrong Format");
}
}
if(num==3){
int year = in.nextInt();
int month = in.nextInt();
int day = in.nextInt();

int anotherYear = in.nextInt();
int anotherMonth = in.nextInt();
int anotherDay = in.nextInt();

DateUtil fromDate = new DateUtil(year, month, day);
DateUtil toDate = new DateUtil(anotherYear, anotherMonth, anotherDay);

if (fromDate.checkInputValidity(year,month,day) && toDate.checkInputValidity(anotherYear,anotherMonth,anotherDay)) {
System.out.print("The days between "+year+"-"+month+"-"+day+" and "+anotherYear+"-"+anotherMonth+"-"+anotherDay+" are:");
System.out.println(fromDate.getDaysofDates(toDate));
} else {
System.out.println("Wrong Format");
}
}
}
else{
System.out.println("Wrong Format");
}
}
}
class DateUtil{
private int year;
private int month;
private int day;

public DateUtil(){

}
public DateUtil(int year,int month,int day){
this.year = year;
this.month = month;
this.day = day;
}

public void setYear(int year) {
this.year = year;
}
public void setMonth(int month) {
this.month = month;
}
public void setDay(int day) {
this.day = day;
}
public int getYear() {
return year;
}
public int getMonth() {
return month;
}
public int getDay() {
return day;
}

public boolean checkInputValidity(int year,int month,int day){
if((year>=1820&&year<=2020)&&(month>=1&&month<=12)&&(day>=1&&day<=getDayOfMonth(year,month))){
return true;
}
return false;
}
public boolean isLeapYear(int year)
{
if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0){
return true;
}
return false;
}

public int getDayOfMonth(int year,int month){
int mon[]={31,28,31,30,31,30,31,31,30,31,30,31};
int days = mon[month-1];
if(month==2&&isLeapYear(year)){
days = 29;
}
return days;
}
public void getNextNDays(int n){
int year = this.year;
int month = this.month;
int day = this.day;

for (int i = 0; i < n; i++) {
day++;
if (day > getDayOfMonth(year, month)) {
day = 1;
month++;
if (month > 12) {
month = 1;
year++;
}
}
}
System.out.println(year+"-"+month+"-"+day);
}

public void getPreviousNDays(int n){
int year = this.year;
int month = this.month;
int day = this.day;
for (int i = 0; i < n; i++) {
day--;
while (day < 1) {
month--;
if (month < 1) {
month = 12;
year--;
}
day += getDayOfMonth(year, month);
}
}
System.out.println(year+"-"+month+"-"+day);
}

public boolean compareDates(DateUtil date)
{
if (this.year > date.year) return true;
if (this.year == date.year) {
if (this.month > date.month) return true;
if (this.month == date.month) {
if (this.day >= date.day) return true;
}
}
return false;
}

public boolean equalTwoDates(DateUtil date)
{
if (date != null) {
if (year == date.year && month == date.month && day == date.day) {
return true;
}
}
return false;
}

private static final int[] mon = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334};
public int getDaysofDates(DateUtil date)
{
DateUtil dateUtil1 = this; // 小
DateUtil dateUtil2 = date; // 大
if (this.compareDates(date)) {
dateUtil1 = date;
dateUtil2 = this;
}

int days;
int leapYearNum = 0;
for (int i = dateUtil1.getYear(); i < dateUtil2.getYear(); i++) {
if (isLeapYear(i)) {
leapYearNum++;
}
}

days = 365 * (dateUtil2.getYear() - dateUtil1.getYear()) + leapYearNum;

int d1 = mon[dateUtil1.getMonth() - 1] + dateUtil1.getDay() + (dateUtil1.getMonth() > 2 && isLeapYear(dateUtil1.getYear()) ? 1 : 0);
int d2 = mon[dateUtil2.getMonth() - 1] + dateUtil2.getDay() + (dateUtil2.getMonth() > 2 && isLeapYear(dateUtil2.getYear()) ? 1 : 0);
return days - d1 + d2;
}
}

总结:我这题和之前那题做法一样,就不重复说明了。

题6 7-5

import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.Scanner;

public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);

DecimalFormat df = new DecimalFormat("0.00");

int flag = 1,flag1 = 1,flag2 = 1,flag3 = 1;

double banjin = 0;
double chang = 0,kuang = 0;
double l1 = 0,l2 = 0,l3 = 0;

double allS1 = 0;
double allS2 = 0;

int c = in.nextInt();
int r = in.nextInt();
int t = in.nextInt();

double[] sc = new double[c];
double[] sr = new double[r];
double[] st = new double[t];

if(c<0||r<0||t<0){
flag = 0;
}
else{
for (int i = 0; i < c; i++) {
Circle[] circle = new Circle[c];
banjin = in.nextDouble();
if (banjin <= 0) {
flag1 = 0;
}
circle[i] = new Circle(banjin);
sc[i] = circle[i].getArea();
}
for (int i = 0; i < r; i++) {
Rectangle[] rectangle = new Rectangle[r];
chang = in.nextDouble();
kuang = in.nextDouble();
if (chang < 0 || kuang < 0) {
flag2 = 0;
}
rectangle[i] = new Rectangle(chang, kuang);
sr[i] = rectangle[i].getArea();
}
for (int i = 0; i < t; i++) {
Triangle[] triangle = new Triangle[t];
l1 = in.nextDouble();
l2 = in.nextDouble();
l3 = in.nextDouble();
triangle[i] = new Triangle(l1, l2, l3);
if (l1 < 0 || l2 < 0 || l3 < 0 || !triangle[i].check()) {
flag3 = 0;
}
st[i] = triangle[i].getArea();
}
}

if(flag1==0||flag2==0||flag3==0||flag==0){
System.out.println("Wrong Format");
}
else{
System.out.println("Original area:");
for (int i = 0; i < c; i++) {
System.out.print(df.format(sc[i]) + " ");
}
for (int j = 0; j < r; j++) {
System.out.print(df.format(sr[j]) + " ");
}
for (int k = 0; k < t; k++) {
System.out.print(df.format(st[k]) + " ");
}
System.out.println();

double[] arr = new double[c + r + t];
for (int i = 0; i < c; i++) {
arr[i] = sc[i];
}
for (int i = 0; i < r; i++) {
arr[i + c] = sr[i];
}
for (int i = 0; i < t; i++) {
arr[i + c + r] = st[i];
}

for (int i = 0; i < (c + r + t); i++) {
allS1 += arr[i];
}
System.out.println("Sum of area:" + df.format(allS1));

Arrays.sort(arr);
System.out.println("Sorted area:");
for (int i = 0; i < (c + r + t); i++) {
allS2 += arr[i];
System.out.print(df.format(arr[i]) + " ");
}
System.out.println();

System.out.print("Sum of area:" + df.format(allS2));

}
}
}

class Circle{
double r;
public Circle(){

}
public Circle(double r){
this.r = r;
}
public double getArea(){
return Math.PI*r*r;
}
}
class Rectangle{
double width,length;
public Rectangle(){

}
public Rectangle(double width,double length){
this.width = width;
this.length = length;
}
public double getArea(){
return width*length;
}
}
class Triangle{
double a,b,c;
public Triangle(){

}
public Triangle(double a,double b,double c){
this.a = a;
this.b = b;
this.c = c;
}

public boolean check(){
if(a+b>c&&a+c>b&&b+c>a){
return true;
}
else{
return false;
}
}
public double getArea(){
double p = (a+b+c)/2;
return Math.sqrt(p*(p-a)*(p-b)*(p-c));
}
}

7-6

import java.util.Scanner;
import java.text.DecimalFormat;
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
DecimalFormat df = new DecimalFormat("#.00");

double a = in.nextDouble();
double b = in.nextDouble();
double c = in.nextDouble();

if(a<=0||b<=0||c<=0){
System.out.println("Wrong Format");
}
else{
Circle circle = new Circle(a);
Rectangle rectangle = new Rectangle(b,c);
double s1 = circle.getArea();
double s2 = rectangle.getArea();

System.out.println(df.format(s1));
System.out.println(df.format(s2));
}
}
}
class Circle{
private double r;
public Circle(){

}
public Circle(double r){
this.r = r;
}
public double getR(){
return r;
}
public void setR(double r){
this.r = r;
}
public double getArea(){
return Math.PI*r*r;
}
}
class Rectangle{
private double width,length;
public Rectangle(){

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

总结:这两题相对简单,我也没跟着题目要求写。也就这样了,不多说。

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

意见哪敢有,是我自己菜。多看视频多大代码吧。多写一点多懂一点,就酱吧。

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

1.通过这几次作业,我学会了java的多态、继承和接口的概念,学会了正则表达式的常用方法。

2.哪些地方需要改进呢:希望老师、课程进度再快一点,不要等我们写完了作业才开始讲知识点,作业的内容对我们很多学生来说都是超纲的,基本都是自学才能完成作业,手动笑哭。

作业呢,就尽量出些我们学过的知识去考,不然学过的知识都没巩固,不会的知识也只学了个皮毛,既没捡到芝麻也丢了西瓜。

课上课下的组织方式应该也算ok,实验课我觉得可以再多给点,还是那句话,实验出真知。

标签:总结性,题目,int,double,month,blog,year,public,day
来源: https://www.cnblogs.com/be11/p/14709788.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有