By GokiSoft.com|
19:42 06/05/2024|
Java Basic
[Examination] ADF1 - Java Basic - T2008A
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)
![Triệu Văn Lăng [T2008A]](https://www.gravatar.com/avatar/1348e3562c6492c26f796cb1f45982a1.jpg?s=80&d=mm&r=g)
Triệu Văn Lăng
2021-03-05 09:01:41
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package exam;
/**
*
* @author MTLS
*/
public class Driver {
/**
*
* @param a
* @return
*/
public static double sumArea(GeometricObject[] a);
public static void main(String[] args) {
}
}
![Triệu Văn Lăng [T2008A]](https://www.gravatar.com/avatar/1348e3562c6492c26f796cb1f45982a1.jpg?s=80&d=mm&r=g)
Triệu Văn Lăng
2021-03-05 09:01:22
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package exam;
/**
*
* @author MTLS
*/
public class Rectangle extends GeometricObject {
double width, height;
public Rectangle(String color, boolean filled) {
super(color, filled);
}
public Rectangle(double width, double height, String color, boolean filled) {
super(color, filled);
this.width = width;
this.height = height;
}
public double getWidth() {
return width;
}
public double getHeight() {
return height;
}
public void setWidth(double width) {
this.width = width;
}
public void setHeight(double height) {
this.height = height;
}
}
![Triệu Văn Lăng [T2008A]](https://www.gravatar.com/avatar/1348e3562c6492c26f796cb1f45982a1.jpg?s=80&d=mm&r=g)
Triệu Văn Lăng
2021-03-05 09:01:03
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package exam;
import java.util.Date;
/**
*
* @author MTLS
*/
public class Circle extends GeometricObject{
double radius;
public Circle(String color, boolean filled) {
super(color, filled);
}
public Circle(double radius, String color, boolean filled) {
super(color, filled);
this.radius = radius;
}
public double getRadius() {
return radius;
}
public void setRadius(double radius) {
this.radius = radius;
}
}
![Triệu Văn Lăng [T2008A]](https://www.gravatar.com/avatar/1348e3562c6492c26f796cb1f45982a1.jpg?s=80&d=mm&r=g)
Triệu Văn Lăng
2021-03-05 09:00:39
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package exam;
import java.util.Date;
/**
*
* @author MTLS
*/
public class GeometricObject {
String color;
boolean filled;
java.util.Date dateCreated = new java.util.Date();
public GeometricObject(String color, boolean filled) {
this.color = color;
this.filled = filled;
}
public String getColor() {
return color;
}
public boolean isFilled() {
return filled;
}
public Date getDateCreated() {
return dateCreated;
}
public void setColor(String color) {
this.color = color;
}
public void setFilled(boolean filled) {
this.filled = filled;
}
public void setDateCreated(Date dateCreated) {
this.dateCreated = dateCreated;
}
@Override
public String toString() {
return "GeometricObject{" + "color=" + color + ", filled=" + filled + ", dateCreated=" + dateCreated + '}';
}
public void getArea() {
}
public void getPerimeter() {
}
}
![Bùi Văn Mạnh [T2008A]](https://www.gravatar.com/avatar/17e9c94870c94e61c9203ee31dccf01c.jpg?s=80&d=mm&r=g)
Bùi Văn Mạnh
2021-03-05 08:58:59
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package exam1;
/**
*
* @author FPT 174
*/
public class Exam3 {
//date field
private double width;
private double height;
//constructors
public Rectangle(double width, double height)
{
this.width = width;
this.height = height;
}
public Rectangle(double width, double height, String color, boolean filled)
{
this.width = width;
this.height = height;
setColor(color);
setFilled(filled);
}
//getter
public double getWidth()
{
return width;
}
public void setWidth(double width)
{
this.width = width;
}
public double getHeight()
{
return height;
}
//setter
private void setHeight(double height)
{
this.height = height;
}
public double getArea()
{
return width * height;
}
//get perimeter
public double getPerimeter(){
return 2 * (width + height);
}
}
![Bùi Văn Mạnh [T2008A]](https://www.gravatar.com/avatar/17e9c94870c94e61c9203ee31dccf01c.jpg?s=80&d=mm&r=g)
Bùi Văn Mạnh
2021-03-05 08:56:42
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package exam1;
/**
*
* @author FPT 174
*/
public class Exam2 {
//date fields
private String color = "White";
private boolean filled;
private java.util.Date dateCreated;
//constructors
public GeometricObject()
{
dateCreated = new java.util.Date();
}
public GeometricObject(String color, boolean filled)
{
dateCreated = new java.util.Date();
this.color = color;
this.filled = filled;
}
//getter
public String getColor()
{
return color;
}
public boolean isFilled()
{
return filled;
}
public java.util.Date getDateCreated()
{
return dateCreated;
}
//setter
public void setColor(String color)
{
this.color = color;
}
public void setFilled(boolean filled)
{
this.filled = filled;
}
//override toString
public String toString()
{
return "Created on " + dateCreated + "\ncolor: " + color +
" and filled: " + filled;
}
}
![Bùi Văn Mạnh [T2008A]](https://www.gravatar.com/avatar/17e9c94870c94e61c9203ee31dccf01c.jpg?s=80&d=mm&r=g)
Bùi Văn Mạnh
2021-03-05 08:56:29
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package exam1;
/**
*
* @author FPT 174
*/
public class Exam1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// T//data field
private double radius;
//constructors
public Circle(){
}
public Circle(double radius){
this.radius = radius;
}
public Circle(double radius, String color, boolean filled)
{
this.radius = radius;
setColor(color);
setFilled(filled);
}
//getter
public double getRadius()
{
return radius;
}
public double getArea()
{
return radius * radius * Math.PI;
}
public double getPerimeter()
{
return 2 * radius;
}
public double getDiameter()
{
return 2 * radius * Math.PI;
}
//setter
public void setRadius( double radius)
{
this.radius = radius;
}
//print the Circle
public void printCircle()
{
System.out.println("The circle is created " + getDateCreated() + " and the radius is " + radius);
}
}ODO code application logic here
}
![Trần Thị Khánh Huyền [T2008A]](https://www.gravatar.com/avatar/554e115833778e4294a01aebe228f3d6.jpg?s=80&d=mm&r=g)
Trần Thị Khánh Huyền
2021-03-05 08:53:09
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package baithilythuyet.geometricobject;
import java.util.Date;
/**
*
* @author Admin
*/
public class Retangle extends GeometricObject {
double wild;
double height;
public Retangle() {
}
public Retangle(double wild, double height, String color, boolean filled, Date dateCreated, double area, double perimeter) {
super(color, filled, dateCreated, area, perimeter);
this.wild = wild;
this.height = height;
}
}
![Đặng Trần Nhật Minh [T2008A]](https://www.gravatar.com/avatar/ee8dc5a777ad26f3a962e86c233437cf.jpg?s=80&d=mm&r=g)
Đặng Trần Nhật Minh
2021-03-05 08:52:27
#Circle.java
package Exam;
public class Circle extends GeometricObject{
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 getDiameter(){
return radius * 2;
}
@Override
public double getArea() {
return Math.PI * radius * radius;
}
@Override
public double getPerimeter() {
return 2 * Math.PI * radius;
}
}
#Drive.java
package Exam;
import java.util.Scanner;
public class Drive {
public static void main(String[] args) {
GeometricObject[] objectList = new GeometricObject[2];
Circle circle = new Circle();
Rectangle rectangle = new Rectangle();
Scanner scan = new Scanner(System.in);
System.out.println("Input circle:");
System.out.println("Radius:");
float radius = scan.nextFloat();
circle.radius = radius;
objectList[0] = circle;
System.out.println("Input rectangle:");
System.out.println("Width:");
float width = scan.nextFloat();
rectangle.width = width;
System.out.println("Height:");
float height = scan.nextFloat();
rectangle.height = height;
objectList[1] = rectangle;
System.out.println("Sum areas of all objects: " + sumArea(objectList));
}
public static double sumArea(GeometricObject[] a){
double sum = 0;
for (GeometricObject geometricObject : a) {
sum += geometricObject.getArea();
}
return sum;
}
}
#GeometricObject.java
package Exam;
import java.util.Date;
public abstract class GeometricObject {
String color;
boolean filled;
java.util.Date dateCreated;
protected GeometricObject() {
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public boolean isFilled() {
return filled;
}
public void setFilled(boolean filled) {
this.filled = filled;
}
public Date getDateCreated() {
return dateCreated;
}
@Override
public String toString() {
return "GeometricObject{" + "color=" + color + ", filled=" + filled + ", dateCreated=" + dateCreated + '}';
}
public abstract double getArea();
public abstract double getPerimeter();
}
#Rectangle.java
package Exam;
public class Rectangle extends GeometricObject{
double width,height;
public Rectangle() {
}
public Rectangle(double width, double height) {
this.width = width;
this.height = height;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
@Override
public double getArea() {
return width * height;
}
@Override
public double getPerimeter() {
return 2 * (width + height);
}
}
![Trần Thị Khánh Huyền [T2008A]](https://www.gravatar.com/avatar/554e115833778e4294a01aebe228f3d6.jpg?s=80&d=mm&r=g)
Trần Thị Khánh Huyền
2021-03-05 08:52:19
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package baithilythuyet.geometricobject;
import java.util.Date;
/**
*
* @author Admin
*/
public class Circle extends GeometricObject{
double radius;
public Circle() {
}
public Circle(double radius, String color, boolean filled, Date dateCreated, double area, double perimeter) {
super(color, filled, dateCreated, area, perimeter);
this.radius = radius;
}
}