changed the file structure
This commit is contained in:
		
							parent
							
								
									b1c3582880
								
							
						
					
					
						commit
						6b23a757b6
					
				
					 70 changed files with 764 additions and 23 deletions
				
			
		
							
								
								
									
										
											BIN
										
									
								
								Code/Steiner/oopUebung6/src/Rectangle.class
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Code/Steiner/oopUebung6/src/Rectangle.class
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										80
									
								
								Code/Steiner/oopUebung6/src/Rectangle.java
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										80
									
								
								Code/Steiner/oopUebung6/src/Rectangle.java
									
										
									
									
									
										Normal 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 | ||||
|     } | ||||
| } | ||||
							
								
								
									
										
											BIN
										
									
								
								Code/Steiner/oopUebung6/src/RectangleTest.class
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Code/Steiner/oopUebung6/src/RectangleTest.class
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										67
									
								
								Code/Steiner/oopUebung6/src/RectangleTest.java
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										67
									
								
								Code/Steiner/oopUebung6/src/RectangleTest.java
									
										
									
									
									
										Normal 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(); | ||||
|     } | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Sage The DM
						Sage The DM