109k views
2 votes
Can someone help me code the statments in the picture?

Can someone help me code the statments in the picture?-example-1

1 Answer

4 votes

Answer:

(In this section I will put the code with no comments and I'll put the code plus comments in the explanation below :)

public class Main

{

public static void main(String[] args)

{

double cost = ParkingSpot.getPrice(4);

System.out.println(cost);

}

}

//End OF Main class

//ParkingSpot class

public class ParkingSpot

{

public static double getPrice(int hours)

{

double cost = 4.25 * hours;

if (cost < 7.00){

cost = 7.00;

}

if (hours > 3){

cost = cost * 0.25;

}

return cost;

}

}

Step-by-step explanation:

(Here I will add the comments so you better understand what is written and whats going on :)

public class Main

{

public static void main(String[] args)

{

/* the code should be written in the ParkingSpot

* class. You may use this main method to call

* methods to test your code

*/

/*We send an integer representing x amount of hours, also calling the

method and displaying the result

*/

double cost = ParkingSpot.getPrice(4);

System.out.println(cost);

}

}

//End OF Main class

//ParkingSpot class

public class ParkingSpot

{

/* Finish the static class getPrice. The parameter hours indicates the time parked.

*/

public static double getPrice(int hours)

{

//Here we set the rates

/*

It costs 4.25 per hour to park in the ParkingSpot

If the total cost come in at less than 7.oo, the price should

be adjusted UP to 7.00, the minimum Price Allowed

If the number of hours is more than three hours,

a 25% discount should be appllied

*/

double cost = 4.25 * hours;

//If the cost is less than 7.00 we set the price up to 7.00

if (cost < 7.00){

cost = 7.00;

}

/*If hours is more than 3 (meaning 4 or it would have said 3 and/or more),

a 25% discount will be appllied*/

if (hours > 3){

cost = cost * 0.25;

}

//Return cost of parking for x amount of hours

return cost;

}

}

User Chiefanov
by
4.5k points