changed the file structure

This commit is contained in:
Sage The DM 2024-10-22 09:33:26 +02:00
parent b1c3582880
commit 6b23a757b6
70 changed files with 764 additions and 23 deletions

View file

@ -0,0 +1,7 @@
{
"java.project.sourcePaths": ["src"],
"java.project.outputPath": "bin",
"java.project.referencedLibraries": [
"lib/**/*.jar"
]
}

View file

@ -0,0 +1,18 @@
## Getting Started
Welcome to the VS Code Java world. Here is a guideline to help you get started to write Java code in Visual Studio Code.
## Folder Structure
The workspace contains two folders by default, where:
- `src`: the folder to maintain sources
- `lib`: the folder to maintain dependencies
Meanwhile, the compiled output files will be generated in the `bin` folder by default.
> If you want to customize the folder structure, open `.vscode/settings.json` and update the related settings there.
## Dependency Management
The `JAVA PROJECTS` view allows you to manage your dependencies. More details can be found [here](https://github.com/microsoft/vscode-java-dependency#manage-dependencies).

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1,80 @@
public class Rectangle {
// Private attributes for length and width
private double length;
private double width;
// Constructor with two parameters to initialize the length and width
public Rectangle(double length, double width) {
this.length = length;
this.width = width;
}
// Setter methods
public void setLength(double length) {
this.length = length;
}
public void setWidth(double width) {
this.width = width;
}
public void setSides(double length, double width) {
this.length = length;
this.width = width;
}
// Getter methods
public double getLength() {
return length;
}
public double getWidth() {
return width;
}
// Method to get the longer side
public double getLongerSide() {
return Math.max(length, width);
}
// Method to get the shorter side
public double getShorterSide() {
return Math.min(length, width);
}
// Method to calculate the diagonal of the rectangle
public double getDiagonal() {
return Math.sqrt(length * length + width * width);
}
// Method to calculate the area of the rectangle
public double getArea() {
return length * width;
}
// Method to calculate the perimeter of the rectangle
public double getPerimeter() {
return 2 * (length + width);
}
// Methods to adjust length and width
public void increaseLength(double l) {
length += l;
}
public void increaseWidth(double w) {
width += w;
}
public void decreaseLength(double l) {
length -= l;
if (length < 0)
length = 0; // Ensure length doesn't become negative
}
public void decreaseWidth(double w) {
width -= w;
if (width < 0)
width = 0; // Ensure width doesn't become negative
}
}

Binary file not shown.

View file

@ -0,0 +1,67 @@
import java.util.Scanner;
public class RectangleTest {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Get user input for length and width
System.out.print("Enter the length of the rectangle: ");
double length = scanner.nextDouble();
System.out.print("Enter the width of the rectangle: ");
double width = scanner.nextDouble();
// Create a Rectangle object
Rectangle rectangle = new Rectangle(length, width);
System.out.println("What do you want to do? (1: increase, 2: decrease)");
int input = scanner.nextInt();
if (input == 1) {
// Increase the dimension
System.out.println("Which dimension do you want to increase? (1: width, 2: length)");
input = scanner.nextInt();
if (input == 1) {
// Increase width
System.out.print("Increase width by: ");
double increaseBy = scanner.nextDouble();
rectangle.increaseWidth(increaseBy);
} else if (input == 2) {
// Increase length
System.out.print("Increase length by: ");
double increaseBy = scanner.nextDouble();
rectangle.increaseLength(increaseBy);
} else {
System.out.println("Invalid input for dimension choice.");
}
} else if (input == 2) {
// Decrease the dimension
System.out.println("Which dimension do you want to decrease? (1: width, 2: length)");
input = scanner.nextInt();
if (input == 1) {
// Decrease width
System.out.print("Decrease width by: ");
double decreaseBy = scanner.nextDouble();
rectangle.decreaseWidth(decreaseBy);
} else if (input == 2) {
// Decrease length
System.out.print("Decrease length by: ");
double decreaseBy = scanner.nextDouble();
rectangle.decreaseLength(decreaseBy);
} else {
System.out.println("Invalid input for dimension choice.");
}
} else {
System.out.println("Invalid input for action choice.");
}
// Display the results
System.out.println("Longer side: " + rectangle.getLongerSide());
System.out.println("Shorter side: " + rectangle.getShorterSide());
System.out.println("Diagonal: " + rectangle.getDiagonal());
System.out.println("Area: " + rectangle.getArea());
System.out.println("Perimeter: " + rectangle.getPerimeter());
scanner.close();
}
}