Skip to content
5 changes: 5 additions & 0 deletions src/Records/src/Classroom.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public record Classroom(int grade, Student[] students, int classNum) {



}
32 changes: 24 additions & 8 deletions src/src/Bed.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
public class Bed {

private double height;
private int pillows;
private String SheetsColor;
private String sheetsColor;
private final int price;
private static final int DEFAULT_BED_PRICE = 1000;


public Bed (double height, int pillows, String SheetsColor) {
public Bed (double height, int pillows, String sheetsColor, int price) {
this.height = height;
this.pillows = pillows;
this.SheetsColor = SheetsColor;
this.sheetsColor = sheetsColor;
this.price = price;
}
public Bed (double height, String SheetsColor) {
this.height = height;
this.SheetsColor = SheetsColor;
this.pillows = 1;

public Bed (double height, String sheetsColor) {
this(height,1,sheetsColor,DEFAULT_BED_PRICE);
}

public int getPrice() {
return price;
}
public double getHeight() {
return height;
Expand All @@ -20,6 +28,14 @@ public int getPillows() {
return pillows;
}
public String getSheetsColor() {
return SheetsColor;
return sheetsColor;
}
public void setSheetsColor(String sheetsColor) {
this.sheetsColor = sheetsColor;
}
public static int getDefaultBedPrice() {
return DEFAULT_BED_PRICE;
}

}

35 changes: 35 additions & 0 deletions src/src/Closet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
public class Closet {

private Shirt[] shirts;

public Closet(Shirt[] Shirts) {
this.shirts = Shirts;
}

public Shirt[] getShirts() {
return shirts;
}

public Shirt[] getShirtsBySize(Shirt[] shirts, int size) {
int arrSize = 0;
for (int i = 0; i < shirts.length; i++) {
if (shirts[i].getSize() == size) {
arrSize++;
}
}
int index = 0;
Shirt[] shirtsBySize = new Shirt[arrSize];
for (int i = 0; i < shirts.length; i++) {
if (shirts[i].getSize() == size) {
shirtsBySize[index] = shirts[i];
index++;
}
}
return shirtsBySize;
}

public void addShirts(Shirt add) {
shirts = Util.addShirt(shirts, add);
}

}
41 changes: 31 additions & 10 deletions src/src/Main.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {

public static void main(String[] args) {
//TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
// to see how IntelliJ IDEA suggests fixing it.
System.out.printf("Hello and welcome!");

for (int i = 1; i <= 5; i++) {
//TIP Press <shortcut actionId="Debug"/> to start debugging your code. We have set one <icon src="AllIcons.Debugger.Db_set_breakpoint"/> breakpoint
// for you, but you can always add more by pressing <shortcut actionId="ToggleLineBreakpoint"/>.
System.out.println("i = " + i);
ex_15();
ex_20();
}

public static void ex_20() {
System.out.println(Util.tolerance(YahliConstants.HIGHEST_PRICE_FOR_BED, Bed.getDefaultBedPrice(),YahliConstants.TOLERANCE_FOR_PRICE_OF_BED));
}

public static void ex_15() {
Shirt[] shirts = new Shirt[10];
Closet closet = new Closet(shirts);
Bed bed = new Bed(10, "Black");
Room r1 = new Room(closet, bed);
bed.setSheetsColor(YahliConstants.FAVORITE_COLOR);

Shirt[] shirtsBySize = closet.getShirtsBySize(shirts, YahliConstants.SHIRT_SIZE);

int count = 0;
int index = 0;
for (int i = 0; i < shirtsBySize.length; i++) {
if (shirtsBySize[i].getColor().equals(YahliConstants.FAVORITE_COLOR)) {
count++;
}
}
Shirt[] shirtsBySizeAndColor = new Shirt[count];
for (int i = 0; i < shirtsBySizeAndColor.length; i++) {
if (shirtsBySize[i].getColor().equals(YahliConstants.FAVORITE_COLOR)) {
shirtsBySizeAndColor[index] = shirtsBySize[i];
}
}
}

}
23 changes: 23 additions & 0 deletions src/src/Room.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
public class Room {

private Closet closet;
private Bed bed;

public Room (Closet closet, Bed bed) {
this.closet = closet;
this.bed = bed;
}

public Room (Bed bed, Shirt[] shirts) {
Closet closet1 = new Closet(shirts);
new Room(closet1, bed);
}
public Closet getCloset() {
return closet;
}

public Bed getBed() {
return bed;
}

}
17 changes: 17 additions & 0 deletions src/src/Shirt.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public class Shirt {

public int size;
public String color;

public Shirt(int size, String color) {
this.size = size;
this.color = color;
}
public int getSize() {
return size;
}
public String getColor() {
return color;
}

}
17 changes: 17 additions & 0 deletions src/src/Util.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public class Util {

protected static Shirt[] addShirt (Shirt[] shirts, Shirt add) {
Shirt[] newShirts = new Shirt[shirts.length + 1];
for (int i = 0; i < shirts.length; i++) {
newShirts[i] = shirts[i];
}
newShirts[shirts.length+1] = add;
return newShirts;
}

protected static boolean tolerance(double wanted, double num, double tolerance) {

return (num >= wanted - tolerance) && (num <= wanted + tolerance);
}

}
8 changes: 8 additions & 0 deletions src/src/YahliConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
public class YahliConstants {

public static final int SHIRT_SIZE = 54;
public static final String FAVORITE_COLOR = "Blue";
public static final double HIGHEST_PRICE_FOR_BED = 2000;
public static final double TOLERANCE_FOR_PRICE_OF_BED = 500;

}