By GokiSoft.com| 19:42 06/05/2024|
Java Basic

[Examination] ADF1 - Java Basic - T2008A



Phản hồi từ học viên

5

(Dựa trên đánh giá ngày hôm nay)

GokiSoft.com [Teacher]
GokiSoft.com

2021-07-27 11:56:16


#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 lesson09.bt2204;

/**
 *
 * @author Diep.Tran
 */
public class Rectangle extends GeometricObject{
    double width;
    double 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);
    }
    
}


#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 lesson09.bt2204;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * @author Diep.Tran
 */
public abstract class GeometricObject {
    String color;
    boolean filled;
    Date dateCreated;

    public 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;
    }

    public void setDateCreated(Date dateCreated) {
        this.dateCreated = dateCreated;
    }

    @Override
    public String toString() {
        return "GeometricObject{" + "color=" + color + ", filled=" + filled + ", dateCreated=" + convertDateToString() + '}';
    }
    
    public String convertDateToString() {
        SimpleDateFormat format = new SimpleDateFormat("dd/mm/yyyy");
        return format.format(dateCreated);
    }
    
    public abstract double getArea();
    
    public abstract double getPerimeter();
}


#Driver.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 lesson09.bt2204;

/**
 *
 * @author Diep.Tran
 */
public class Driver {
    public static void main(String[] args) {
        Circle circle = new Circle(12.5f);
        Rectangle rectangle = new Rectangle(3.6f, 10.6f);
        
        GeometricObject[] list = new GeometricObject[2];
        list[0] = circle;
        list[1] = rectangle;
        
        double total = sumArea(list);
        
        System.out.println("Tong dien tich = " + total);
    }
    
    public static double sumArea(GeometricObject[] list) {
        double total = 0;
        
        for (GeometricObject obj : list) {
            total += obj.getArea();
        }
        
        return total;
    }
}


#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 lesson09.bt2204;

/**
 *
 * @author Diep.Tran
 */
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;
    }
    
    @Override
    public double getArea() {
        return Math.PI * radius * radius;
    }

    @Override
    public double getPerimeter() {
        return getDiameter() * Math.PI;
    }
    
    public double getDiameter() {
        return 2 * radius;
    }
}



Võ Như Việt [C2010L]
Võ Như Việt

2021-07-25 15:02:42


#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 Exam;

import java.util.Date;
import java.util.Scanner;

/**
 *
 * @author ADMIN
 */
public class Circle extends GeometricObject{
    final double PI = 3.14;
    double radius;

    public Circle() {
    } 
    
    public Circle(double radius) {
        this.radius = radius;
    }


    public double getRadius() {
        return radius;
    }

    public void setRadius(double radius) {
        this.radius = radius;
    }
    
    double getDiameter(){
        double diameter = radius * 2;
        return diameter;
    }
    
    public void input(){
        Scanner scan = new Scanner(System.in);
        
        System.out.println("Circle radius: ");
        radius = Double.parseDouble(scan.nextLine());
       
    }
    

    @Override
     double getArea() {
        double Areaofcircle = radius * radius * Math.PI;
        return Areaofcircle;
    }

    @Override
     double getPerimeter() {
         double Perimeterofcircle = getDiameter() * Math.PI;
         return Perimeterofcircle;
    }
}


#Driver.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 Exam;

import java.util.ArrayList;
import java.util.Scanner;

/**
 *
 * @author ADMIN
 */
public class Driver {
    
    public static double sumArea(GeometricObject[] a){
      double sum = 0;
        for (int i = 0; i < a.length; i++) {
            sum += a[i].getArea();
        
        }return sum;
    
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        Circle c = new Circle();
        Rectangle r = new Rectangle();
        
        GeometricObject[] array = new GeometricObject[2];
        c.input();
        array[0] = new Circle();
        array[0] = c;
        System.out.println(c.getArea());
        
        r.input();
        array[1] = new Rectangle();
        array[1] = r;
        System.out.println(r.getArea());
       
     System.out.println("\nTotal area of elements in array = " + sumArea(array));
    
       
    }
    
}


