Question

Write a program to run the following methods in C#. 2) Write a method that takes...

Write a program to run the following methods in C#.

2) Write a method that takes in a teacher’s last name and exam number via parameters. Ask the teacher (using her name) to tell you the highest score on that exam. Your question should look something like “Ms. Jones, what was the highest grade on test two?” Return the value of the highest grade to the calling method.

3) Write a function called MinOfThree that takes in three numbers and returns the smallest.

6) A parking lot charges a minimum fee of $5 to park for 2 hours, and then $1 for each additional hour. The maximum charge is $10.00 per day. Write a function named Fee that takes in the number of hours parked, and returns the amount of money owed.

7) Write a function that takes in a user’s hourly rate and hours worked. Calculate and return the user’s gross pay. The user gets time and one half for any time worked over 40 hour.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//PROGRAM.CS

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
class Program
{
int GetHighestGrade(string name, string exam_number)
{
//Print the name and exam_num as concatenated string as below
Console.WriteLine("Ms. " + name + ", what was the highest grade on test " + exam_number + "?");
//Read the line and convert to int as below
int highest_grades = Convert.ToInt32(Console.ReadLine());
//return the value read
return highest_grades;
}

int MinOfThree(int a, int b, int c)
{
//if a is less than both b and c .. it is smallest
if ((a < b) && (a < c))
return a;
else //else we know a is not smallest, so now either b or c
{
if (b < c) //is b smallest ?
return b; //yes
else //no
return c; //hence c is smallest
}
}

int Fee(int num_of_hours)
{
int fee = 5; // it is base fee upto 2 hours
int max_fee = 10; //it is max for a day
  
if (num_of_hours <= 2) //so till 2 hours we charge base fee
return fee;

else //more than 2 hours
{
fee += 1*(num_of_hours - 2); //we charge base fee + $1 per extra hour after 2 hours

if (fee < max_fee) //but don't forget we can't charge more than max fee ie 10
return fee;
else
return max_fee;
}
}

double GrossPay(double hourly_rate, double hours_worked)
{
double gross_pay = hourly_rate * hours_worked; //thats how we calculate rate*time
if (hours_worked > 40)
{
//the user gets time and one half for any time worked over 40 hour.
//Not sure if I understand this condition right.
//I am assuming user gets bonus of 1/2 of his hourly rate for any hour worked over 40 hours
//Please comment if this condition is not this, and i will provide the correction
double overtime = hours_worked - 40;
gross_pay += (overtime * hourly_rate) / 2;
}
return gross_pay;
}

static void Main(string[] args)
{
//Programs instance
Program p = new Program();

Console.WriteLine("Q.2.\n");

//Q.2 just passing the values here to method GetHighestGrade and reading the return value in a local variable
int highest_grades = p.GetHighestGrade("Jones", "two");
Console.WriteLine("Highest grades: " + highest_grades);

Console.WriteLine("\n");

//Q.3 just passing the values here to method MinOfThree and reading the return value in a local variable
Console.WriteLine("Q.3.\n");
int smallest = p.MinOfThree(33, 6, 98);
Console.WriteLine("Smallest of 33, 6, 98 is " + smallest);


Console.WriteLine("\n");
//Q.6 just passing the value here to method Fee and reading the return value in a local variable
Console.WriteLine("Q.6.\n");
int fee = p.Fee(5);
Console.WriteLine("Fee of parking for 5 hours is $" + fee);

Console.WriteLine("\n");
//Q.7 just passing the values here to method GrossPay.
//and reading the return value in a local variable
// hourly rate 12 and hours worked= 30
//You can change as per your requirment
double gross_pay = p.GrossPay(12, 30);
Console.WriteLine("Q.7.\n");
Console.WriteLine("The gross pay for 30 hours @ 12$/hr is $" + gross_pay);
}
}
}

//OUTPUT

Q.2 Ms. Jones, what was the highest grade on test two? 100 Highest grades: 100 Smallest of 33 , 6, 98 is 6 Q.6 Fee of parking

