First Commit

This commit is contained in:
2023-09-19 22:07:16 +03:00
commit 5e4b81c90d
35 changed files with 1092 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
plugins {
id("java")
}
group = "org.lumijiez"
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
}
dependencies {
testImplementation(platform("org.junit:junit-bom:5.9.1"))
testImplementation("org.junit.jupiter:junit-jupiter")
}
tasks.test {
useJUnitPlatform()
}

View File

@@ -0,0 +1,19 @@
package org.lumijiez;
public class Diamond {
public static void draw(int size) {
if (size % 2 == 0) {
System.out.println("Please give an odd number");
return;
}
int count = 1;
for (int x = 0; x < size; x++) {
for (int y = 0; y <= size; y++) System.out.print((y >= (size - count) / 2 && y <= (size / 2 + count / 2)) ? '*' : ' ');
System.out.println();
count += (x < size / 2) ? 2 : -2;
}
}
}

View File

@@ -0,0 +1,24 @@
package org.lumijiez;
public class Main {
public static void main(String[] args) {
// First Challenge
User.printInitials(new User("Dominic", "Toretto"));
// Second Challenge
MathUtils.printSumMultiples(10);
// Third Challenge
Diamond.draw(7);
// Fourth Challenge
Member member1 = new Member("Don", 56, 9);
member1.printCategory();
// Fifth Challenge
MathUtils.printNextPerfectSqr(64);
// Sixth Challenge
MathUtils.printIsNarcissistic(153);
}
}

View File

@@ -0,0 +1,23 @@
package org.lumijiez;
public class MathUtils {
public static void printSumMultiples(int number) {
int sum = 0;
for(int x = 0; x < number; x++) sum += (x % 3 == 0 || x % 5 == 0) ? x : 0;
System.out.println("The sum of all multiples of 3 and 5 is: " + sum);
}
// Nested as fuck, but 1 line
public static void printNextPerfectSqr(double number) {
System.out.println(Math.pow(Math.ceil(Math.sqrt((number == Math.pow(Math.ceil(Math.sqrt(number)), 2) ? number + 1 : number))), 2));
}
// Streams seemed useful here
public static void printIsNarcissistic(int number) {
System.out.println(String.valueOf(number).chars()
.mapToObj(Character::getNumericValue)
.map(n -> (int) Math.pow(n, String.valueOf(number).length()))
.reduce(0, Integer::sum) == number ? "Narcissistic" : "NOT");
}
}

View File

@@ -0,0 +1,36 @@
package org.lumijiez;
public class Member {
private final int age;
private final int handicap;
private final String category;
public int getAge() {
return age;
}
public int getHandicap() {
return handicap;
}
public String getCategory() {
return category;
}
public String getName() {
return name;
}
private String name;
public Member(String name, int age, int handicap) {
this.age = age;
this.handicap = handicap;
this.name = name;
this.category = (age > 55 && handicap > 7) ? "SENIOR" : "OPEN";
}
public void printCategory() {
System.out.println(this.category);
}
}

View File

@@ -0,0 +1,13 @@
package org.lumijiez;
public class User {
public String firstName, lastName;
public User(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
public static void printInitials(User user) {
System.out.print(user.firstName.charAt(0) + ". " + user.lastName.charAt(0) + ". \n");
}
}