#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 Exam;
import java.util.Date;
import java.util.Scanner;

/**
 *
 * @author ADMIN
 */
public abstract class GeometricObject {
    String color;
    boolean filled;
    Date dataCreated;
    

    public GeometricObject() {
        filled = true;
    }

    public GeometricObject(String color, boolean filled, Date dataCreated) {
        this.color = color;
        this.filled = filled;
        this.dataCreated = dataCreated;
    }

    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 getDataCreated() {
        return dataCreated;
    }

    public void setDataCreated(Date dataCreated) {
        this.dataCreated = dataCreated;
    }
    
    abstract double getArea();
    
    
    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 Exam;

import java.util.Date;
import java.util.Scanner;

/**
 *
 * @author ADMIN
 */
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;
    }
    
   
    public void input(){
        Scanner scan = new Scanner(System.in);
        System.out.println("Nhap chieu rong: ");
        width = Double.parseDouble(scan.nextLine());
        
        System.out.println("Nhap chieu cao: ");
        height = Double.parseDouble(scan.nextLine());
        
    }
    
    
    @Override
     double getArea() {
       double Areaofrectangle = width * height;
       return Areaofrectangle;
    }

    @Override
    double getPerimeter() {
         double Perimeterofrectangle = 2 * (width * height);
       return Perimeterofrectangle;
    }
}



Chu Quốc Việt [community,C2010L]
Chu Quốc Việt

2021-07-25 09:50:50


#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 com.mycompany.exam;

import java.util.Scanner;

/**
 *
 * @author ADMIN
 */
public class Circle extends GeometricObject {
    double radius;
    double Diameter;
    final float PI=3.14f;
    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 Diameter;
    }
    
    
    
    @Override
    double getArea(){
        return radius*radius*PI ;
    }

    @Override
    double getPerimeter() {
        return Diameter*PI;
    }
    @Override
    public void input(){
        Scanner scan = new Scanner(System.in);
        System.out.println("Radius :");
        radius = scan.nextDouble();
        System.out.println("Diameter :");
        Diameter = scan.nextDouble();
    }

    @Override
    public String toString() {
        return "Circle{" + "radius=" + radius + ", Diameter=" + Diameter + ", PI=" + PI + '}';
    }
    
}


#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 com.mycompany.exam;

import java.util.Date;
import java.util.Scanner;

/**
 *
 * @author ADMIN
 */
public abstract class GeometricObject {

    String color;
    boolean filled;
    java.util.Date dateCreate;

    public GeometricObject() {
    }

    public GeometricObject(String color, boolean filled, Date dateCreate) {
        this.color = color;
        this.filled = filled;
        this.dateCreate = dateCreate;
    }

    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 getDateCreate() {
        return dateCreate;
    }

    public void setDateCreate(Date dateCreate) {
        this.dateCreate = dateCreate;
    }

      abstract double getArea() ;
      abstract double getPerimeter();
     public void input(){
         Scanner scan = new Scanner(System.in);
         System.out.println("Nhap Color");
         color = scan.nextLine();
         System.out.println("Nhap Filled");
         filled = scan.nextBoolean();

     }
     public String display(){
         System.out.println("Color : " + color +" Filled" + filled);
        return null;
     }

    void input(Scanner in) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
}


#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 com.mycompany.exam;

import java.util.Scanner;

/**
 *
 * @author ADMIN
 */
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
    double getArea() {
        return width*height;
    }

    @Override
    double getPerimeter() {
        return 2*(width+height);
    }
    @Override
    public void input(){
        Scanner scan = new Scanner(System.in);
        System.out.println("Width");
        width = scan.nextDouble();
        System.out.println("Height");
        height = scan.nextDouble();
    }

    @Override
    public String toString() {
        return "Rectangle{" + "width=" + width + ", height=" + height + '}';
    }
    
}


#Tesst.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 com.mycompany.exam;

import java.util.Scanner;

/**
 *
 * @author ADMIN
 */
