Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

step by step Create a new Eclipse project named LabSLastnameFirstname All.of thi

ID: 3735158 • Letter: S

Question


step by step

Create a new Eclipse project named LabSLastnameFirstname All.of this lab's programs should be in the same project 1. (2 pts) Within a new class named Factorial, write a method that retums the factorial of a number. The method should take one int parameter and use a loop to compute the factorial Remember that the factorial of a positive integer n (written as n) is defined as the product of all integers from 1 up to n For example, 4! is 4 x 3 x 2 x 1 or 24. If your method is called with a zero or negative argument, just return 1 2. (2 pts) Within the same Factorial class, write a main method that gets user imput for an integer, calls your factorial method using that integer as an argument, and prints the return value. 3. (6 pts) As indicated at http//www flymemphis.com/parking, Memphis International Airport uses the following pricing schedule for their short-term parking fees Time First 30 minutes 31 to 60 minutes Each additional 30 minutes 24 bour maximum Pricing FREE $2.00 1.00 $24.00 Within a new class named Parking, write a method that takes a parameter for the number of minutes parked (you can assume it's a whole number) and returns the appropriate short-term parking charge, in dollars. Assume that the airport will always round UP to the next half hour for example, parking exactly 60 minutes would cost $2, but 61 minutes would make it S3 After all, they want to make as much money as possible If the method is called with a zero or negative argument, make it return zero. If the method is called with an argument exceeding 24 hours, the 24-hour maximum listed in the table should be applied to each complete day, and any partial day should be charged according to the schedule in the table. For example, parking for 1471 minutes would result in a charge of S26 The first 1440 minutes (24 hours) cost S24, the next 30 minutes is free, and the next 1 mnute costs $2 the same Parking class, write a main method that makes at least six calls to your parking method using different arguments and prints the return value from each call. Test a wide range of values

Explanation / Answer

Factorial .java

import java.util.Scanner;

public class Factorial {

   public static void main(String[] args) {
       //To read data from user
       Scanner sc = new Scanner(System.in);
       System.out.println("Please enter the number : ");

       int number = sc.nextInt();

       int fact = factorial(number);

       System.out.println("Factorial of " + number + " is: " + fact);

   }

   // method that takes number as argument and return factorial
   static int factorial(int number) {
       int fact = 1;
       for (int i = 1; i <= number; i++) {
           fact = fact * i;
       }
       return fact;
   }

}

output

Please enter the number :
5
Factorial of 5 is: 120

Parking .java
public class Parking {
   static double cost = 0;
   public static void main(String[] args) {

       System.out.println("Parking ...." + park(150));
       System.out.println("Parking ...." + park(15500));
       System.out.println("Parking ...." + park(2000));
       System.out.println("Parking ...." + park(15444));
       System.out.println("Parking ...." + park(250));
       System.out.println("Parking ...." + park(-25));
       System.out.println("Parking ...." + park(20));
   }

   static double park(int minutes) {
  
       if (minutes <= 30) {
           cost = 0;
       } else if (minutes > 30 && minutes <= 60) {
           cost = 2;
       } else if (minutes > 60) {
           double hours = minutes / 60.0;

           if (hours > 24) {
               cost += 24;
               minutes = (int) ((hours - 24) * 60);
               cost += park(minutes);
           } else if (hours > 1) {
               cost += 2;
               minutes = (int) ((hours - 1) * 60);
               cost += park(minutes);
           } else {
               cost += Math.ceil((double)minutes/30);
           }
       }
       return cost;
   }
}