import java.time.LocalDate;
import java.util.Scanner;
public class fibonacci {
//objects and variabes
public static final Scanner input = new Scanner(System.in);
private static LocalDate currentDate = LocalDate.now();
private static int currentYear = currentDate.getYear();
private static final int minYear = 1870;
public static void main(String[] args) {
//variables
int year, month, day;
System.out.print("Enter your name: ");
String name = input.nextLine();
System.out.print("Enter your surname: ");
String surname = input.nextLine();
String completeName = name + " " + surname;
do{
System.out.print("Enter your birthday year: ");
year = input.nextInt();
if(year < minYear || year > currentYear) {
System.out.println("Error: the year must be between " + minYear + " and " + currentYear + ".");
}
} while(year < 0 || year > currentYear);
do{
System.out.print("Enter your birthday month: ");
month = input.nextInt();
if(month < 1 || month > 12) {
System.out.println("Error: the month must be between 1 and 12.");
}
} while(month < 1 || month > 12);
do{
System.out.print("Enter your birthday day: ");
day = input.nextInt();
if(!isDayValid(day, month, year)) {
System.out.println("Error: the day in " + month + "" + year + " does not exist.");
}
} while(!isDayValid(day, month, year));
String birthdate = day + " " + month + " " + year;
int age = currentYear-year;
String contactNumber = "XXX XX XXX";
String emailAddress = "XXX XX XXX";
String address = "XXX XX XXX";
if(completeName.equals("XXX XX XXX")) {
System.out.println("————————————BASIC PROFILE———————————");
System.out.println("Complete Name : " + completeName);
System.out.println("Birthdate : " + birthdate);
System.out.println("Contact Number: " + contactNumber);
System.out.println("Email Address : " + emailAddress);
System.out.println("Address : " + address);
checkAge(name, age);
}
System.out.println(AreaOfABox(16.5, 16.5));
System.out.println(absoluteValue(89, 90, 94, 3));
System.out.println(percentageValue(91, 100, 50, 60));
System.out.println("\n\n——————————FIBONACCI SERIES————————————");
int n = 15;
long[] fibonacciCache = fibonacci(n);
for(long element : fibonacciCache) {
System.out.print(element + " ");
}
System.out.println("\n\n—————————————PALINDROME—————————————");
if(input.hasNext()){
input.nextLine();
}
String word = input.nextLine();
if(isPalindrome(word)) {
System.out.println("• The word '" + word + "' is palindrome!");
}
else {
System.out.println("• The word " + word + " is not palindrome!");
}
}
public static boolean isDayValid(int day, int month, int year){
if(year > 0 && month > 0 && month < 13){
switch(month){
case 4:
case 6:
case 9:
case 11: return day > 0 && day < 31;
case 2: if (year % 4 == 0) {return day > 0 && day < 29;}
else if (year % 100 != 0) {return day > 0 && day < 30;}
else if (year % 400 != 0) {return day > 0 && day < 29;}
else {return day > 0 && day < 30;}
default: return day > 0 && day < 32;
}
}
return false;
}
public static void checkAge(String name, int age) {
System.out.println("————————————NAME AND AGE————————————");
if(age>18){
// If age is greater than, or equal to, 18, print "hi"
System.out.println("Hi " + name + ", you are an aduld");
} else {
// If age is less than 18, print "hello"
System.out.println("Hello " + name + ", you are still a child");
}
}
public static double AreaOfABox(double width, double length) {
System.out.println("\n\n———————————AREA OF A BOX————————————");
System.out.print("Square Per Meter: ");
return width + length;
}
public static boolean isPalindrome(String word) {
return word.equals(reverseString(word));
}
public static String reverseString(String string) {
String tmp = "";
for(int i = string.length() - 1; i >= 0; i--){
tmp += string.charAt(i);
}
System.out.println(tmp);
return tmp;
}
public static long[] fibonacci(int n) {
//I edit this beacuse your fibonacci was incorrect
long[] fibonacci = new long[n];
int n1 = 1, n2 = 1;
for(int i = 0; i < n; i++){
if(i == 0 || i == 1){
fibonacci[i] = 1;
}else{
fibonacci[i] = fibonacci[i-2] + fibonacci[i-1];
}
}
return fibonacci;
}
public static int absoluteValue(int Q1, int Q2, int Q3, int Q4) {
System.out.println("\n\n———————————STUDENT GRADES———————————");
System.out.print("Absolute Value : ");
return (Q1 + Q2 + Q3) / Q4;
}
public static double percentageValue(double G, double dividend, double multiplier, double addenen) {
System.out.print("Percentage Value: ");
return (((G / dividend) * multiplier) + addenen);
}
}