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

Java primitives-string #54

Open
wants to merge 6 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
7 changes: 7 additions & 0 deletions exercises/getting-started/com/cbfacademy/HelloWorld.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.cbfacademy;

public class HelloWorld {
public static void main(String... args) {
System.out.println("Hello World!");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,46 @@
public class App {
public static void main(String[] args) {
System.out.println("Hello World!");

// Test arithmetic methods
System.out.println("Addition: " + add(5.5, 3.2)); // Output: 8.7
System.out.println("Subtraction: " + subtract(5.5, 3.2)); // Output: 2.3
System.out.println("Multiplication: " + multiply(5.5, 3.2)); // Output: 17.6

// Test relational methods
System.out.println("Are Equal: " + areEqual(5.5, 5.5)); // Output: true
System.out.println("Is Less Than: " + isLessThan(5.5, 3.2)); // Output: false
System.out.println("Is More Than: " + isMoreThan(5.5, 3.2)); // Output: true

// Test unary operators
int number1 = 12;
int number2 = 12;

System.out.println(number1++); // Output: 12
System.out.println(++number2); // Output: 13
}

public static double add(double operand1, double operand2) {
throw new RuntimeException("Not implemented");
return operand1 + operand2; // Add operand1 and operand2
}

public static double subtract(double operand1, double operand2) {
throw new RuntimeException("Not implemented");
return operand1 - operand2; // Subtract operand2 from operand1
}

public static double multiply(double operand1, double operand2) {
throw new RuntimeException("Not implemented");
return operand1 * operand2; // Multiply operand1 and operand2
}

public static Boolean areEqual(double operand1, double operand2) {
throw new RuntimeException("Not implemented");
return operand1 == operand2; // Check if operand1 is equal to operand2
}

public static Boolean isLessThan(double operand1, double operand2) {
throw new RuntimeException("Not implemented");
return operand1 < operand2; // Check if operand1 is less than operand2
}

public static Boolean isMoreThan(double operand1, double operand2) {
throw new RuntimeException("Not implemented");
return operand1 > operand2; // Check if operand1 is greater than operand2
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
package com.cbfacademy.strings;

public class App {
public static void main( String[] args ) {
System.out.println( "Hello World!" );
public static void main(String[] args) {
// Example test cases to verify functionality
System.out.println(concatenate("Hello", "World", "Java")); // Output: HelloWorldJava
System.out.println(areEqual("Test", "Test")); // Output: true
System.out.println(areEqual("Test", "test")); // Output: false
System.out.println(format("Apple iPhone 15 Pro", 47, 1199.99)); // Output: Item: Apple iPhone 15 Pro. Price: £1199.99. Quantity: 47
}

public static String concatenate(String word1, String word2, String word3) {
// TODO: Write code that concatenates the input parameters and returns the result
throw new RuntimeException("Not implemented");
// Concatenates the input strings and returns the result
return word1 + word2 + word3;
}

public static Boolean areEqual(String word1, String word2) {
// TODO: Write code to determine whether the input parameters are equal strings
throw new RuntimeException("Not implemented");
// Compares the two strings and returns true if they are equal (case-sensitive)
return word1.equals(word2);
}

public static String format(String item, int quantity, double price) {
// TODO: Write code to return a string formatted as follows: "Item: [item]. Price: £[price]. Quantity: [quantity]". The price should be formatted to two decimal places, e.g. 99.99
throw new RuntimeException("Not implemented");
// Formats the string with item, price with £ symbol, and quantity
return String.format("Item: %s. Price: £%.2f. Quantity: %d", item, price, quantity);
}
}