Skip to content

Debugging #24

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

Open
wants to merge 9 commits into
base: debugging
Choose a base branch
from
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
24 changes: 23 additions & 1 deletion classes-part-2/studio/src/main/java/org/launchcode/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,28 @@
public class Main {

public static void main(String[] args) {
// write your code here
MenuItem item1 = new MenuItem("Pepperoni Pizza", "The classic slice, hot and delicious!", 7.39, "main course");
MenuItem item2 = new MenuItem("Toasted Ravioli", "A St. Louis favorite, served with a size of pizza sauce", 6.89, "appetizer");
MenuItem item3 = new MenuItem("Chocolate Cake", "Rich, moist cake with dark chocolate cream cheese frosting", 4.99, "dessert");
MenuItem item4 = new MenuItem("Veggie Pizza", "Peppers, onions, mushrooms, olives, and tomatoes make a delicious combo", 6.39, "main course");
MenuItem item5 = new MenuItem("Garlic Breadsticks", "Hot, garlicky carbs FTW", 4.59, "appetizer");

Menu menu = new Menu();
menu.addItem(item1);
menu.addItem(item2);
menu.addItem(item3);
menu.addItem(item4);
menu.addItem(item5);


System.out.println(menu);

System.out.println(item1);

menu.removeItem(item4);
System.out.println(menu);


menu.removeItem(item4);
}
}
51 changes: 31 additions & 20 deletions classes-part-2/studio/src/main/java/org/launchcode/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,40 @@
import java.util.Date;

public class Menu {
private Date lastUpdated;
private ArrayList<MenuItem> items;

public Menu(Date d, ArrayList<MenuItem> i) {
this.lastUpdated = d;
this.items = i;
}
private ArrayList<MenuItem> menuItems = new ArrayList<>();

public void setLastUpdated(Date lastUpdated) {
this.lastUpdated = lastUpdated;
public ArrayList<MenuItem> getMenuItems() {
return menuItems;
}

public void setItems(ArrayList<MenuItem> items) {
this.items = items;
public String toString() {
StringBuilder appetizers = new StringBuilder();
for (MenuItem item : menuItems) {
if (item.getCategory().equals("appetizer")) {
appetizers.append("\n" + item.toString() + "\n");
}
}
StringBuilder mainCourses = new StringBuilder();
for (MenuItem item : menuItems) {
if (item.getCategory().equals("main course")) {
mainCourses.append("\n" + item.toString() + "\n");
}
}
StringBuilder desserts = new StringBuilder();
for (MenuItem item : menuItems) {
if (item.getCategory().equals("dessert")) {
desserts.append("\n" + item.toString() + "\n");
}
}
return "\nTONY'S PIZZA MENU\n" +
"APPETIZERS" + appetizers.toString() + "\n" +
"MAIN COURSES" + mainCourses.toString() + "\n" +
"DESSERTS" + desserts.toString() + "\n";
}

public Date getLastUpdated() {
return lastUpdated;
void removeItem(MenuItem item) {
menuItems.remove(item);
}

public ArrayList<MenuItem> getItems() {
return items;
void addItem(MenuItem newItem) {
menuItems.add(newItem);
}
}


}
48 changes: 39 additions & 9 deletions classes-part-2/studio/src/main/java/org/launchcode/MenuItem.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,62 @@
package org.launchcode;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
public class MenuItem {
private String name;
private double price;
private String description;
private String category;
private boolean isNew;
private final LocalDate dateAdded;

public MenuItem(double p, String d, String c, boolean iN) {
this.price = p;
this.description = d;
this.category = c;
this.isNew = iN;
public MenuItem(String name, String description, double price, String category) {
this.name = name;
this.price = price;
this.description = description;
this.category = category;
this.dateAdded = LocalDate.now();
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public double getPrice() {
return price;
}

public void setPrice(double price) {
this.price = price;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public String getCategory() {
return category;
}

public void setCategory(String category) {
this.category = category;
}

public void setNew(boolean aNew) {
isNew = aNew;
public LocalDate getDateAdded() {
return dateAdded;
}
public String toString() {
//String newText = isNew() ? " - NEW!" : "";
return name + '\n' +
description + " | $" + price;
}


}

Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.launchcode;
import java.util.ArrayList;

public class ArrayListExample {

public static int sumEvenNumbers(ArrayList<Integer> numbers){
int sum = 0;
for(int num: numbers){
if(num % 2 == 0){
sum += num;
}
}
return sum;
}

public static void main(String[] args){
ArrayList<Integer> numbers = new ArrayList<>();
numbers.add(5);
numbers.add(6);
numbers.add(12);
numbers.add(18);
numbers.add(2);
numbers.add(8);
numbers.add(3);
numbers.add(9);
numbers.add(11);
numbers.add(7);

int ArrayTotal = sumEvenNumbers(numbers);
System.out.println("Sum of Even numbers in ArrayList is " + ArrayTotal + ".");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.launchcode;
import java.util.Scanner;
import java.util.Arrays;
public class Arraypractice {
public static void main(String[] args) {
int[] integerArray = {1, 1, 2, 3, 5, 8};

for (int i = 0; i < integerArray.length; i++) {
if (integerArray[i] % 2 != 0) {
System.out.println(integerArray[i]);
}
}
String phrase = "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[] words = phrase.split(" ");
System.out.println(Arrays.toString(words));


}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.launchcode;

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

public class countingCharacter {
public static void main(String[] args) {
//String phrase = "If the product of two terms is zero then common sense says at least one of the two terms has to be zero to start with. So if you move all the terms over to one side, you can put the quadratics into a form that can be factored allowing that side of the equation to equal zero. Once you’ve done that, it’s pretty straightforward from there.";
Scanner input =new Scanner(System.in);
System.out.println("enter the quote");
String quote =input.nextLine();
char[] charactersInString = quote.toLowerCase().toCharArray();
HashMap<Character,Integer> countingCharacter = new HashMap<>();
for (char letter : charactersInString) {
int count = countingCharacter.containsKey(letter) ? countingCharacter.get(letter) : 0;
countingCharacter.put(letter, count + 1);

}
for (Map.Entry<Character,Integer> character: countingCharacter.entrySet()){
System.out.println(character.getKey() + ":" + character.getValue());
}


}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.launchcode;
import java.util.Scanner;
public class Alice {
public static void main(String[] args) {
String name="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?’";

Scanner scanner = new Scanner(System.in);

System.out.print("Enter a term to search for: ");
String searchTerm = scanner.nextLine().toLowerCase();

boolean found = name.toLowerCase().contains(searchTerm);

System.out.println("Search term found: " + found);

scanner.close();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.launchcode;
import java.util.Scanner;
public class Hello {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Hello, what is your name:");
String name = input.nextLine();
System.out.println("Hello " + name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.launchcode;

import java.util.Scanner;

public class Miles {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);

System.out.println("How many miles have you driven?");
Double numMiles = input.nextDouble();

System.out.println("How much gas did you use? In gallons.");
Double numGallons = input.nextDouble();

Double mpg = numMiles / numGallons;
System.out.println("You are running on " + mpg + " mpg.");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.launchcode;

import java.util.Scanner;
public class Rectangle {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Enter the length of the rectangle");
Integer length =input.nextInt();
System.out.println("Enter the width of the rectangle");
Integer width =input.nextInt();
Integer aoR = length * width;
System.out.println("Area of the Rectagle is" + aoR + "cm");
}
}
12 changes: 12 additions & 0 deletions datatypes/datatypes-studio/src/main/java/org/launchcode/Area.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.launchcode;
import java.util.Scanner;
public class Area {
public static void main(String[] args) {
Scanner input =new Scanner(System.in);
System.out.println("Enter the radius of a circle");
double radius =input.nextFloat();
double areaCircle = Circle.getArea(radius);
System.out.println("Area of a circle " +areaCircle);
input.close();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.launchcode;

public class Circle {
public static Double getArea(Double radius) {
return 3.14 * radius * radius;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package technology;

public class Computer {
private String brand;
private int storage;
private int ramSize;

public Computer(String brand, int storage, int ramSize) {
this.brand = brand;
this.storage = storage;
this.ramSize = ramSize;
}

public void powerOn() {
System.out.println("Computer powered on.");
}

public void powerOff() {
System.out.println("Computer powered off.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package technology;
public class Laptop extends Computer {
private double screenSize;

public Laptop(String brand, int storage, int ramSize, double screenSize) {
super(brand, storage, ramSize);
this.screenSize = screenSize;
}

public void fold() {
System.out.println("Laptop folded.");
}

}

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package technology;

public class SmartPhone extends Computer {
private String cameraResolution;

public SmartPhone(String brand, int storage, int ramSize, String cameraResolution) {
super(brand, storage, ramSize);
this.cameraResolution = cameraResolution;
}

public void takePhoto() {
System.out.println("Photo taken with " + cameraResolution + " camera.");
}

}
Loading