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

****C# Coding assignment***** I have prompted the user to submit the total minut

ID: 3703626 • Letter: #

Question

****C# Coding assignment*****

I have prompted the user to submit the total minutes for a guest object.

The assignment reads: "Gets minutes rented – a guest has to rent for a minimum of an hour and no more than 8 hours."

Method:

Accepts the minutes rented and sets the class data fields (# hours rented, # minutes rented) accordingly.

private int hourRented;
private int minuteRented;

        public void CalculateTotalRentalTime()
        {
           //insert code here
        }

Then, I have to use those totals to provide the following:

calculates total price - calculated in half hour increments. For example. An snorkle costs $8 per hour. If the rental period is 30 minutes, the price is $4. Otherwise the price is $8. So a rental of 75 minutes costs $12. (1 hour is $8 and additional up to 30 minutes is $4) A rental of 45 minutes costs $8.

public void TotalPricePerHour(int hourRented, int minuteRented)
        {
            totalRentedPrice = // EQUATION MUST GO HERE
        }

Explanation / Answer

public void CalculateTotalRentalTime()

{

   while(true)

   {

       Console.WriteLine("Enter no of hours : ");

      

       // read int

       this.hourRented = Convert.ToInt32(Console.ReadLine());

      

       // if entered input is invalid

       if( this.hourRented < 1 || this.hourRented > 8 )

           Console.WriteLine("Error! a guest has to rent for a minimum of an hour and no more than 8 hours. ");

       // if entered input is valid

       else

           break;

   }

   

   // a maximum of 8 hours can be rented

   if( this.hourRented == 8 )

       this.minuteRented = 0;

   else

   {

       Console.WriteLine("Enter no of minutes : ");

       this.minuteRented = Convert.ToInt32(Console.ReadLine());

   }

   

}

public void TotalPricePerHour(int hourRented, int minuteRented)

{

    totalRentedPrice = 8 * hourRented;

   

    // calculate no of half hours

    int x = minuteRented / 30;

   

    totalRentedPrice += x * 4;

   

    // calculate remaining minutes

    minuteRented = minuteRented - ( x * 30 );

   

    // if still some more minutes are left

    if( minuteRented > 0 )

        totalRentedPrice += 4;

}