Skip to content

Lj lesson 06 Pull Request: Created mathematic expression methods and integrated them #243

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

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions lesson_04/ljmcwilliams/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
In this lesson, I explored the differences between Java and JavaScript. Despite their similar names, these languages have distinct features.

- ## Key Differences
- ### Document Preparation:

- Java requires preparation before defining variables and functions.
JavaScript has more flexibility with variable definitions.

- ### User Input:

- In Java, I used the Scanner class to prompt the user for number input.
This required importing Java's Scanner class.
In JavaScript, there is no built-in Scanner class, so I used Node.js as a workaround.
With Node.js, I utilized process.stdin for input and process.stdout for output (similar to console.log).

- ### Loop Control:

- Both languages allow for loops to be exited early, but the methods differ:
In Java, using a break statement within the loop will terminate it.
In JavaScript, I opted for read.close(), which achieves a similar effect.

- ### Variable Declaration:

- Java requires explicit declaration of variable types.
JavaScript automatically assigns variable types.
- ## Loop Behavior
Both languages share similarities in loop functionality:

- **For Loops**:
- Take three expressions.

- **If Statements**:
- Accept a condition and can be nested.

- **Java Example**
```java
for (int i = 2; i < userInput; i++) {
if ((userInput / i) == (int) (userInput / i)) {
System.out.println(userInput + " is not a prime number.");
isConditionMet = true;
break;
}
} if (!isConditionMet) {
System.out.println(userInput + " is a prime number.");
}
```
- **JavaScript Example**
```javascript
for (let i = 2; i < answer; i++) {
if ((answer / i) == parseInt(answer / i)) {
console.log(answer + " is not a prime number.");
isConditionMet = true;
read.close();
}
} if (!isConditionMet) {
console.log(answer + " is a prime number.");
read.close();
}
```
32 changes: 32 additions & 0 deletions lesson_04/ljmcwilliams/findPrimeNum.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import java.util.Scanner; //This allows us to use the scanner to take in user input
public class findPrimeNum {
public static void main(String[] args) {
Scanner objScanner = new Scanner(System.in); //A scanner named 'objScanner'
boolean isConditionMet = false;

/*if the condition is met, the print statement within the loop will be printed.
If not, the print statement after the loop will be printed*/

System.out.print("Please enter a whole number: "); //User input prompt
double userInput = objScanner.nextDouble(); //This reads an integer value from the user

/*to determine a number's primality, we can check to see if the division
of that number by 2 to (1 - that number) results in any whole number quotients.
Once we do the division we can compare that number to (int) number to see if the
values are equal.*/

/*the program should end if A: the first whole number quotient is found, indicating that
* indicating a number is not prime or if B: no whole number quotients are found within the
* range indicating the number IS prime.*/

for (int i = 2; i < userInput; i++) {
if ((userInput / i) == (int) (userInput / i)) {
System.out.println(userInput + " is not a prime number.");
isConditionMet = true;
break; //this helps jump out of the loop once this first whole number quotient instace is found
}
} if (!isConditionMet) {
System.out.println(userInput + " is a prime number.");
}
}
}
21 changes: 21 additions & 0 deletions lesson_04/ljmcwilliams/findPrimeNum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const readline = require('readline'); //"require()" imports the readline module which will process the user input
const read = readline.createInterface({
input: process.stdin, //this acts as an input scanner
output: process.stdout //this works like a normal console.log combined with a user's input
});
let isConditionMet = false;

/* When looking at the Node.js docs, it states '.question()' displays the query (in this case the user prompt).
It waits for an input and uses it as the first argument in a callback function (here I am using a arrow function). */
read.question("Enter a number: ", (answer) => {
for (let i = 2; i < answer; i++) {
if ((answer / i) == parseInt(answer / i)) { //similar to the "(int)" statement in java, parseInt converts doubles to ints
console.log(answer + " is not a prime number.");
isConditionMet = true;
read.close(); //this works similar to a break statement in java and ends the program
}
} if (!isConditionMet) {
console.log(answer + " is a prime number.");
read.close();
}
})
84 changes: 84 additions & 0 deletions lesson_05/ljmcwilliams/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
## User Story 1: Offline Learning Mode for Language App
<b>As a</b> language learner,<br><b>I want</b> an offline mode in the language learning app,<br><b>so I</b> can continue learning without an internet connection.

### Acceptance Criteria
<ol>
<li><b>Access to Lessons:</b>
<ul>
<li>Users can download specific lessons and exercises for offline access.</li>
<li>A clear indicator shows which lessons are available for offline use.</li>
</ul>
</li>
<li><b>Content Availability:</b>
<ul>
<li>All downloaded lessons should be fully functional without an internet connection.</li>
<li>Any media (audio, video) within the lessons must be accessible offline.</li>
</ul>
</li>
<li><b>Sync Progress:</b>
<ul>
<li>Users’ progress should sync automatically when the app reconnects to the internet.</li>
<li>Any completed lessons or exercises should be saved and updated in the user’s profile once online.</li>
</ul>
</li>
</ol>

## User Story 2: Receive E-Statements for Bank Account
<b>As a</b> customer,<br><b>I want</b> to receive e-statements for my bank account,<br><b>so I</b> can reduce paper waste.