Add a comment
Know the answer?
Add Answer to:
Write a program to run the following methods in C#. 2) Write a method that takes...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question 3. Write a program that contains the following functions a) A function that takes in...

    Question 3. Write a program that contains the following functions a) A function that takes in as input the amount a person has to pay to buy a house, and the monthly payments made. Your function should display how much has been payed and how much is left to pay every month until the mortgage has been payed (Ignore interest and the like) b) A function that takes in as input the color of a car, and returns the number...

  • Complete the code in C#. Part 1 is one program. Part 2 is another program. They're...

    Complete the code in C#. Part 1 is one program. Part 2 is another program. They're seperate programs, but use part 1 to figure out part 2. Part! Create a new console application named Demojobs. Write a program for Harold's Home Services. The program should instantiate an array of job objects and demonstrate their methods. The Job class contains four data fields-description (for example "wash windows), time in hours to complete (for example 3.5), per-hour rate charged (for example, $25.00),...

  • Write a Java program that has the following methods: findSum - a method that takes in...

    Write a Java program that has the following methods: findSum - a method that takes in three integers and returns the sum of these three integers; findAverage - a method that takes in three integers and returns the average of these three integers (as a double value) Within the main method read in 3 integers from the user and call above two methods by passing the three integers. Your program should print the user provided three integers and results of...

  • Write a program to prompt the user for hours and rate per hour using input to...

    Write a program to prompt the user for hours and rate per hour using input to compute gross pay. Pay should be the normal rate for hours up to 40 and time-and-a-half for the hourly rate for all hours worked above 40 hours. Put the logic to do the computation of pay in a function called computepay() and use the function to do the computation. The function should return a value. Use 45 hours and a rate of 10.50 per...

  • Part 3 (Lab2a) In this exercise you will: a. Write a method called secondTime that takes...

    Part 3 (Lab2a) In this exercise you will: a. Write a method called secondTime that takes as argument an integer corresponding to a number of seconds, computes the exact time in hours, minutes and seconds, then prints the following message to the screen: <inputseconds> seconds corresponds to: <hour> hours, <minute> minutes and <second> seconds Write another method called in Seconds that takes as arguments three integers: hours, minutes and seconds, computes the exact time in seconds, then returns the total...

  • problem specification: writing in c++ language ... Question Problem Specification: Writing in c++ language write a...

    problem specification: writing in c++ language ... Question Problem Specification: Writing in c++ language write a program that will define a structure consisting of the following data members, “fields”: - name - hours worked - hourly rate Use a structure to implement the following: -Use a function to read the name, hours and rate, passing them by reference to the main function. -Call a function to print, this function accepts the entire structure by value. This function will call a...

  • Write a C++ program that simulates playing the Powerball game. The program will generate random numbers...

    Write a C++ program that simulates playing the Powerball game. The program will generate random numbers to simulate the lottery terminal generated numbers for white balls and red Powerball. The user will have the option to self-pick the numbers for the balls or let the computer randomly generate them. Set the Grand Prize to $1,000,000,000.00 in the program. Project Specifications Input for this project: Game mode choice – self pick or auto pick Five numbers between 1 and 69 for...

  • c++ language Write a program that contains the following functions, i. A function isVowel that takes...

    c++ language Write a program that contains the following functions, i. A function isVowel that takes in a character and returns true if it is a vowel and false otherwise ii. A function that request from the user to enter in a sequence of characters, and outputs the number of vowels entered. (Use Function in a) to assist you, a sentinel value can be used to specify the end of the user input iii. A function that reads 3 test...

  • I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that a...

    I need java code for the following problem. Lab 7: Methods 1. Write a Java program called Numbers that calls the following methods and displays the returned value: Write a method called cubelt that accepts one integer parameter and returns the value raised to the third power as an integer. o Write a method called randominRange that accepts two integer parameters representing a range. The method returns a random integer in the specified range inclusive. 2. o Write a method...

  • This is a c++ program. Use the description from Parking Ticket Simulator (listed below) as a basis, where you need to...

    This is a c++ program. Use the description from Parking Ticket Simulator (listed below) as a basis, where you need to create a Car class and Police Officer class, to create a new simulation. Write a simulation program (refer to the Bank Teller example listed below) that simulates cars entering a parking lot, paying for parking, and leaving the parking lot. The officer will randomly appear to survey the cars in the lot to ensure that no cars are parked...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT