java3.30作业

Posted niuwy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java3.30作业相关的知识,希望对你有一定的参考价值。

1.

package com.company.niuweiyong;
public class asdasdasd

abstract class Geometric
String color;
boolean filled;
public Geometric()

public Geometric(String color, boolean filled)
this.color = color;
this.filled = filled;

abstract double getArea();
abstract double getPerimeter();
@Override
public String toString()
return "Geometric [color=" + color + ", filled=" + filled + ", getArea()=" + getArea() + ", getPerimeter()="
+ getPerimeter() + ", getClass()=" + getClass() + ", hashCode()=" + hashCode() + ", toString()="
+ super.toString() + "]";




2.
package com.company.niuweiyong;;

public class Circle extends Geometric
private static final double pI=3.14;

double radius;//名为radius的double属性表示半径。
//无参构造方法。
public Circle()




//一个能创建指定radius的圆的构造方法
public Circle(double radius)
this.radius = radius;

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

//radius的访问器方法
public double getRadius()
return radius;

@Override
double getArea()

return pI * radius *radius;


@Override
double getPerimeter()

return 2 * pI *radius;

@Override
public String toString()
return "Circle [radius=" + radius + ", getArea()=" + getArea() + ", getPerimeter()=" + getPerimeter() + "]";


3.
package com.company.niuweiyong;;

public class Rectangle extends Geometric

private double side1;
private double side2;
public Rectangle()

public Rectangle(double side1, double side2)
super();
this.side1 = side1;
this.side2 = side2;

public double getSide1()
return side1;

public void setSide1(double side1)
this.side1 = side1;

public double getSide2()
return side2;

public void setSide2(double side2)
this.side2 = side2;

@Override
double getArea()
// TODO Auto-generated method stub
return side1 *side2;

@Override
double getPerimeter()
// TODO Auto-generated method stub
return 2 *(side1 + side2);

@Override
public String toString()
return "Rectangle [side1=" + side1 + ", side2=" + side2 + ", getArea()=" + getArea() + ", getPerimeter()="
+ getPerimeter() + "]";




4.
package com.company.niuweiyong;;
import org.apache.jasper.tagplugins.jstl.core.If;
public class Triangle extends Geometric
int t;
private double side1;
private double side2;
private double side3;
public Triangle()
// TODO Auto-generated constructor stub

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

@Override
double getArea()
double p=((side1+side2+side3)/2);;
return Math.sqrt(p*(p-side1)*(p-side2)*(p-side3)) ;

@Override
double getPerimeter()
return side1+side2+side3;

boolean kk(double side1, double side2, double side3)
if ((side1 + side2) > side3 && (side1 + side3) > side2 && (side2 + side3) > side1)
return true;
else
return false;


@Override
public String toString()
//判断最小值
double temp;
if (side1 >= side2)
temp = side1;
side1 = side2;
side2 = temp;

if (side1 >= side3)
temp = side1;
side1 = side3;
side3 = temp;

return " kk [side1=" + side1 + "] ";


5.
package com.company.niuweiyong;
import java.util.Scanner;
public class dasdsadas
private static Scanner sc;

public static void main(String[] args)
sc =new Scanner(System.in);
double radius=sc.nextDouble();
Circle c1 =new Circle(radius);
System.out.println("圆的面积"+c1.getArea());
System.out.println("圆的周长" +c1.getPerimeter());
System.out.println(c1.toString());

double side1 =sc.nextDouble();
double side2 =sc.nextDouble();
Rectangle rectangle=new Rectangle(side1,side2);
System.out.println("矩形的面积"+rectangle.getArea());
System.out.println("矩形的周长" +rectangle.getPerimeter());
System.out.println(rectangle.toString());

double side3 =sc.nextDouble();
double side4 =sc.nextDouble();
double side5 =sc.nextDouble();
Triangle triangle =new Triangle(side3,side4,side5);
if (triangle.kk(side3, side4, side5))
System.out.println("三角形的面积"+triangle.getArea());
System.out.println("三角形的周长" +triangle.getPerimeter());
System.out.println("三边最小值"+triangle.toString());
else

System.out.println("不能构成三角行");




以上是关于java3.30作业的主要内容,如果未能解决你的问题,请参考以下文章

LSF 作业管理系统

作业第三周作业

为啥在 Kubernetes cron 作业中可能会创建两个作业,或者可能不会创建作业?

第五次个人作业:个人总结

模拟处理机作业调度---短作业优先调度算法

ThinkPHP5作业管理系统中处理学生未交作业与已交作业信息