Compare commits

...

5 Commits

10 changed files with 501 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
import java.util.Scanner;
/*
CS2 Challenge Solution
Original Challenge Description: Build a program that requests a user's name,
and then prints a greeting.
*/
public class Main {
public static void main(String[] args) {
//Setup a Scanner to work with System.in
Scanner scan = new Scanner(System.in);
//Start by printing some text that will prompt the user to enter a name
//then print another line that Says "Hello" and then whatever the user entered.
System.out.print("Please enter your name: ");
System.out.println("Hello " + scan.nextLine());
//Close the scanner, while not really necessary, it's a good habit to get into
//for other resources.
scan.close();
}
}

View File

@@ -0,0 +1,92 @@
# 2022 Training - CS2 - Challenge Solution
## Getting started
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
## Add your files
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
```
cd existing_repo
git remote add origin https://gitlab.coldlightalchemist.com/brad95411/2022-training-cs2-challenge-solution.git
git branch -M main
git push -uf origin main
```
## Integrate with your tools
- [ ] [Set up project integrations](https://gitlab.coldlightalchemist.com/brad95411/2022-training-cs2-challenge-solution/-/settings/integrations)
## Collaborate with your team
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Test and Deploy
Use the built-in continuous integration in GitLab.
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
***
# Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
## License
For open source projects, say how it is licensed.
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.

View File

@@ -0,0 +1,38 @@
import java.util.Scanner;
/*
CS3 Challenge Solution
Original Challenge Description: Build a program that requests
three numbers from the user, and performs a math operation on
them and prints the result.
*/
public class Main {
public static void main(String[] args) {
//Start with setting up System.in through a Scanner
Scanner scan = new Scanner(System.in);
//Grab three values from the user, all of them are doubles
System.out.print("Value 1: ");
double firstValue = scan.nextDouble();
System.out.print("Value 2: ");
double secondValue = scan.nextDouble();
System.out.print("Value 3: ");
double thirdValue = scan.nextDouble();
//Print out the operation being performed. Two things of note here,
//the first thing in the println is an empty string, this helps Java to know
//that it's supposed to be combining Strings, not attempting to do regular
//mathematical addition.
//The second thing is that we have the actual math at the end of the println
//statement wrapped in parenthesis. This helps to ensure that Java treats
//that as a math operation, and separates it from all of the combining of Strings
//that is going on outside the parenthesis.
System.out.println("" + firstValue + " / " + secondValue + " - " + thirdValue + " = " + (firstValue / secondValue - thirdValue));
//Close the scanner, because good practice.
scan.close();
}
}

View File

@@ -0,0 +1,92 @@
# 2022 Training - CS3 - Challenge Solution
## Getting started
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
## Add your files
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
```
cd existing_repo
git remote add origin https://gitlab.coldlightalchemist.com/brad95411/2022-training-cs3-challenge-solution.git
git branch -M main
git push -uf origin main
```
## Integrate with your tools
- [ ] [Set up project integrations](https://gitlab.coldlightalchemist.com/brad95411/2022-training-cs3-challenge-solution/-/settings/integrations)
## Collaborate with your team
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Test and Deploy
Use the built-in continuous integration in GitLab.
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
***
# Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
## License
For open source projects, say how it is licensed.
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.

View File

@@ -0,0 +1,43 @@
import java.util.Scanner;
/*
CS4 Challenge Solution
Original Challenge Description: Built a program that requests the user's age,
and return on of the following:
<= 18 - You're a youngin'
> 18 AND <= 35 - The early adult years
> 35 AND <= 55 - Middle aged, time to buy a really expensive car
> 55 AND <= 64 - Getting old...
> 64 - Retirement! Time to live out the golden years.
*/
public class Main {
public static void main(String[] args) {
//Start with setting up System.in through a Scanner
Scanner scan = new Scanner(System.in);
//Request the user's age, as an int
System.out.print("Enter your age: ");
int age = scan.nextInt();
//Close the scanner, because good practice
scan.close();
//This is a larger if statement than what we saw in the demos and for good reason.
//We cover all the different case scenarios here as described in the challenge, but
//notice how I didn't explicitly put an else if statement for > 64 years old condition.
//Because it's the last condition, and we have if's or else if's for the other possible
//conditions, we can put the last possible condition as the "else" statement.
if(age <= 18) { // <= 18
System.out.println("You're a youngin'");
} else if(age > 18 && age <= 35) { // > 18 AND <= 35
System.out.println("The early adult years");
} else if(age > 35 && age <= 55) { // > 35 AND <= 55
System.out.println("Middle aged, time to buy a really expensive car");
} else if(age > 55 && age <= 64) { // > 55 AND <= 64
System.out.println("Getting old...");
} else { // > 64
System.out.println("Retirement! Time to live out the golden years.");
}
}
}

View File

@@ -0,0 +1,52 @@
import java.util.Random;
import java.util.Scanner;
/*
CS5 Challenge Solution
Original Challenge Description: Write a program that requests an integer
from the user, and prints that many random numbers AND prints the sum
and average of those numbers.
*/
public class Main {
public static void main(String[] args) {
//Setup our random number generator and a scanner
//to get input from the user
Random random = new Random();
Scanner scan = new Scanner(System.in);
//Get the number of random numbers the user
//wants us to generate
System.out.print("Number of random values to create: ");
int numberToRandomize = scan.nextInt();
//Close the scanner, we shouldn't need it anymore.
scan.close();
//Create a variable to store the sum of all the numbers
//we're about to generate. Notice that it is a DOUBLE,
//not an int
double sum = 0;
//Setup a for loop, this loop will run for the number
//of random numbers the user requested.
for(int i = 0; i < numberToRandomize; i++) {
//Generate a random number and store it temporarily
double randomNumber = random.nextDouble();
//Properly print the current random number (i + 1),
//along with the number that we actually generated
System.out.println("Random Number " + (i + 1) + ": " + randomNumber);
//Add the current random number to the sum.
//sum += randomNumber is equivalent to sum = sum + randomNumber
sum += randomNumber;
}
//Print the sum, and then print the average.
//The average being the sum divided by the number of numbers
//to randomize requested by the user.
System.out.println("Sum = " + sum);
System.out.println("Average = " + (sum / numberToRandomize));
}
}

View File

@@ -0,0 +1,55 @@
import java.util.Random;
import java.util.Scanner;
/*
CS6 Challenge Solution
Original Challenge Description: Write a program that generates
a random number, and repeatedly asks the user to guess the number,
telling them if they're too low, too high, of if they guess correctly.
The program should end once they guess the correct number.
*/
public class Main {
public static void main(String[] args) {
//Setup our random number generator and a scanner
//to get input from the user
Random random = new Random();
Scanner scan = new Scanner(System.in);
//Generate a random integer 0-100 (inclusive)
int randomValue = random.nextInt(101);
//Create a value for guess and set it to something that
//definitely isn't going to be the random number we just
//generated. We do this because the while loop that we are
//going to use needs to run so long as the guess does not
//equal the random value we generated. If it's something
//we know isn't possible for the random number, then
//we know our loop will run properly at least once.
int guess = -1;
//While the user hasn't guessed the right number
while(randomValue != guess) {
//Ask the user for a number, and overwrite
//the value of guess with that number
System.out.print("Guess the number: ");
guess = scan.nextInt();
//This if statement just checks to see if the user's guess
//is less, more or the same as what the random generated
//number was. If the guess is the same as the random number
//the condition of the while loop will handle getting out
//of the loop, so no need to call break.
if(guess < randomValue) {
System.out.println("You're too low");
} else if(guess > randomValue) {
System.out.println("You're too high");
} else {
System.out.println("You guessed the right number");
}
}
//Close our scanner, for good measure
scan.close();
}
}

View File

@@ -0,0 +1,55 @@
//A class based representation of a ball
public class Ball {
//3 instance variables, the first, diameter,
//stores the diameter of the ball in whatever
//units you want.
//The second, a String representation of the color
//of the ball.
//The third, an integer that stores the number
//of times the ball has been bounced.
private double diameter;
private String color;
private int timesBounced;
//Constructor to create balls with, specifying
//the diameter and color of the ball.
//Note that timesBounced is set to 0,
//this constructor assumes that this is a fresh
//ball that has never been bounced.
public Ball(double newDiameter, String newColor) {
diameter = newDiameter;
color = newColor;
timesBounced = 0;
}
//Returns the current diameter of the ball
public double getDiameter() {
return diameter;
}
//Returns the current color of the ball
public String getColor() {
return color;
}
//Returns the number of times this ball has
//been bounced
public int getTimesBounced() {
return timesBounced;
}
//Bounces the ball, all this does is add
//one to the timesBounced instance variable
public void bounceBall() {
timesBounced++;
}
//A normal toString method, that provides the
//instance information about the Ball that we
//are currently working with as a String
public String toString() {
return "This ball is " + color + " with a diameter of " +
diameter + " and has been bounced " + timesBounced +
" times!";
}
}

View File

@@ -0,0 +1,46 @@
/*
CS7 Challenge Solution
Original Challenge Description:
Write a class Ball with the following:
Characteristics
diameter (double)
color (string)
timesBounced (int)
Behaviors
bounceBall
getDiameter
getColor
getTimesBounced
Create 2 Balls
Ball 1
Diameter: 5
Color: Red
Bounce the ball 10 times
Ball 2
Diameter: 1
Color: Yellow
Bounce the ball 1 time
Print all the values for both balls
*/
public class Main {
public static void main(String[] args) {
//Create two balls, one 5 units in diameter and red,
//and another that's one unit in diameter and yellow
Ball ball1 = new Ball(5, "Red");
Ball ball2 = new Ball(1, "Yellow");
//Using a for loop, bounce ball1 10 times
for(int i = 0; i < 10; i++) {
ball1.bounceBall();
}
//Bounce ball2 once
ball2.bounceBall();
//Print information about both ball1 and ball2
System.out.println(ball1);
System.out.println(ball2);
}
}

5
README.md Normal file
View File

@@ -0,0 +1,5 @@
# 2024 Programming Training Content
Link to videos:
https://youtube.com/playlist?list=PLqXijX9Z0Iz8sZZk0QTXEhc_eTw2-h3Gb&si=YC_YtjYzMWcGyxh6