Classes and Objects (Exercise 1)

preview_player
Показать описание
Java Programming: Java Exercise on Classes and Objects
Topics Discussed:
1. Implementing a Rectangle Class in Java.
2. Creating an array of 3 Rectangles filled by the user in Java.

Music:
Axol x Alex Skrindo - You [NCS Release]

#JavaByNeso #JavaProgramming #OOP #ClassesAndObjects
Рекомендации по теме
Комментарии
Автор

Dude, you'e an absolute god send, this video summed up everything we learned in the last few videos and for the first time, the whole concept of OOP is starting to make sense to me, thanks a ton!

a.human.
Автор

I have an exam tomorrow and this helped me. Thanks man!

BinkingThig
Автор

Hello I love your teaching, don't you teach javascript?

petrusmoshweulaka
Автор

How to make methods of the last two codes?

brocklesnarufcchamp
Автор

If you don't, Please explain OOPS in C++. Please please

Code_Solver
Автор

Can you help me with this?

Main.java:15: error: no suitable constructor found for Rectangle(double, double)
rectangles[i] = new Rectangle(input.nextDouble(), input.nextDouble());
^
constructor Rectangle.Rectangle(int, int) is not applicable
(argument mismatch; possible lossy conversion from double to int)
constructor Rectangle.Rectangle(Point, Dimension) is not applicable

ryanchristopheredquila
Автор

Sir, Please try to upload the videos faster.

sr-sunny-raj
Автор

what does the key word 'this' mean

calvinclarkjr
Автор

package rectangle;

public class Rectangle {
private double width;
private double height;

public Rectangle() {
this(1, 1);
}

public Rectangle(double width, double height) {
if(width >= 0)
this.width = width;
else
this.width = 1;

if(height >= 0)
this.height = height;
else
this.height = 1;
}

public void setWidth(double width) {
this.width = (width >= 0) ? width : this.width;
}

public double getWidth() {
return width;
}

public void setHeight(double height) {
this.height = (height >= 0) ? height : this.height;
}

public double getHeight() {
return height;
}

public double getArea() {
return width * height;
}

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

suswithcherry
Автор

import rectangle.Rectangle;
import java.util.Scanner;

class Test {

public static void fillTheArray(Rectangle[] arr) {
Scanner input = new Scanner(System.in);

for(int i = 0; i < 3; i++) {
System.out.print("Enter the width of Rectangle " + i + " : ");
double width = input.nextDouble();
System.out.print("Enter the height of Rectangle " + i + " : ");
double height = input.nextDouble();
System.out.println();

arr[i] = new Rectangle(width, height);
}
}

public static void arr) {
for(int i = 0; i < 3; i++) {
Rectangle r1 = arr[i];
System.out.println("Area of Rectangle " + i + " = " + r1.getArea());
System.out.println("Perimeter of Rectangle " + i + " = " + r1.getPerimeter());
System.out.println();
}
}

public static void main(String[] args) {
Rectangle[] arr = new Rectangle[3];
fillTheArray(arr);
System.out.println();
printAreaAndPerimeter(arr);
}
}

suswithcherry
Автор

Sir, your English is from korean?
😆😆😆

surajrenake