Skip to content
Open
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
15 changes: 15 additions & 0 deletions src/exercises/Lesson1/Area.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package exercises.Lesson1;
import java.util.Scanner;

public class Area {

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter rectangle length in sq ft: ");
Double length = input.nextDouble();
System.out.println("Enter rectangle width in sq ft: ");
Double width = input.nextDouble();
Double area = length * width;
System.out.println("Your rectangle's area is: " + area + " sq ft");
}
}
13 changes: 13 additions & 0 deletions src/exercises/Lesson1/HelloWorld.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package exercises.Lesson1;
import java.util.Scanner;


public class HelloWorld {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("What's your name?");
String name = input.nextLine();
System.out.println("Hello " + name);
}
}

17 changes: 17 additions & 0 deletions src/exercises/Lesson1/MilesPerGallon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package exercises.Lesson1;
import java.util.Scanner;

public class MilesPerGallon {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.println("Enter the number of miles driven: ");
Double milesDriven = input.nextDouble();

System.out.println("Enter the amount of gas consumed (in gallons): ");
Double gasConsumed = input.nextDouble();

Double milesPerGallon = milesDriven/gasConsumed;
System.out.println("You are running on " + milesPerGallon + " mpg.");

}
}
22 changes: 22 additions & 0 deletions src/exercises/Lesson1/StringSearch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package exercises.Lesson1;
import java.util.Locale;
import java.util.Scanner;

public class StringSearch {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
String sentence = "Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, 'and what is the use of a book,' thought Alice 'without pictures or conversation?'";

System.out.println("Enter your search term: ");
String searchTerm = input.nextLine().toLowerCase();

boolean contains = sentence.toLowerCase().contains(searchTerm);
System.out.println("The results of your search are " + contains);

System.out.println("The index of your search term is " + sentence.indexOf(searchTerm) + " and its length is " + searchTerm.length());

String newSentence = sentence.toLowerCase().replace(searchTerm, "");
System.out.println(newSentence);

}
}
47 changes: 47 additions & 0 deletions src/exercises/Lesson2/ArrayListPractice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package exercises.Lesson2;

import java.util.Arrays;
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;

public class ArrayListPractice {
/*Exercise 1*/
public static int evenSum(ArrayList<Integer> arr) {
int sum = 0;
for (int number : arr) {
if (number % 2 == 0) {
sum += number;
}
}
return sum;
}

/*Exercise 2 + 3*/
public static void printLetters(ArrayList<String> arr) {
Scanner input = new Scanner(System.in);
System.out.println("Enter number of letters: ");
int numOfLetters = input.nextInt();
for (String word : arr) {
if (word.length() == numOfLetters) {
System.out.println(word);
}
}
}

public static void main(String[] args) {
ArrayList<Integer> values = new ArrayList<>();
for (int i = 0; i < 10; i++) {
values.add(i);
}

/*BONUS Exercise 3*/
String sentence = "I would not, could not, in a box. I would not, could not with a fox. I will not eat them in a house. I will not eat them with a mouse.";
sentence = sentence.replace(",", "");
sentence = sentence.replace(".", "");
String[] sentenceSplit = sentence.split(" ");
ArrayList<String> wordsArrList = new ArrayList<>(
Arrays.asList(sentenceSplit));
printLetters(wordsArrList);
}
}
25 changes: 25 additions & 0 deletions src/exercises/Lesson2/ArrayPractice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package exercises.Lesson2;

import java.util.Arrays;

public class ArrayPractice {
public static void main (String[] args){
/* Exercise 1 */
int[] values = {1,1,2,3,5,8};

/* Exercise 2 */
for (int value: values){
System.out.println(value);
}
/* Exercise 3 */
String sentence = "I would not, could not, in a box. I would not, could not with a fox. I will not eat them in a house. I will not eat them with a mouse.";
String[] splitSentence = sentence.split(" ");
/* Exercise 4 */
System.out.println(Arrays.toString(splitSentence));
/* Exercise 5 */
String[] sentences = sentence.split("\\.");
System.out.println(Arrays.toString(sentences));


}
}
35 changes: 35 additions & 0 deletions src/exercises/Lesson2/HashMapPractice.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package exercises.Lesson2;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class HashMapPractice {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
HashMap<Integer, String> studentRoster = new HashMap<>();
String newStudent = "";
do {
System.out.print("Student: ");
newStudent = input.nextLine();

if (!newStudent.equals("")) {
System.out.print("ID: ");
Integer newID = input.nextInt();
studentRoster.put(newID, newStudent);

input.nextLine();
}
} while(!newStudent.equals(""));

input.close();

System.out.println("\nClass roster:");

for (Map.Entry<Integer, String> student : studentRoster.entrySet()) {
System.out.println(student.getValue() + "'s ID: " + student.getKey());
}

System.out.println("Number of students in roster: " + studentRoster.size());
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package org.launchcode.java.demos.lsn1datatypes;

import java.util.Scanner;

public class TempConverter {
public static void main(String[] args) {
double fahrenheit;
double celsius;
Scanner input;
java.util.Scanner input;

input = new Scanner(System.in);
input = new java.util.Scanner(System.in);
System.out.println("Enter the temperature in Fahrenheit: ");
fahrenheit = input.nextDouble();
input.close();
Expand Down