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
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,33 @@ public class Variables {
public static void main(String[] args) {

// TODO: 1 - Declare an int variable called age and assign it the value 25

int age = 25;

// TODO: 2 - Declare a double variable called price and assign it the value 9.99

double price = 9.99;

// TODO: 3 - Declare a boolean variable called isJavaFun and assign it the value true

boolean isJavaFun = true;

// TODO: 4 - Declare a String variable called name and assign it your name

String name = "Jose";

// TODO: 5 - Declare a char variable called grade and assign it the value 'A'

char grade = 'A';

// TODO: 6 - Print all the variables above using System.out.println
// Hint: You can print each variable on its own line, e.g.:
// System.out.println("Age: " + age);

System.out.println("Age: " + age);
System.out.println("Price: " + price);
System.out.println("isJavaFun: " + isJavaFun);
System.out.println("Name: " + name);
System.out.println("Grade: " + grade);

// TODO: 7 - Declare a final (constant) variable called MAX_SCORE, set it to 100, and print it
// Hint: Use the 'final' keyword before the type to make a constant
final int MAX_SCORE = 100;
System.out.println("MAX_SCORE: " + MAX_SCORE);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class DateExercises {
*/
public static LocalDate getToday() {
// TODO: 1 - Use LocalDate.now() to get and return today's date.
return null;
return LocalDate.now();
}

/**
Expand All @@ -30,7 +30,7 @@ public static LocalDate getToday() {
*/
public static LocalDate getIndependenceDay() {
// TODO: 2 - Use LocalDate.of(year, month, day) to create and return July 4, 1776.
return null;
return LocalDate.of(1776, 7, 4);
}

/**
Expand All @@ -40,7 +40,7 @@ public static LocalDate getIndependenceDay() {
*/
public static LocalDateTime getCurrentDateTime() {
// TODO: 3 - Use LocalDateTime.now() to get and return the current date and time.
return null;
return LocalDateTime.now();
}

/**
Expand All @@ -56,7 +56,7 @@ public static LocalDate addToDate(LocalDate date, int days, int months, int year
// TODO: 4 - Use plusDays(), plusMonths(), and plusYears() on the date.
// Remember: LocalDate is immutable, so each method returns a NEW LocalDate.
// Chain the calls or apply them sequentially.
return null;
return date.plusDays(days).plusMonths(months).plusYears(years);
}

/**
Expand All @@ -69,7 +69,9 @@ public static LocalDate addToDate(LocalDate date, int days, int months, int year
public static String compareDates(LocalDate date1, LocalDate date2) {
// TODO: 5 - Use isBefore() and isAfter() methods on date1 to compare with date2.
// Return "before", "after", or "equal".
return null;
boolean before = date1.isBefore(date2);
boolean after = date1.isAfter(date2);
return before ? "before" : after ? "after" : "equal";
}

/**
Expand All @@ -84,7 +86,8 @@ public static String formatDate(LocalDate date, String pattern) {
// TODO: 6 - Create a DateTimeFormatter using DateTimeFormatter.ofPattern(pattern).
// Use date.format(formatter) to format the date.
// Return the formatted string.
return null;
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
return date.format(formatter);
}

/**
Expand All @@ -98,7 +101,9 @@ public static LocalDate parseDate(String dateString) {
// TODO: 7 - Create a DateTimeFormatter with the pattern "dd-MM-yyyy".
// Use LocalDate.parse(dateString, formatter) to parse the string.
// Return the resulting LocalDate.
return null;
String pattern = "dd-MM-yyyy";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
return LocalDate.parse(dateString, formatter);
}

public static void main(String[] args) {
Expand Down