I have solved some questions, please check if my answers are correct
Hi every Java aces,
I have solved some programming questions, please check if my answers are correct. Thanks
Here are the questions and the answers to each question
(a) Write a method called add that takes three integers as parameters and returns an
integer that is the sum of the three parameters.
(b) Write a method called max that takes three integers as parameters and returns the
largest of the three integers.
(c) Write a method called printMax that takes three integers as parameters and prints
the maximum value to the screen. The method should return nothing. The method
should print the words \The maximum value is " followed by the maximum value,
followed by a new-line character. You should try to use the max method that you
wrote earlier.
(d) Write a method called min that takes three integers as parameters and returns the
smallest of the three integers.
(f) Write a method called ticketPrice that takes one integer parameter representing
the age of a person, and returns the price of a movie ticket in dollars (as a
oating
point value). Children under 6 get in for free (0.00), people that are 18 or under
pay 8.50, senior citizens (65 or older) pay 6.50, and all other people pay 10.00.
(g) Write a method called isDivisor that takes two integers as parameters and returns
true if the rst parameter is a divisor of the second parameter or false otherwise.
We say that m is a divisor of n, or that m divides n, if there is an integer k such
that n = k m. Note that 1 divides every integer, and every integer divides i
itself .
here are my codes
public class Methods
{
// This is method (a)
public static int add (int a, int b, int c)
{
int sum = a + b + c;
return sum;
}
// This is method (b)
public static int max (int a, int b, int c)
{
int largest;
if (a > b)
{
if (a > c)
{ largest = a; }
else
{ largest = c;}
}
else
{
if (b < c)
{ largest = c; }
else
{ largest = b;}
}
return largest;
}
// This is method (c)
public static void printMax (int d, int e, int f)
{
int maxValue;
maxValue = max (d, e, f);
System.out.println ("The maximum value is " + maxValue);
}
// This is method (d)
public static int min (int a, int b, int c)
{
int smallest;
if ( a < b )
{
if ( a < c )
{ smallest = a; }
else
{ smallest = c; }
}
else
{
if ( b > c )
{ smallest = c; }
else
{ smallest = b; }
}
return smallest;
}
// This is method (f)
public static double ticketPrice (int age)
{
double price;
if ( age < 6 )
{ price = 0.00; }
else
{
if ( age <= 18 )
{ price = 8.50; }
else
{
if ( age < 65 )
{ price = 10.00; }
else
{ price = 6.50; }
}
}
return price;
}
// This is method (g)
public static boolean isDivisor ( int m, int n )
{
boolean result;
int check1;
double check2;
check1 = n / m;
check2 = (double)n / m;
if ( check2 == check1 )
{ result = true; }
else
{ result = false; }
return result;
}

