Write the function header for each of the following functions. a) Function hypot
ID: 3684054 • Letter: W
Question
Write the function header for each of the following functions.
a) Function hypotenuse that takes two double- precision floating- point arguments, side1 and side2, and returns a double- precision floating- point result.
b) Function smallest that takes three integers, x, y, z, and returns an integer.
c) Function instructions that does not receive any arguments and does not return a value. [ Note: Such functions are commonly used to display instructions to a user.]
d) Function intToFloat that takes an integer argument, number, and returns a floating-point result. 5.9 ( Parking Charges) A parking garage charges a $ 2.00 minimum fee to park for up to three hours and an additional $ 0.50 per hour for each hour or part thereof over three hours. The maximum charge for any given 24- hour period is $ 10.00. Assume that no car parks for longer than 24 hours at a time. Write a program that will calculate and print the parking charges for each of three customers who parked their cars in this garage yesterday. You should enter the hours parked for each customer. Your program should print the results in a tabular format, and should calculate and print the total of yesterday's receipts. The program should use the function calculateCharges to determine the charge for each customer. (calculateCharges will be made by you.)
Please keep the hours data in an array.
car hours charge
1 1.5 2.00
2 4 2.50
3 24 10.00
TOTAL 29.5 14.50
In this program -- you will have loops, arrays and functions
Explanation / Answer
1)
a)
double hypotenuse( double side1, double side2 )
b)
int smallest( int x, int y, int z )
c)
void instructions()
2)
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class Garage extends JApplet implements ActionListener
{
JTextField hoursInput;
JLabel hoursPrompt;
double totalReceipts, fee;
public void init()
{
hoursPrompt = new JLabel( "Enter number of hours:" );
hoursInput = new JTextField( 4 );
hoursInput.addActionListener( this );
Container container = getContentPane();
container.setLayout( new FlowLayout() );
container.add( hoursPrompt);
container.add( hoursInput );
}
public void actionPerformed( ActionEvent e )
{
double hours = Double.parseDouble( e.getActionCommand() );
fee = calculateCharges( hours );
totalReceipts += fee;
showStatus( "Current charge: " + fee + "; Total receipts: " + totalReceipts );
}
public double calculateCharges( double hours )
{
double charge = 2.0;
if ( hours > 3.0 )
charge = 2.0 + 0.5 * Math.ceil( hours - 3.0 );
if ( charge > 10.0 )
charge = 10.0;
return charge;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.