Question

In: Computer Science

USING JAVA A little-known fact: According to Pets.WebMD website: For dogs under 21 pounds in weight,...

USING JAVA

A little-known fact: According to Pets.WebMD website: For dogs under 21 pounds in weight, the conversion from a dog’s age to an equivalent human age is:
1st year: 15 years
2nd year: add 9 years
thereafter: add 4 years for each additional year of the dog’s age
So, for example, a dog aged 5 would have an equivalent age of (15+9+4+4+4), or 36 human years old.   

Write a lambda expression called convertToHuman, using a standard functional interface, that will take a given dog and return the equivalent human age . [Assume dog weighs less than 21 pounds]

Solutions

Expert Solution

If you have any problem with the code feel free to comment.

Program

import java.util.Scanner;

//funtional interface
interface DogToHuman{
        public int convertToHuman(int dog);
}

public class Test{
        public static void main(String[] args) {
                //creating a labda expression
                DogToHuman obj = (int dog) -> {
                        int age = 0;
                        //calcualting the age  of human in dog years
                        for(int i=1; i<=dog; i++) {
                                if(i==1)
                                        age +=15;
                                else if(i==2)
                                        age += 9;
                                else
                                        age += 4;
                        }
                        return age;
                };
                
                Scanner sc = new Scanner(System.in);
                //taking user input
                System.out.print("Enter dogs age: ");
                int dog = sc.nextInt();
                sc.close();
                //displaying output
                System.out.println("Human age: "+obj.convertToHuman(dog)+" years");
        }
}

Output


Related Solutions

In a sample of 51 babies, the mean weight is 21 pounds and the standard deviation...
In a sample of 51 babies, the mean weight is 21 pounds and the standard deviation is 4 pounds. Calculate a 95% confidence interval for the true mean weight of babies. Suppose we are interested in testing if the true mean weight of babies is 19.4 vs the alternative that it is not 19.4 with an alpha level of .05. Would this test be significant? Explain your answer. Perform the t test and use a t-table to get the p-value
It is known that 1 year old dogs have a mean gain in weight of 1.0...
It is known that 1 year old dogs have a mean gain in weight of 1.0 pound per month with a standard deviation of 0.40 pound. A special diet supplement, Helthpup, is given to a rando sample of 36, 1-year-old dogs for a month; their mean gain in weight is 2.15 pounds. At the 0.01 level of significance, does helthpup affect weight gain in 1-year-old dogs? (a) What is the research problem? (b) State null and alternative hypothesis (c) Is...
USING MATLAB: Create a BMI calculator application that reads the user’s weight in pounds and height...
USING MATLAB: Create a BMI calculator application that reads the user’s weight in pounds and height in inches (or, if you prefer, the user’s weight in kilograms and height in meters), then calculates and displays the user’s body mass index. Also, the application should display the following information from the Department of Health and Human Services/National Institutes of Health so the user can evaluate his/her BMI: BMI VALUES ("Underweight : Less than 18.5 Normal : between 18.5 and 24.9 Overweight...
----------USING JAVA----------- Your objective is to beat the dealer's hand without going over 21. Cards dealt...
----------USING JAVA----------- Your objective is to beat the dealer's hand without going over 21. Cards dealt (randomly) are between 1 and 11. You receive 2 cards, are shown the total, and then are asked (in a loop) whether you want another card. You can request as many cards as you like, one at a time, but don't go over 21. (If you go over 21 it should not allow you any more cards and you lose) Determine the dealer's hand...
Create using Java Description: Palindrome -- According to wikipedia "A palindrome is a word, phrase, number...
Create using Java Description: Palindrome -- According to wikipedia "A palindrome is a word, phrase, number or other sequence of units that can be read the same way in either direction" Write a application that can determine if a 5 digit number you input is a palindrome. If the number is a palindrome then print "The number is a palindrome." If it is not then print "The number is NOT a palindrome" Make sure to use an array Allow input...
Given the population mean for weight at 191.00 pounds, but no population standard deviation, using t = X-bar - µ/est. σx̄, and alpha .01, perfom the following seven-step process and contstruct the appropriate confidence intervals.
Data Set Height Weight Age Shoe Size Waist Size Pocket Change 64 180 39 7 36 18 66 140 31 9 30 125 69 130 31 9 25 151 63 125 36 7 25 11 68 155 24 8 31 151 62 129 42 6 32 214 63 173 30 8 34 138 60 102 26 6 25 67 66 180 33 8 30 285 66 130 31 9 30 50 63 125 32 8 26 32 68 145 33...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT