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)
![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:50: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 baithilythuyet.geometricobject;
import java.util.Date;
/**
*
* @author Admin
*/
public class GeometricObject{
String color;
boolean filled;
Date dateCreated;
double area;
double perimeter;
public GeometricObject() {
}
public GeometricObject(String color, boolean filled, Date dateCreated, double area, double perimeter) {
this.color = color;
this.filled = filled;
this.dateCreated = dateCreated;
this.area = area;
this.perimeter = perimeter;
}
public String getColor() {
return color;
}
public boolean isFilled() {
return filled;
}
public Date getDateCreated() {
return dateCreated;
}
public double getArea() {
return area;
}
public double getPerimeter() {
return perimeter;
}
public void setColor(String color) {
this.color = color;
}
public void setFilled(boolean filled) {
this.filled = filled;
}
public void setDateCreated(Date dateCreated) {
this.dateCreated = dateCreated;
}
public void setArea(double area) {
this.area = area;
}
public void setPerimeter(double perimeter) {
this.perimeter = perimeter;
}
}
![Đỗ Mạc Nam [T2008A]](https://www.gravatar.com/avatar/71dd707204cf6115a4fe17bbdee2b5fa.jpg?s=80&d=mm&r=g)
Đỗ Mạc Nam
2021-03-05 08:43: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 exam1;
/**
*
* @author mac
*/
public class Rectangle extends GeometricObject{
//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);
}
}
![Đỗ Mạc Nam [T2008A]](https://www.gravatar.com/avatar/71dd707204cf6115a4fe17bbdee2b5fa.jpg?s=80&d=mm&r=g)
Đỗ Mạc Nam
2021-03-05 08:42:32
/*
* 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 mac
*/
public class Circle extends GeometricObject {
//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);
}
}
![Đỗ Mạc Nam [T2008A]](https://www.gravatar.com/avatar/71dd707204cf6115a4fe17bbdee2b5fa.jpg?s=80&d=mm&r=g)
Đỗ Mạc Nam
2021-03-05 08:41:55
/*
* 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 mac
*/
public class Rectangle {
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;
}
}
![Đỗ Mạc Nam [T2008A]](https://www.gravatar.com/avatar/71dd707204cf6115a4fe17bbdee2b5fa.jpg?s=80&d=mm&r=g)
Đỗ Mạc Nam
2021-03-05 08:41:10
/*
* 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 exem1;
/**
*
* @author mac
*/
public class GeometricObject {
//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;
}
}
![Nguyễn Tiến Đạt [T2008A]](https://www.gravatar.com/avatar/b5819cd0adc95c727c7ad0c2bcf6098b.jpg?s=80&d=mm&r=g)
Nguyễn Tiến Đạt
2021-03-05 08:36:59
#Circle.java
/*
* 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 ExamAptechJavaBasic;
/**
*
* @author MyPC
*/
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
/*
* 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 ExamAptechJavaBasic;
import java.util.Scanner;
/**
*
* @author MyPC
*/
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 info of circle:");
System.out.println("Radius:");
float radius = scan.nextFloat();
circle.radius = radius;
objectList[0] = circle;
while(true){
System.out.println("");
System.out.println("Input info of rectangle:");
System.out.println("Width:");
float width = scan.nextFloat();
System.out.println("Height:");
float height = scan.nextFloat();
System.out.println("");
if( width > height ){
System.out.println("Height must be longer than width!!");
System.out.println("Please try again");
continue;
}
rectangle.width = width;
rectangle.height = height;
objectList[1] = rectangle;
System.out.println("Sum areas of all the geometric objects in an array is: " + sumArea(objectList));
break;
}
}
public static double sumArea(GeometricObject[] a){
double sum = 0;
for (GeometricObject geometricObject : a) {
sum += geometricObject.getArea();
}
return sum;
}
}
#GeometricObject.java
/*
* 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 ExamAptechJavaBasic;
import java.util.Date;
/**
*
* @author MyPC
*/
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
/*
* 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 ExamAptechJavaBasic;
/**
*
* @author MyPC
*/
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);
}
}
![nguyen dinh quan [T2008A]](https://www.gravatar.com/avatar/12423072c0ca04128eb9b68f6cdb773c.jpg?s=80&d=mm&r=g)
nguyen dinh quan
2021-03-05 08:00:45
#ảnh điểmt thực hành.png
https://res.cloudinary.com/wegoup/image/upload/v1614931242/b82jl8cpyejjup876ktf.png
![Đức Sơn [T2008A]](https://www.gravatar.com/avatar/d2b971b7bc54e4a9689c3e2240f27949.jpg?s=80&d=mm&r=g)
Đức Sơn
2021-03-05 07:50:17
#156808455_1135766476844989_5478286330375543139_n.png
https://res.cloudinary.com/wegoup/image/upload/v1614930607/pwlr0bhyktmiq7mfljz2.png
![Vũ Đình Khôi [community,T2008A]](https://www.gravatar.com/avatar/522a3ab049e7409705e97b96dbbc327b.jpg?s=80&d=mm&r=g)
Vũ Đình Khôi
2021-03-05 07:47:36
KQ thi lý thuyết
![bui duy khanh [T2008A]](https://www.gravatar.com/avatar/50b4bb73ad99c982b2c18af8cf07e2a4.jpg?s=80&d=mm&r=g)
bui duy khanh
2021-03-05 07:47:30
lý thuyết