Add files via upload

This commit is contained in:
Aesthetiful authored and GitHub committed 2024-06-13 08:40:42 -07:00
1 parent 49c6374d74
commit 59d556f1b4
6 files changed
+313

No files matched your search

+41
View File
@@ -0,0 +1,41 @@
// Online Java Compiler
// Use this editor to write, compile and run your Java code online
public static class HiddenWord {
private String word;
public HiddenWord(String word) {
this.word = word;
}
public String getHint(String guess) {
String result = "";
for(int i = 0; i < guess.length() - 1; i++) {
String char1 = word.substring(i, i + 1);
String char2 = guess.substring(i, i + 1);
boolean isInWord = false;
for(int j = 0; j < word.length() - 1; j++) {
String char = word.substring(i, i + 1);
if(char.equals(char2)) {
isInWord = true;
}
}
if(char1.equals(char2)) {
result += char2;
} else if(isInWord) {
result += "*";
} else {
result += "+";
}
}
}
}
public class 2015 Practive Exam FRQ {
public static void main(String[] args) {
HiddenWord word = new HiddenWord("HARPS");
System.out.println(word.getHint("HELLO"));
}
}
+169
View File
@@ -0,0 +1,169 @@
//use to not be smart idk dont be completely reer
public int findFreeBlock(int period, int duration) {
// Iterate through each possible start minute in the period
for (int startMinute = 0; startMinute <= 60 - duration; startMinute++) {
boolean blockFound = true;
// Check each minute in the block to see if it is free
for (int minute = startMinute; minute < startMinute + duration; minute++) {
if (!isMinuteFree(period, minute)) {
blockFound = false;
break;
}
}
// If a block is found, return the starting minute of that block
if (blockFound) {
return startMinute;
}
}
// If no suitable block is found, return -1
return -1;
}
public boolean makeAppointment(int startPeriod, int endPeriod, int duration) {
// Iterate through each period from startPeriod to endPeriod
for (int period = startPeriod; period <= endPeriod; period++) {
// Use findFreeBlock to find the first block of free minutes in the current period
int startMinute = findFreeBlock(period, duration);
// If a free block is found, reserve it and return true
if (startMinute != -1) {
reserveBlock(period, startMinute, duration);
return true;
}
}
// If no suitable block is found in any period, return false
return false;
}
public class Sign {
private String message;
private int width;
// Constructor
public Sign(String message, int width) {
this.message = message;
this.width = width;
}
// Method to return the number of lines needed to display the text on the sign
public int numberOfLines() {
if (message.isEmpty()) {
return 0;
}
return (message.length() + width - 1) / width;
}
// Method to return the message broken into lines separated by semicolons
public String getLines() {
if (message.isEmpty()) {
return null;
}
StringBuilder result = new StringBuilder();
int length = message.length();
for (int i = 0; i < length; i += width) {
if (i > 0) {
result.append(";");
}
int end = Math.min(i + width, length);
result.append(message, i, end);
}
return result.toString();
}
public static void main(String[] args) {
// Example usage
Sign sign = new Sign("HelloWorld", 3);
System.out.println(sign.numberOfLines()); // Output: 4
System.out.println(sign.getLines()); // Output: Hel;loW;orl;d
}
}
public void cleanData(double lower, double upper) {
// Create a new list to store valid temperatures
ArrayList<Double> cleanedTemperatures = new ArrayList<>();
// Iterate through the temperatures and add valid temperatures to the new list
for (Double temp : temperatures) {
if (temp >= lower && temp <= upper) {
cleanedTemperatures.add(temp);
}
}
// Replace the original temperatures list with the cleaned list
temperatures = cleanedTemperatures;
}
public int longestHeatWave(double threshold) {
int longest = 0;
int currentLength = 0;
for (Double temp : temperatures) {
if (temp > threshold) {
currentLength++;
if (currentLength > longest) {
longest = currentLength;
}
} else {
// Reset currentLength if the temperature is not above the threshold
if (currentLength >= 2) { // Ensure it was a valid heat wave before resetting
currentLength = 0;
} else {
currentLength = 0;
}
}
}
// In case the heat wave continues till the end of the list
if (currentLength >= 2 && currentLength > longest) {
longest = currentLength;
}
return longest;
}
public boolean moveCandyToFirstRow(int col) {
// Check if the element at row 0 and column col already contains a piece of candy
if (box[0][col] != null) {
return true;
}
// Search the remaining rows in column col for a piece of candy
for (int row = 1; row < box.length; row++) {
if (box[row][col] != null) {
// Move the candy to the first row
box[0][col] = box[row][col];
// Set the previous location to null
box[row][col] = null;
return true;
}
}
// Return false if no candy was found in the specified column
return false;
}
public Candy removeNextByFlavor(String flavor) {
// Traverse the box from the last row to the first row
for (int row = box.length - 1; row >= 0; row--) {
// Traverse each row from left to right
for (int col = 0; col < box[row].length; col++) {
// Check if the current position has a Candy object with the desired flavor
if (box[row][col] != null && box[row][col].getFlavor().equals(flavor)) {
// Remove the candy from the box
Candy removedCandy = box[row][col];
box[row][col] = null;
return removedCandy;
}
}
}
// Return null if no Candy with the desired flavor is found
return null;
}
+40
View File
@@ -0,0 +1,40 @@
import java.util.Random;
public class PasswordGenerator {
private String prefix;
private int generatedCount;
public PasswordGenerator(int num, String prefix) {
this.prefix = prefix;
this.generatedCount = num;
}
public PasswordGenerator(int num) {
this.prefix = "A";
this.generatedCount = num;
}
public String pwGen() {
Random random = new Random();
String password = "";
password += prefix + ".";
for (int i = 0; i < 4; i++) {
password += (int) (Math.random() * 10);
}
generatedCount++;
return password;
}
public int pwCount() {
return generatedCount;
}
public static void main(String[] args) {
PasswordGenerator pw1 = new PasswordGenerator(4, "chs");
System.out.println(pw1.pwCount());
System.out.println(pw1.pwGen());
}
}
+17
View File
@@ -0,0 +1,17 @@
public class Drink {
String name;
double price;
public Drink(String name, double price) {
this.name = name;
this.price = price;
}
String getName() {
return name;
}
double getPrice() {
return price;
}
}
+17
View File
@@ -0,0 +1,17 @@
public class Salad {
String name;
double price;
public Salad(String name, double price) {
this.name = name;
this.price = price;
}
String getName() {
return name;
}
double getPrice() {
return price;
}
}
+29
View File
@@ -0,0 +1,29 @@
public class Trio {
private Sandwich sandwich;
private Salad salad;
private Drink drink;
public Trio(Sandwich sandwich, Salad salad, Drink drink) {
this.sandwich = sandwich;
this.salad = salad;
this.drink = drink;
}
String getName() {
return sandwich.getName() + "/" + salad.getName() + "/" + drink.getName() + " Trio";
}
double getPrice() {
double sandwichPrice = sandwich.getPrice();
double saladPrice = salad.getPrice();
double drinkPrice = drink.getPrice();
if(sandwichPrice < saladPrice && sandwichPrice < drinkPrice) {
return saladPrice + drinkPrice;
} else if(saladPrice < sandwichPrice && saladPrice < drinkPrice) {
return sandwichPrice + drinkPrice;
} else {
return sandwichPrice + saladPrice;
}
}
}