Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feedback #1

Open
wants to merge 19 commits into
base: feedback
Choose a base branch
from
11 changes: 11 additions & 0 deletions 01-leap-year/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Main {
public static void main(String[] args) {
System.out.println(isLeapYear(2022));
System.out.println(isLeapYear(2020));
System.out.println(isLeapYear(1900));
System.out.println(isLeapYear(2000));
}
public static boolean isLeapYear(double year) {
return year % 4 == 0 && year % 100 == 0 && year % 400 == 0;
}
}
23 changes: 16 additions & 7 deletions 01-leap-year/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,26 @@
2. Label each as either correct or incorrect syntax. If incorrect, rewrite below:
* if (x == y) {

* **YOUR WRITING HERE**
* Correct

* if [x == 10] {

* **YOUR WRITING HERE**
*Incorrect
if (x == 10) {

* if x = 10 then {

* **YOUR WRITING HERE**
*Incorrect
if (x == 10)

* if (x equals 42) {

* **YOUR WRITING HERE**
*Incorrect
if (x == 42) {

* if (x => y) {

* **YOUR WRITING HERE**
*Correct


3. Fix the error in the code below:
Expand All @@ -44,5 +47,11 @@
    System.out.println("Mine, too!");
}
```

* **YOUR WRITING HERE**

* import java.util.Scanner;
Scanner console = new Scanner(System.in);
System.out.print("What is your favorite color?");
String name = console.next();
if (name == "blue") {
System.out.println("Mine, too!")
}
21 changes: 21 additions & 0 deletions 02-fizzbuzz/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Main {
public static void main(String[] args) {
isFizzBuzz();
}
public static void isFizzBuzz () {
for (int i = 0; i < 100; i++) {
if (i % 5 == 0 && i % 3 == 0) {
System.out.println("FizzBuzz");
}
else if (i % 5 == 0) {
System.out.println("Buzz");
}
else if (i % 3 == 0) {
System.out.println("Fizz");
}
else {
System.out.println(i);
}
}
}
}
18 changes: 9 additions & 9 deletions 02-fizzbuzz/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@

| P | Q | P && Q | P \|\| Q |
|:--:|:--:|:------:|:--------:|
| T | T | | |
| T | F | | |
| F | T | | |
| F | F | | |
| T | T | T | T |
| T | F | F | T |
| F | T | F | F |
| F | F | F | F |


2. Prove a version of DeMorgan's Law:

| P | Q | P \|\| Q | ! (P \|\| Q) | !P | !Q | !P && !Q |
|:--:|:--:|:--------:|:------------:|:--:|:--:|:--------:|
| T | T | | | | | |
| T | F | | | | | |
| F | T | | | | | |
| F | F | | | | | |
| T | T | T | F | F | F | F |
| T | F | T | T | F | T | F |
| F | T | T | T | T | F | F |
| F | F | F | T | T | T | T |

3. What does DeMorgan's state and how did you prove it for the case above?
* **YOUR WRITING HERE**
*
10 changes: 10 additions & 0 deletions 03-count-quarters/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Main {
public static void main(String[] args) {
System.out.println(countQuarters(4984));
}
public static String countQuarters(int cents) {
String coin = Integer.toString(cents);
String quarters = coin.substring(coin.length() -2);
return quarters;
}
}
3 changes: 2 additions & 1 deletion 03-count-quarters/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
#### Respond to the following:

1. How do you isolate the ones digit of a number?
* **YOUR WRITING HERE**
* Convert to string, substring the last digit (the length of the integer - 1)
Alternatively, you could % by 10, giving you the remainder, which would be the ones digit.
56 changes: 56 additions & 0 deletions 04-letter-grade/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
class Main {
public static void main(String[] args) {
System.out.println(letterGrade(87));
}
public static String letterGrade(int grade) {
String letter = "";
if (grade >= 90) {
if (grade % 10 >= 7) {
letter = "A+";
}
else if (grade % 10 >= 3 && grade % 10 <= 6) {
letter = "A";
}
else {
letter = "A-";
}
}
else if (grade >= 80 && grade <= 89) {
if (grade % 10 >= 7) {
letter = "B+";
}
else if (grade % 10 >= 3 && grade % 10 <= 6) {
letter = "B";
}
else {
letter = "B-";
}
}
else if (grade >= 70 && grade <= 79) {
if (grade % 10 >= 7) {
letter = "C+";
}
else if (grade % 10 >= 3 && grade % 10 <= 6) {
letter = "C";
}
else {
letter = "C-";
}
}
else if (grade >= 60 && grade <= 69) {
if (grade % 10 >= 7) {
letter = "D+";
}
else if (grade % 10 >= 3 && grade % 10 <= 6) {
letter = "D";
}
else {
letter = "D-";
}
}
else if (grade < 60) {
letter = "F";
}
return letter;
}
}
6 changes: 3 additions & 3 deletions 04-letter-grade/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
* Attach a "+" on their grade if the grade ends in a 7, 8 or 9 (eg: 78 -> C+, 89 -> B+)
* Attach a "-" on their grade if the grade ends in a 0, 1 or 2 (eg: 92 -> A-, 61 -> D-)

* **YOUR WRITING HERE**
* % by 100, then have if statements for + and -


2. Discuss how you would make sure 100 is not misrepresented as an A-.
* **YOUR WRITING HERE**
* Add if (grade = 100), make it return A+


3. Discuss how you would make sure grades that are an F are not mislabeled as F- or F+ (eg: 49 -> F+ and 52 -> F-)
* **YOUR WRITING HERE**
* Add if (grade < 60), make it always return F if the grade is under 60
18 changes: 18 additions & 0 deletions 05-div-by-3/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Main {
public static void main(String[] args) {
System.out.println(divBy3(181));
System.out.println(divBy3(35));
System.out.println(divBy3(0));
System.out.println(divBy3(57));
System.out.println(divBy3(21));
}
public static boolean divBy3 (int number) {
int addition = 0;
String numint = Integer.toString(number); // convert to string
for (int i = 0; i < numint.length(); i++) { // loop number check for string length
char check = numint.charAt(i);
addition += check; // adds all digits
}
return addition % 3 == 0; // returns true or false (true = divisible, false = not divisible)
}
}
12 changes: 9 additions & 3 deletions 05-div-by-3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
1. A number is considered *prime* if its only factors are 1 and itself. For example, 7 is prime (1 and 7 are the only factors) and 9 is not (1, 3 and 9 are factors).
Outline an algorithm to determine whether or not a number is prime.
Think of the following method header:
`public static boolean isPrime(int num)`

* **YOUR WRITING HERE**
public static boolean isPrime(int num) {
if (num % 2 == 0) {
return false;
}
else {
return num % 3 != 0 || num % 5 != 0 || num % 7 != 0 || num % 11 != 0;
}
}
}
27 changes: 25 additions & 2 deletions 06-shapes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,18 @@
000111222333444555666777888999
000111222333444555666777888999
```
* **YOUR WRITING HERE**
* public static String shapeNum(int num) {
String newString = "";
String num2 = Integer.toString(num);
for (int i = 0; i < num2.length();i++) {
for (int j = 0; j < 3; j++) {
String temp = num2.substring(i, i + 1);
newString += temp;
}
}
return newString;
}
}


2. Write a plan for the following output:
Expand All @@ -18,4 +29,16 @@
999998888877777666665555544444333332222211111
999998888877777666665555544444333332222211111
```
* **YOUR WRITING HERE**
(assuming that num = 987654321
* public static String shapeNum(int num) {
String newString = "";
String num2 = Integer.toString(num);
for (int i = 0; i < num2.length();i++) {
for (int j = 0; j < 5; j++) {
String temp = num2.substring(i, i + 1);
newString += temp;
}
}
return newString;
}
}
17 changes: 17 additions & 0 deletions 07-string-puzzles/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//divide word in half
class Main {
public static void main(String[] args) {
firstHalf("WooHoo");
}
public static void firstHalf(String word1) {
if (word1.length() % 2 == 0) {
int length = word1.length();
int div1 = length/2;
String word2 = word1.substring(0, div1);
System.out.println(word2);
}
else {
System.out.print("Not divisible");
}
}
}
15 changes: 15 additions & 0 deletions 07-string-puzzles/Main2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//count hi in string
class Main2 {
public static void main(String[] args) {
System.out.print(countHi("jjdfkjiHI"));
}
public static int countHi(String str) {
int count = 0;
for (int i = 0; i <= str.length() - 2; i++) {
if (str.substring(i, i + 2).equalsIgnoreCase("hi")) {
count++;
}
}
return count;
}
}
19 changes: 19 additions & 0 deletions 07-string-puzzles/Main3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//letterswap
class Main3 {
public static void main(String[] args) {
System.out.println(mysteryMethod("walk", "w", "ch"));
}
public static String mysteryMethod(String s, String r, String a) {
String newString = "";
for (int i = 0; i < s.length(); i++) {
String character = s.substring(i, i + 1);
if (character.equals(r)) {
newString += a;
}
else {
newString += character;
}
}
return newString;
}
}
10 changes: 5 additions & 5 deletions 07-string-puzzles/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@

1. *In your own words*, discuss what each String method does:
* `.substring(a)`
* **YOUR WRITING HERE**
* Gets the characters after index a (for "Test", if a = 2, then its substring will be "st")

* `.substring(a, b)`
* **YOUR WRITING HERE**
* Gets the characters from index a up until index b, excludes b ("Macintosh" and a = 2, b = 5, substring will be "cin)

* `.indexOf(str)`
* **YOUR WRITING HERE**
* Finds the character in a string ("pie" and str = e will be 2)

* `.equals(str)`
* **YOUR WRITING HERE**
* Checks if the string is equivalent to itself ("hello" and "hi" will not be equal, but "a" and "a" will)


2. *In your own words*, discuss what the following `for` loop accomplishes for `String s`:
Expand All @@ -21,4 +21,4 @@ for(int i = 0; i < s.length(); i++) {
// DO STUFF
}
```
* **YOUR WRITING HERE**
* Loops for the length of the string, if the length is 5, it will loop 5 times. This can be used for work on the string used for the loop