Individual and Team of 3 coding on CSA Mini Project. Areas of emphasis...
Fibonacci - Inheritance and Abstraction
Sorting - Algorithms, Inheritance, Abstraction
Analysis - Calculation and Measurements
Each individual must show role in work. Be prepared to show you personal key commits. Individuals must have Java contributions.
Frontend
Emaad's commits:
Some of the key commits that I made to the frontend include:
Adding text indicating the user's score and the amount they bet
Adding a finish line to very end of the track of all four cars (that also had the word "finish" written on it)
Before, Emaad proposed that we could have a relatively simple design for the track and finish line, but
what we ended up doing was creating a much more aesthetically pleasing design (made by Tay) and merging his track design with Emaad's finish line, which ended up looking like this:
Tay's commits:
Here are the commits that I did:
Designed the track for sorting and fibonacci
Added lanes
Added user input box at the bottom
Added the car images to each lane
Ethan's commits:
My key commits to the frontend include my progress on the movement of the cars and their speed based off of the sorting algorithm each racer represents
The main function makes a GET request to the backend to retrieve the speed of each sort
Backend
Emaad's commits:
Some of the key commits Emaad made to the backend include:
Adding a folder for betting and some sample code for the betting
Adding a button and input box for the user's bet
Adding a method to CarApiController for returning the message the user gets after guessing right or wrong
Here is what some of the code looks like:
// Betting.java
package com.nighthawk.spring_portfolio.mvc.betting;
public class Betting {
private int points;
private String resultMessage;
public Betting(int startingPoints) { // method for the actual Betting with parameter being the number of points the user begins with
this.points = startingPoints;
}
public void placeBet(int betAmount, boolean isGuessCorrect) {
if (betAmount > points) {
System.out.println("Insufficient points to place bet.");
// user cannot bet a number of points greater than the number of points they currently have, ex. can't be 501 points if they have 500 pts
return;
}
if (isGuessCorrect) {
points += betAmount*2;
resultMessage = "Correct guess! You won " + (betAmount * 2) + " points. Current points: " + points;
} else {
points -= betAmount;
resultMessage = "Wrong guess! You lost " + betAmount + " points. Current points: " + points;
}
System.out.println("Current points: " + points);
}
public String getResultMessage(){
return resultMessage;
}
public static void main(String[] args) {
Betting game = new Betting(500); // example call where user starts with 500 points
// Example calls to placeBet method
game.placeBet(150, true);
game.placeBet(200, false);
}
}
function placeBet() {
const betAmount = parseInt(document.getElementById('betAmount').value);
const userPoints = parseInt(document.getElementById('userPointsDisplay').textContent.split(': ')[1]);
// Validate the bet amount
if (isNaN(betAmount) || betAmount <= 0) {
document.getElementById('betMessage').textContent = 'Error: Please enter a positive number.';
return;
}
if (betAmount > userPoints) {
document.getElementById('betMessage').textContent = 'Error: Bet amount exceeds available points.';
return;
}
fetch(`http://localhost:8085/api/sort/bet?algorithm=YOUR_CHOSEN_ALGORITHM&betAmount=${betAmount}&startingPoints=${userPoints}`)
.then(response => response.text())
.then(data => {
document.getElementById('betMessage').textContent = data;
// Update user points based on the response
})
.catch(error => console.error('Error:', error));
}
Tay's commits:
Here are some screenshots of my code:
What I worked on in backend:
Helping make the Car java files (most of them were deleted by Ethan because we realized they were not needed)
Making the fibonacci algorithms and creating the code for the fibonacci backend
To Do:
Add inheritance to the backend
Connect to frontend
Ethan's commits:
@RestController
@RequestMapping("/api/sort")
public class CarApiController {
@GetMapping("/speeds")
public Map<String, Integer> getAlgorithmSpeeds(@RequestParam(required = false) Integer arraySize) {
// Use a fixed array size for testing if not provided by the user
int size = (arraySize != null && arraySize > 0) ? arraySize : 50000;
// generate random array based on the specified size
int[] randomArray = generateRandomArray(size);
// measure sorting speeds for different algorithms
long mergeSortStartTime = System.currentTimeMillis();
// merge sort on the random array
mergeSort(randomArray.clone());
long mergeSortEndTime = System.currentTimeMillis();
int mergeSortSpeed = (int) (mergeSortEndTime - mergeSortStartTime);
long insertionSortStartTime = System.currentTimeMillis();
// insertion sort on the random array
insertionSort(randomArray.clone());
long insertionSortEndTime = System.currentTimeMillis();
int insertionSortSpeed = (int) (insertionSortEndTime - insertionSortStartTime);
long bubbleSortStartTime = System.currentTimeMillis();
// bubble sort on the random array
bubbleSort(randomArray.clone());
long bubbleSortEndTime = System.currentTimeMillis();
int bubbleSortSpeed = (int) (bubbleSortEndTime - bubbleSortStartTime);
long selectionSortStartTime = System.currentTimeMillis();
// selection sort on the random array
selectionSort(randomArray.clone());
long selectionSortEndTime = System.currentTimeMillis();
int selectionSortSpeed = (int) (selectionSortEndTime - selectionSortStartTime);
// algorithm speeds
Map<String, Integer> algorithmSpeeds = new HashMap<>();
algorithmSpeeds.put("mergeSort", mergeSortSpeed);
algorithmSpeeds.put("insertionSort", insertionSortSpeed);
algorithmSpeeds.put("bubbleSort", bubbleSortSpeed);
algorithmSpeeds.put("selectionSort", selectionSortSpeed);
return algorithmSpeeds;
}
private int[] generateRandomArray(int size) {
int[] randomArray = new int[size];
Random random = new Random();
for (int i = 0; i < size; i++) {
randomArray[i] = random.nextInt(100);
}
return randomArray;
}
// sorting algorithms
private void mergeSort(int[] arr) {
Arrays.sort(arr);
}
private void insertionSort(int[] arr) {
int n = arr.length;
for (int i = 1; i < n; ++i) {
int key = arr[i];
int j = i - 1;
while (j >= 0 && arr[j] > key) {
arr[j + 1] = arr[j];
j = j - 1;
}
arr[j + 1] = key;
}
}
private void bubbleSort(int[] arr) {
int n = arr.length;
for (int i = 0; i < n-1; i++) {
for (int j = 0; j < n-i-1; j++) {
if (arr[j] > arr[j+1]) {
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
}
private void selectionSort(int[] arr) {
int n = arr.length;
for (int i = 0; i < n-1; i++) {
int minIdx = i;
for (int j = i+1; j < n; j++) {
if (arr[j] < arr[minIdx]) {
minIdx = j;
}
}
int temp = arr[minIdx];
arr[minIdx] = arr[i];
arr[i] = temp;
}
}
In the backend, I added the sorting algorithms (merge, insertion, bubble, selection)
A GET request can be made through the endpoint /api/sort/speeds in the backend
In the backend, an array of random numbers is created, the amount of numbers in the array will be determined by the user however for now the code utilizes a placeholder as our backend is not deployed
The algorithms each sort the array and their times are recorded, this is used to determine the speed of the racers in the frontend code provided earlier
It looks like ur all doing ur work, I like how u showed ur committed work and highlighted the code. Maybe some more explanation of the code would be good but overall work looks fine.
Individual and Team of 3 coding on CSA Mini Project. Areas of emphasis...
Fibonacci - Inheritance and Abstraction Sorting - Algorithms, Inheritance, Abstraction Analysis - Calculation and Measurements Each individual must show role in work. Be prepared to show you personal key commits. Individuals must have Java contributions.
Frontend
Emaad's commits:
Some of the key commits that I made to the frontend include:
Before, Emaad proposed that we could have a relatively simple design for the track and finish line, but what we ended up doing was creating a much more aesthetically pleasing design (made by Tay) and merging his track design with Emaad's finish line, which ended up looking like this:
Tay's commits:
Here are the commits that I did:
Ethan's commits:
Backend
Emaad's commits:
Some of the key commits Emaad made to the backend include:
Here is what some of the code looks like:
Tay's commits:
Here are some screenshots of my code:
What I worked on in backend:
To Do:
Ethan's commits: