Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aonic/827788 to your computer and use it in GitHub Desktop.
Save aonic/827788 to your computer and use it in GitHub Desktop.
/**
*
*/
package example05;
import java.util.Scanner;
/**
* @author pajensen
*
*/
public class MethodDemo
{
/**
* @param args
*/
public static void main (String[] args)
{
Scanner in = new Scanner (System.in);
System.out.println ("Enter an east coordinate: ");
int e1 = in.nextInt();
System.out.println ("Enter a south coordinate: ");
int s1 = in.nextInt();
System.out.println ("Enter another east coordinate: ");
int e2 = in.nextInt();
System.out.println ("Enter another south coordinate: ");
int s2 = in.nextInt();
double result;
result = MethodDemo.distance(e1, s1, e2, s2);
result /= 700;
System.out.println ("As the crow flies, the coordinates are " + result + " miles apart.");
}
/**
* This method computes the Cartesian distance between two
* points.
*
* @param x1 the first x coordinate
* @param y1
* @param x2
* @param y2
* @return
*/
public static double distance (double x1, double y1, double x2, double y2)
{
double deltaX, deltaY;
deltaX = x1 - x2;
deltaY = y1 - y2;
double dist;
dist = Math.sqrt(deltaX * deltaX + deltaY * deltaY);
return dist;
}
}
/**
* This method computes an overdue fine for a number of books.
* Given an integer number of books and late days, the
* fine is computed as follows:
*
* $0.15 per book per day for the first week
* $0.25 per book for any additional late days
*
* No fine will exceed $25. If the computed fine exceeds $25, it is
* reduced to $25.
*
* It is assumed that the inputs are non-negative.
*
* @param bookCount the number of books that are late
* @param daysLate the total number of days late
*
* @return the total fine (as a double)
*/
public static double computeOverdueFine (int bookCount, int daysLate) {
int firstWeek = 0;
int afterWeek = 0;
double fine = 0.0;
if(daysLate > 7) {
afterWeek = (daysLate - 7);
firstWeek = 7;
}
else {
firstWeek = daysLate;
}
fine += (firstWeek * bookCount) * 0.15;
fine += (afterWeek * bookCount) * 0.20;
if(fine > 25) {
return 25.00d;
}
return fine;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment