Skip to content

Java web dev projects #20

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 5 commits into
base: main
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
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package org.launchcode;

public class Main {
public class Main {

public static void main(String[] args) {
// write your code here
public static void main(String[] args) {
MenuItem item1 = new MenuItem(10.99, "Caesar Salad", "Appetizer", true);
MenuItem item2 = new MenuItem(15.99, "Steak Dinner", "Main Course", false);
// Create more menu items as needed...

// Test the methods of your MenuItem class here
item1.printMenuItem();
// You can use other methods to set and get properties as well.
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,61 @@ public class MenuItem {
private String category;
private boolean isNew;

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

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 boolean isNew() {
return isNew;
}

public void setNew(boolean isNew) {
this.isNew = isNew;
}

// Method to determine whether two menu items are equal
public boolean equals(MenuItem other) {
if (this == other) return true;
if (other == null || getClass() != other.getClass()) return false;

if (Double.compare(other.price, price) != 0) return false;
if (isNew != other.isNew) return false;
if (!description.equals(other.description)) return false;
return category.equals(other.category);
}

// Method to print a single menu item
public void printMenuItem() {
System.out.println("Description: " + description);
System.out.println("Category: " + category);
System.out.println("Price: $" + price);
System.out.println("New: " + (isNew ? "Yes" : "No"));
}
}
Submodule collections-exercises added at 7839f5
1 change: 1 addition & 0 deletions control-flow-and-collections/studio/counting-characters
Submodule counting-characters added at 5e963c
11 changes: 11 additions & 0 deletions control-flow-and-collections/studio/studio.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/counting-characters/src/main/java" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.launchcode;

import java.util.Scanner;

public class HelloWorld {
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,4 @@
package org.launchcode;

public class InputOutput {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.launchcode;

import java.util.Scanner;

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

System.out.println("Enter the length of the rectangle:");
double length = input.nextDouble();

System.out.println("Enter the width of the rectangle:");
double width = input.nextDouble();

double area = length * width;

System.out.println("The area of the rectangle is: " + area);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.launchcode;

import java.util.Scanner;

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

String sentence = "Alice was beginning to get very tired...";
System.out.println("Enter a term to search for:");
String searchTerm = input.nextLine();

boolean found = sentence.toLowerCase().contains(searchTerm.toLowerCase());
System.out.println("Search term found: " + found);
}
}

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

import java.util.Scanner;

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

String sentence = "Alice was beginning to get very tired...";
System.out.println("Enter a word to search for:");
String word = input.nextLine();

int index = sentence.toLowerCase().indexOf(word.toLowerCase());
int wordLength = word.length();

if (index != -1) {
System.out.println("Word found at index: " + index);
System.out.println("Word length: " + wordLength);

// Remove the word
String updatedSentence = sentence.substring(0, index) + sentence.substring(index + wordLength);
System.out.println("Updated sentence: " + updatedSentence);
} else {
System.out.println("Word not found in the sentence.");
}
}
}
16 changes: 16 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,16 @@
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 a radius: ");
double radius = input.nextDouble();

double area = Circle.getArea(radius);

System.out.println("The area of a circle of radius " + radius + " is: " + area);
}
}
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,56 @@
package org.launchcode;

public abstract class BaseDisc {

// Fields
//name : Store the name of the disc
private String name;

//Store the storage capacity of the disc
private double storageCapacity;

//Store the data content of the disc
private String contents;

// Constructors
//Initializes the name and storage capacity of the disc and sets the initial contents to an empty string.
//Getters and Setters: Provide access to the fields.
public BaseDisc(String name, double storageCapacity) {
this.name = name;
this.storageCapacity = storageCapacity;
this.contents = "";
}

// Getters and Setters
public String getName() {
return name;
}

public double getStorageCapacity() {
return storageCapacity;
}

public String getContents() {
return contents;
}

public void setContents(String contents) {
this.contents = contents;
}

// Custom Methods
// Represents the common spinning behavior for all optical discs. This method is inherited by both CD and DVD classes but can be overridden.
public void spinDisc() {
// This method can be common for both CD and DVD
System.out.println("A disc spins.");
}

//Represents the common behavior for ejecting a disc
public void ejectDisc() {
// Common method for ejecting a disc
System.out.println("Ejecting the disc.");
}

// An abstract method that forces subclasses (CD and DVD) to provide their own implementation to return information about the disc
public abstract String discInfo();
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,47 @@
package org.launchcode;

public class CD {
// TODO: Implement your custom interface.

// TODO: Determine which fields, methods, and constructors can be extended from the base class and which ones
// need to be declared separately.
//This class extends BaseDisc and implements the OpticalDisc interface. It provides the specific implementation for CDs
public class CD extends BaseDisc implements OpticalDisc {

public CD(String name, double storageCapacity) {
super(name, storageCapacity);
}

//Overrides the spinDisc() method to provide CD-specific spinning behavior.
//Implements the methods defined in the OpticalDisc interface for CD-specific behavior

@Override
public void spinDisc() {
// Override spinDisc() method for CD
System.out.println("A CD spins at a rate of " + CD_MIN_SPIN_SPEED + " - " + CD_MAX_SPIN_SPEED + " rpm.");
}

//Stores data on the CD.
@Override
public void storeData(String data) {
// Implementation specific to CD
setContents(data);
}

//Reads data from the CD.
@Override
public String readData() {
// Implementation specific to CD
return getContents();
}

//Writes data to the CD.
@Override
public void writeData(String data) {
// Implementation specific to CD
setContents(data);
}

//Provides CD-specific information about the disc.
@Override
public String discInfo() {
// Implementation specific to CD
return "CD Name: " + getName() + ", Storage Capacity: " + getStorageCapacity() + " MB";
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,47 @@
package org.launchcode;

public class DVD {
// TODO: Implement your custom interface.

// TODO: Determine which fields, methods, and constructors can be extended from the base class and which ones
// need to be declared separately.
//This class also extends BaseDisc and implements the OpticalDisc interface. It provides the specific implementation for DVDs
public class DVD extends BaseDisc implements OpticalDisc {

public DVD(String name, double storageCapacity) {
super(name, storageCapacity);
}

// method to provide DVD-specific spinning behavior.
//Implements the methods defined in the OpticalDisc interface for DVD-specific behavior
@Override
public void spinDisc() {
// Override spinDisc() method for DVD
System.out.println("A DVD spins at a rate of " + DVD_MIN_SPIN_SPEED + " - " + DVD_MAX_SPIN_SPEED + " rpm.");
}

//Stores data on the DVD
@Override
public void storeData(String data) {
// Implementation specific to DVD
setContents(data);
}

//Reads data from DVD
@Override
public String readData() {
// Implementation specific to DVD
return getContents();
}


//Writes data to the DVD
@Override
public void writeData(String data) {
// Implementation specific to DVD
setContents(data);
}

// Provides DVD specific information about DVD
@Override
public String discInfo() {
// Implementation specific to DVD
return "DVD Name: " + getName() + ", Storage Capacity: " + getStorageCapacity() + " GB";
}
}
Loading