### Acceptance Criteria
<ol>
<li><b>Customer Information Validation:</b>
<ul>
<li>The system verifies that the customer has a valid and active email address before enabling e-statement delivery.</li>
<li>If the email address is invalid, the system prompts the user to update their information.</li>
</ul>
</li>
<li><b>E-statement Delivery</b>
<ul>
<li>E-statements must be sent to the customer’s registered email address monthly (or according to the account’s statement cycle).</li>
<li>The email subject line should clearly indicate it is a bank statement (e.g., "[Bank Name] - Your Monthly Statement for [Month]").</li>
<li>The e-statement must be attached as a PDF file.
</li>
</ul>
</li>
<li><b>Notification Preferences Management:</b>
<ul>
<li>The customer must be able to modify their email address or opt out of e-statements at any time through the bank's website or mobile app.</li>
<li>Upon opting out, the customer should receive a confirmation message, and the system should revert to sending paper statements.</li>
</ul>
</li>
</ol>

## User Story 3: Keyboard Navigation for Faster Programming
<b>As a</b> software engineer,<br><b>I want</b> to be able to navigate the IDE using keyboard shortcuts,<br><b>so that I</b> can perform actions more quickly.

### Acceptance Criteria
<ol>
<li><b>Shortcut configuration:</b></li>
<ul>
<li>The IDE must provide a default set of keyboard shortcuts for common actions (e.g., opening files, saving files, navigating between files, searching, etc.).</li>
<li>The software engineer must be able to customize keyboard shortcuts through the IDE settings/preferences menu.</li>
<li>There must be an option to reset all keyboard shortcuts to their default settings.</li>
</ul>
<li><b>Common actions support:</b></li>
<ul>
<li>
The following common actions must be accessible via keyboard shortcuts:
<ul>
<li>Opening, closing, and saving files.</li>
<li>Navigating between open tabs or files.</li>
<li>Searching within the file and across the project.</li>
<li>Running and debugging the code.</li>
<li>Copying, pasting, and duplicating lines of code.</li>
<li>Formatting code and applying indentation.</li>
<li>Commenting and uncommenting lines or blocks of code.</li>
</ul>
</li>
</ul>
<li><b>Shortcut discoverability:</b></li>
<ul>
<li>The IDE must provide a way to view all available keyboard shortcuts (e.g., a "Keyboard Shortcuts" menu or help section).</li>
<li>When hovering over action buttons in the IDE interface, the corresponding keyboard shortcut must be displayed in the tooltip.</li>
</ul>
</ol>
20 changes: 10 additions & 10 deletions lesson_05/quiz/src/lesson5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class Lesson5 {
[AnswerChoice.C, "To insert an image"],
[AnswerChoice.D, "To create a paragraph"],
]),
AnswerChoice.UNANSWERED,
AnswerChoice.B,
);
}

Expand All @@ -52,7 +52,7 @@ export class Lesson5 {
[AnswerChoice.C, "alt"],
[AnswerChoice.D, "href"],
]),
AnswerChoice.UNANSWERED,
AnswerChoice.C,
);
}

Expand All @@ -66,7 +66,7 @@ export class Lesson5 {
[AnswerChoice.C, "<div>"],
[AnswerChoice.D, "<link>"],
]),
AnswerChoice.UNANSWERED,
AnswerChoice.B,
);
}

Expand All @@ -80,7 +80,7 @@ export class Lesson5 {
[AnswerChoice.C, "<span>"],
[AnswerChoice.D, "<br>"],
]),
AnswerChoice.UNANSWERED,
AnswerChoice.B,
);
}

Expand All @@ -94,7 +94,7 @@ export class Lesson5 {
[AnswerChoice.C, "Computer Style Sheets"],
[AnswerChoice.D, "Cascading System Sheets"],
]),
AnswerChoice.UNANSWERED,
AnswerChoice.B,
);
}

Expand All @@ -108,7 +108,7 @@ export class Lesson5 {
[AnswerChoice.C, "text-color"],
[AnswerChoice.D, "background-color"],
]),
AnswerChoice.UNANSWERED,
AnswerChoice.B,
);
}

Expand All @@ -122,7 +122,7 @@ export class Lesson5 {
[AnswerChoice.C, "/* this is a comment */"],
[AnswerChoice.D, "<!-- this is a comment -->"],
]),
AnswerChoice.UNANSWERED,
AnswerChoice.C,
);
}

Expand All @@ -136,7 +136,7 @@ export class Lesson5 {
[AnswerChoice.C, "text-size"],
[AnswerChoice.D, "text-style"],
]),
AnswerChoice.UNANSWERED,
AnswerChoice.B,
);
}

Expand All @@ -150,7 +150,7 @@ export class Lesson5 {
[AnswerChoice.C, "inline-block"],
[AnswerChoice.D, "none"],
]),
AnswerChoice.UNANSWERED,
AnswerChoice.B,
);
}

Expand All @@ -164,7 +164,7 @@ export class Lesson5 {
[AnswerChoice.C, "<stylesheet link='styles.css'>"],
[AnswerChoice.D, "<css href='styles.css'>"],
]),
AnswerChoice.UNANSWERED,
AnswerChoice.A,
);
}
}
Expand Down
17 changes: 16 additions & 1 deletion lesson_06/expression/src/expression_calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,25 @@ export class ExpressionCalculator {
/** Returns the calculation of ((a + b) * c) / d^e */
calculate(a: number, b: number, c: number, d: number, e: number): number {
// Implement your code here to return the correct value.
return 0;
const sum = this.add(a, b);
const product = this.multiply(sum, c);
const exp = this.pow(d, e);
const quotient = this.divide(product, exp);
return quotient;
}

pow(base: number, exponent: number): number {
return Math.pow(base, exponent);
}
add(addendA: number, addendB: number): number {
return addendA + addendB;
}
divide(dividend: number, divisor: number): number {
return dividend / divisor;
}
multiply(factorA: number, factorB: number): number {
return factorA * factorB;
}
}

//divide(multiply(add(a, b), c), pow(d, e))