import java.io.*;
import java.util.Scanner;  // Import the Scanner class
import java.lang.Math;
/**
 * Write a description of class exercises here.
 *
 * @author (Henry)
 * @version (1.00)
 */
public class exercises{
    
    /**
     * Run this function. Notice how we don't need to convert the int into a string.
     */
    public void testInput(){
        System.out.println("apple!");
        
        Scanner scan = new Scanner(System.in);
        System.out.println("Enter your name");
        String input = scan.nextLine();
        
        
        int number = 45;
        System.out.println("Hello " + input + " " + number);
        
    }
    
    /**
     * Ask the user for their first name, then last name and then print them both, one line after the other
     * You will need to use a Scanner Object
     */
    public void askName(){
        Scanner firstname = new Scanner(System.in);
        System.out.println("whats your first name");
        String input1 = firstname.nextLine();
        Scanner secondname = new Scanner(System.in);
        System.out.println("whats your second name");
        String input2 = secondname.nextLine();
        System.out.println("your first name is " + input1 + " ");
        System.out.println("your second name is " + input2 + " ");
    }
    
    /**
     * Ask the user for their first name, then last name and then print them both on the same line
     */
    public void askFullName(){
        Scanner firstname = new Scanner(System.in);
        System.out.println("whats your first name");
        String input1 = firstname.nextLine();
        Scanner secondname = new Scanner(System.in);
        System.out.println("whats your second name");
        String input2 = secondname.nextLine();
        System.out.println("your first name is " + input1 + " and your second name is " + input2);
    }
    
    /**
     *  Build a calorie counter for one day. The NHS recommends that an adult male takes on board 2,500 calories per-day.
     *  Ask the user how much calories they have ate and print out how much they can still eat. You will have to convert the user input to a int.
     */
    public void calorieCounter(){
        Scanner numcals = new Scanner(System.in);
        System.out.println("how many calories have you eaten?");
        String input = numcals.nextLine();
        try {
            int num = Integer.parseInt(input);
            if(num <= 2500 && num > 0){
                System.out.println("you can still eat " + (2500 - num));
            } else {
                System.out.println("you have eaten " + (num - 2500) + " too many calories!");
            }
        } catch (NumberFormatException e) {
            System.out.println("Invalid string format: " + e.getMessage() + " is not a number!");
        }
    }
    
        /**
         * Ask the users for 2 measurements of an rectangle and print out the area of it.
         */
    public void areaCalculator(){
        Scanner firstname = new Scanner(System.in);
        System.out.println("whats your first measurement");
        String input1 = firstname.nextLine();
        Scanner secondname = new Scanner(System.in);
        System.out.println("whats your second measurement");
        String input2 = secondname.nextLine();
        try {
            int num1 = Integer.parseInt(input1);
            int num2 = Integer.parseInt(input2);
            System.out.println("the area is " + (num1 * num2));
        } catch (NumberFormatException e) {
            System.out.println("Invalid string format: " + e.getMessage() + " is not a number!");
        }
    }
        
        /**
         * Ask the users for their age in years and print out how long they have been alive in hours and minutes and seconds.
         */
    public void yearsToTime(){
        Scanner age = new Scanner(System.in);
        System.out.println("how old are you? (input in years)");
        String input = age.nextLine();
        try {
            float num = Float.parseFloat(input);
            System.out.println("you are " + (Math.floor(365 * num * 24)) + " hrs"); 
            System.out.println( (Math.floor(((365 * num * 24) % 1) * 60)) + " mins");
            System.out.println( (((((365 * num * 24) % 1) * 60) % 1) * 60) + " seconds old");
        } catch (NumberFormatException e) {
            System.out.println("Invalid string format: " + e.getMessage() + " is not a number!");
        }
    }
}
