Code Monkey home page Code Monkey logo

point-rectangle-design-exercice's Introduction

๐Ÿ”ท Rectangle Drawing Application ๐Ÿ”ท

Welcome to the Rectangle Drawing Application! This project enables users to create intricate drawings composed of multiple rectangles effortlessly. Whether you're an artist ๐ŸŽจ, designer โœ๏ธ, or simply love geometry ๐Ÿ”ท, this application provides a versatile tool to express your creativity.

Table of Contents

Description ๐Ÿ“

The Rectangle Drawing Application simplifies the creation and manipulation of rectangles within a graphical space. It includes meticulously crafted classes to handle various aspects of rectangle management, ensuring seamless creation, modification, and visualization.

Features โœจ

  • Create Drawings: Generate drawings with multiple rectangles to visualize complex layouts.
  • Add Rectangles: Dynamically add rectangles to your drawing with customizable dimensions.
  • Calculate Area: Obtain the total area covered by all rectangles in the drawing with a single click.
  • Calculate the number of objects created: Get insights into the number of objects created in the application.

Exercises ๐Ÿ‹๏ธโ€โ™‚๏ธ


Exercise 2

Description ๐Ÿ“

Implementing encapsulation, write Java code for the Point class. A point is defined by its x and y coordinates (float). The class doesn't define any constructor.

TestPoint Class

  • Create and initialize an object point of type Point to coordinates (5,3).
  • Add 2 to the x-coordinate and 4 to the y-coordinate of point.
  • Display the new coordinates of point.

Exercise 3

Description ๐Ÿ“

  1. Rewrite the Point class from Exercise 2, adding a constructor with two parameters to initialize the point's coordinates.
  2. Using the Point class, define a Rectangle class describing a rectangle by its bottom-left and top-right points. It has two constructors: one with the coordinates of the defining points and the other with two points to initialize the rectangle's attributes.
  3. Write methods to calculate the length, width, and area of the rectangle.
  4. Implement a method to count the total number of Rectangle objects created.

Exercise 4

Description ๐Ÿ“

Consider the Dessin class; a drawing consists of multiple rectangles. The Dessin class contains an array of rectangles, and its size is set by the constructor. A method add(Rectangle r) adds a rectangle r to the drawing, and sum() calculates the total area of the rectangles.

Exercise 5

Description ๐Ÿ“

Enter the following java code and explain the result obtained by executing it.

public class Test {
    public static void main(String[] args) {
        int x = 10;
        int y = 20;
        String s1 = "A";
        String s2 = "B";
        Rectangle p1 = new Rectangle(1, 2);
        Rectangle p2 = new Rectangle(3, 4);
        System.out.println("Before change: " + x + " " + y + " " + s1 + " " + s2 + " " + p1.getLength() + " " + p1.getWidth() + " " + p2.getLength() + " " + p2.getWidth());
        change(x, y, s1, s2, p1, p2);
        System.out.println("After change: " + x + " " + y + " " + s1 + " " + s2 + " " + p1.getLength() + " " + p1.getWidth() + " " + p2.getLength() + " " + p2.getWidth());
    }
    
    public static void change(int a, int b, String n, String m, Rectangle p, Rectangle q) {
        System.out.println("Begin of change: " + a + " " + b + " " + n + " " + m + " " + p.getLength() + " " + p.getWidth() + " " + q.getLength() + " " + q.getWidth());
        a = 30;
        b = 40;
        n = "C";
        m = "D";
        p.setLength(10);
        q = new Rectangle(5, 6);
        System.out.println("End of change: " + a + " " + b + " " + n + " " + m + " " + p.getLength() + " " + p.getWidth() + " " + q.getLength() + " " + q.getWidth());
    }
}

Classes ๐Ÿ“š

Point.java ๐Ÿ”น

The Point class represents a point in a 2D Cartesian coordinate system. It encapsulates the x and y coordinates of the point and provides methods to set and get the coordinates, as well as to add increments to the coordinates.

Rectangle.java ๐ŸŸฉ

The Rectangle class represents a rectangle in a 2D Cartesian coordinate system. It provides methods to calculate the length, width, and area of the rectangle. Additionally, it tracks the number of instances created.

Dessin.java ๐Ÿ–ผ๏ธ && Design.java ๐ŸŽจ

The Dessin and Design classes represent a drawing composed of multiple rectangles. The Design class uses uses an ArrayList to store the rectangles while the Dessin class uses an array to store the rectangles and both provide methods to add rectangles to the drawing and calculate the total area.

TestPoint.java ๐Ÿงช

The TestPoint class is the main program used to test the functionality of the Dessin and Design classes.

Test.java ๐Ÿงช

The Test class demonstrates the behavior of Java method parameter passing by value and reference. Observe how the variables x, y, s1, s2, p1, and p2 change or remain unchanged after the change method is called.

Usage ๐Ÿš€

  1. Clone the Repository: Clone this repository to your local machine using git clone.
  2. Navigate to the Project Directory: Open a terminal and move into the project directory.
  3. Navigate to the Source Directory: Change directory to the src folder.
  4. Compile and Run: Compile and run the TestPoint.java file.
    • Compile: javac *.java
    • Run: java TestPoint
  5. Interact with the Application: Follow the on-screen instructions to create drawings, add rectangles, and calculate the total area.

Tools and Languages ๐Ÿ”ง

  • Java: Primary programming language.
  • IntelliJ IDEA: Integrated Development Environment (IDE).

Execution ๐Ÿ’ป

For the TestPoint.java file:


For the Test.java file:

point-rectangle-design-exercice's People

Contributors

kaoutherbo avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.