TEE-CSA / TEE-Frontend

Apache License 2.0
0 stars 0 forks source link

Coding Progress on CSA Mini Project 12/1 #5

Open Emaad-Mir opened 11 months ago

Emaad-Mir commented 11 months ago

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:

image

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:

image

Tay's commits:

image

Here are the commits that I did:

Ethan's commits:

image

image

Backend

Emaad's commits:

image

Some of the key commits Emaad made to the backend include:

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:

image

Here are some screenshots of my code:

image

What I worked on in backend:

To Do:

Ethan's commits:

image

@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;
        }
    } 
F1nnC commented 11 months ago

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.