public class Tesst {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Circle circle = new Circle();
        Rectangle rectangle = new Rectangle();
        Scanner scan = new Scanner(System.in);
        int choice;
        do {
            showmenu();
            choice = scan.nextInt();
            switch (choice) {
                case 1:
                    circle.input();
                    break;
                case 2:
                    System.out.println("Chu Vi" + circle.getArea());
                    break;
                case 3:
                    System.out.println("Dien tich" + circle.getPerimeter());
                    break;
                case 4:
                    rectangle.input();
                    break;
                case 5:
                    System.out.println("Chu vi hcn :" + rectangle.getArea());
                    break;
                case 6:
                    System.out.println("dien tich hcn :" + rectangle.getPerimeter());
                    break;
                case 7:
                    System.out.println("Thoat !!!!");
                    break;
                default:
                      System.out.println("Vui Long nhap lai!!");
                            break;
            }

        } while (choice != 7);

    }

    static void showmenu() {
        System.out.println("1: Nhap thong tin hinh tron");
        System.out.println("2: Tinh chu vi hinh tron");
        System.out.println("3: Tinh dien tich hinh tron");
        System.out.println("4: Nhap thong tin hinh chu nhat");
        System.out.println("5: Tinh chu vi hinh chu nhat ");
        System.out.println("6: Tinh dien tich hinh chu nhat");
        System.out.println("7: Thoat");
    }
}



Vũ Ngọc Văn [community,C2010L]
Vũ Ngọc Văn

2021-07-24 15:17:42


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 jv0724_test;

import java.util.Date;

/**
 *
 * @author ASUS
 */
public abstract class GeometricObject {
    String color;
    boolean filled;
    Date dateCreated;

    protected GeometricObject() {
    }

    public GeometricObject(String color, boolean filled, Date dateCreated) {
        this.color = color;
        this.filled = filled;
        this.dateCreated = dateCreated;
    }

    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;
    }

    public void setDateCreated(Date dateCreated) {
        this.dateCreated = dateCreated;
    }
    
    abstract double getArea();
}
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 jv0724_test;

import java.util.Scanner;

/**
 *
 * @author ASUS
 */
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(){
        double diameter;
        return diameter = radius*2;
    }
    
    public void input(){
        Scanner scan = new Scanner(System.in);
        
        System.out.println("Circle RADIUS:");
        radius = scan.nextDouble();
    }
    
    @Override
    public double getArea(){
        double area = radius * radius * Math.PI;
        return area;
    }
}
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 jv0724_test;

import java.util.Scanner;

/**
 *
 * @author ASUS
 */
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;
    }
    
    public void input(){
        Scanner scan = new Scanner(System.in);
        
        System.out.println("Rectangle WIDTH:");
        width = scan.nextDouble();
        
        System.out.println("Rectangle HEIGHT:");
        height = scan.nextDouble();
    }
    
    public void display(){
        double recArea = width * height;
        System.out.println("The Circle has area of " + recArea);
    }
    
    @Override
    public double getArea(){
        double area = width * height;
        return area;
    }
}
Driver.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 jv0724_test;

import java.util.ArrayList;

/**
 *
 * @author ASUS
 */
public class Driver {
       
//    public static void sumArea(GeometricObject[] object){
//        double totalArea = 0;
//        for (GeometricObject item : object){
//            double area = item.getArea();
//            totalArea += area;
//        }
//    }
    
    
    public static void main(String[] args) {
        ArrayList<GeometricObject> object = new ArrayList<>();
        
        System.out.println("====== INPUT DATA FOR CIRCLE ======");
        Circle circle = new Circle();
        circle.input();
        object.add(circle);
        System.out.println();
        
        System.out.println("====== INPUT DATA FOR RECTANGLE ======");
        Rectangle rec = new Rectangle();
        rec.input();
        object.add(rec);
        System.out.println();

        
        double sumArea = 0;
        for (GeometricObject value : object){
//            System.out.println(value.getArea());
            sumArea += value.getArea();
        }

        System.out.println("====== RESULT ======");
        System.out.println("Total area of two objects is: " + sumArea);

    }
}



Đỗ Phan Hà [community,C2010L]
Đỗ Phan Hà

2021-07-24 14:56:34

#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 javabuoi8.aptech;

import static java.lang.Math.PI;

/**
 *
 * @author ZZoukertic
 */
public class Circle extends GeometricObject{
    private 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 2*radius;
    }
    @Override
    public double getPerimeter(){
        return getDiameter()*PI;
    }
    @Override
    public double getArea(){
        return radius*radius*PI;
    }
    
}


#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 javabuoi8.aptech;
/**
 *
 * @author ZZoukertic
 */
public abstract class GeometricObject {
    private String color;
    private boolean filled;
    private 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 java.util.Date getDateCreated(){
        return dateCreated;
    }
    @Override
    public String toString(){
        return getClass().getName();
    }
    public abstract double getArea();
    public abstract double getPerimeter();
}


#main.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 javabuoi8.aptech;
import java.util.Scanner;
/**
 *
 * @author ZZoukertic
 */
public class main {


    public static double sumArea(GeometricObject[] a){
        int sum = 0;
        for (int i = 0; i < 2; i++){
            sum += a[i].getArea();
        }
        return sum;
    }
    
    public static void main(String[] args) {
        GeometricObject[] objects = new GeometricObject[2];
        Scanner sc = new Scanner(System.in);
        objects[0] = new Rectangle(3.5, 6.2) {};
        objects[1] = new Circle(5.2);
        System.out.println("Sum of Area is " + sumArea(objects));
        for (int i = 0; i < 2; i++){
            System.out.println("Area of objects[" + i + "]: " + objects[i].getArea());
            System.out.println("Perimeter of objects[" + i + "]: " + objects[i].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 javabuoi8.aptech;

/**
 *
 * @author ZZoukertic
 */
public class Rectangle extends GeometricObject {
    private double width;
    private double 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);
    }
}



Đào Mạnh Dũng [C2010L]
Đào Mạnh Dũng

2021-07-24 14:09:28


#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 thi;

/**
 *
 * @author Đào Dũng
 */
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 Math.PI*getdiameter();
    
    }
}


#Driver.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 thi;

import java.io.IOException;
import java.nio.CharBuffer;

/**
 *
 * @author Đào Dũng
 */
public class Driver   {

    /**
     * @param a
     * @return 
     */
    public static double sumArea(GeometricObject[] a) {
        double r = 0;
        for (int i = 0; i < a.length; i++) {
            r+=a[i].getArea();
            
        }
        return r;
    }
    
    public static void main(String[] args) {
        
        GeometricObject a = new Rectangle(4.8,9.3);
        GeometricObject b = new Circle(5.9);
        
        GeometricObject[] c = {a,b};
          
        System.out.println(sumArea(c));
                
    }
     
    
}


#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 thi;

import java.util.Date;

/**
 *
 * @author Đào Dũng
 */
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;
    }

    public void setDateCreated(Date dateCreated) {
        this.dateCreated = 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 thi;

/**
 *
 * @author Đào Dũng
 */
public class Rectangle extends GeometricObject{

    double width;
    double 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 height*width;
        
    }

    @Override
    public double getPerimeter() {
            
        return 2*(height+width);
    
    }
    
}



TRẦN VĂN ĐIỆP [Teacher]
TRẦN VĂN ĐIỆP

2021-03-08 07:43:14


#Test.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 aptech.exam;

/**
 *
 * @author Diep.Tran
 */
public class Test {
    public static void main(String[] args) {
        GeometricObject[] list = new GeometricObject[2];
        
        list[0] = new Circle(6.2);
        list[1] = new Rectangle(5.2, 7.5);
        
        double sum = sumArea(list);
        
        System.out.println("sum: " + sum);
    }
    
    static double sumArea(GeometricObject[] a) {
        double sum = 0;
        for (GeometricObject geometricObject : a) {
            sum += geometricObject.getArea();
        }
        
        return sum;
    }
}


#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 aptech.exam;

/**
 *
 * @author Diep.Tran
 */
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);
    }
}


#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 aptech.exam;

import java.util.Date;

/**
 *
 * @author Diep.Tran
 */
public abstract class GeometricObject {
    String color;
    boolean filled;
    Date createdDate;

    public 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 getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(Date createdDate) {
        this.createdDate = createdDate;
    }

    @Override
    public String toString() {
        return "GeometricObject{" + "color=" + color + ", filled=" + filled + ", createdDate=" + createdDate + '}';
    }
    
    public abstract double getArea();
    
    public abstract double getPerimeter();
}


#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 aptech.exam;

/**
 *
 * @author Diep.Tran
 */
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 2 * radius;
    }

    @Override
    public double getArea() {
        return radius * radius * Math.PI;
    }

    @Override
    public double getPerimeter() {
//        return 2 * radius * Math.PI;
        return getDiameter() * Math.PI;
    }
}



Đỗ Minh Quân [T2008A]
Đỗ Minh Quân

2021-03-05 09:26:40



/*
 * 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 GeometricObject;

import java.util.Date;

/**
 *
 * @author PC
 */
public class geometricobject {
    String color ;
    Boolean filles;
    Date dateCreated;
}

public geometricobject(string color , boolean fillers , date dateCreated){
this color = color ;
this fillers = fillers ;
this date = date ;
}

public string getcolor (){
return color ;
}

public void setcolor(){
this.color = color ;
}
public boolean isfillers(){
return fillers ;
}

public void setfillers (){
this.fillers = filler ;
}

public date getdateCreated (){
return dateCreated;
}
public void setdateCreated(){
this.dateCreated = dateCreated;
}

public static double sumArea(geometricobject){
}


public class circle  extends geometricobject {
	private double radius;
	
	
	public circle(){
	}
	public circle(double radius){
		this.radius = radius;
	}
	public circle(double radius, String color, boolean filled)
	{
		this.radius = radius;
		setColor(color);
		setFilled(filled);
	}
	
	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;
	}
	public void setRadius( double radius)
	{
		this.radius = radius;
	}
	public void printCircle()
	{
		System.out.println("circle" + getDateCreated() + " radius " + radius);
	}
}

public class rectangle extends geometricobject{
 double width;
 double height;
	
 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;
	}
	
	public double getWidth(){
            return width;
	}
	public void setwidth(double width)
	{
		this.width = width;
	}
	public double getHeight()
	{
		return height;
	}
	private void setHeight(double height)
	{
		this.height = height;
	}
	public double getArea()
	{
		return width * height;
	}
	public double getPerimeter(){
		return 2 * (width + height);
	}
}



Nguyễn Anh Vũ [T2008A]
Nguyễn Anh Vũ

2021-03-05 09:23:45



/*
 * 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 Examination;

/**
 *
 * @author NAV
 */
public class Rectangle extends GeometricObject {
     /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
    }
    private double width;
	private double height;
	
	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);
	}
	
	public double getWidth()
	{
		return width;
	}
	public void setWidth(double width)
	{
		this.width = width;
	}
	public double getHeight()
	{
		return height;
	}
	private void setHeight(double height)
	{
		this.height = height;
	}
	public double getArea()
	{
		return width * height;
	}
	public double getPerimeter(){
		return 2 * (width + height);
	}
}



Nguyễn Anh Vũ [T2008A]
Nguyễn Anh Vũ

2021-03-05 09:22:25



/*
 * 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 Examination;

/**
 *
 * @author NAV
 */
public class Circle extends GeometricObject {
     /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
    }
   private double radius;
	public Circle(){
	}
	public Circle(double radius){
		this.radius = radius;
	}
	public Circle(double radius, String color, boolean filled)
	{
		this.radius = radius;
		setColor(color);
		setFilled(filled);
	}
	
	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;
	}
	public void setRadius( double radius)
	{
		this.radius = radius;
	}
	public void printCircle()
	{
		System.out.println("The circle is created " + getDateCreated() + " and the radius is " + radius);
	}
}



Đăng nhập để làm bài kiểm tra

Chưa có kết quả nào trước đó