/**
* class MethodUser gives you a main method to use to call some methods
* that were already created beforehand.
* Start by copying this entire page into BlueJ in a new class.
* Then, replace the comments with the correct program calls.
* Do one line at a time and compile and test after each.
*
* You can choose tools / project documentation to see what each method
needs,
* or you can look at the method code,
* or you can look at the methodsExercises
instructions
* Unfortunately, I have not been able to properly indent
*
* @author pepper
* @version 4/14/07
*/
import java.util.Scanner;
public class MethodUser
{
/** main method that uses all the other methods
* @param String[] args not used
*/
public static void main (String [] args)
{
Scanner myTerm = new Scanner(System.in);
System.out.println ("What is the price of the item?");
double myPrice = myTerm.nextDouble();
System.out.println ("What is the cost of the item?");
double myCost = myTerm.nextDouble();
//--------
// determine the profit on one sale of this item
// call the method profitOnOneSale to determine the profit and
// put that into a variable called myprofit.
//--------
// print "The profit is " followed by myprofit. It cost mycost
and the price was myprice.
System.out.println ("How many did you buy?");
double myQty = myTerm.nextInt();
//--------
//determine the profit on that total amount sold
// call the method profitOnManySales to determine the profit
// on the entire quantity, and save it into myTotalProfit
//--------
// print "my total profit on x qty is " and then myTotalProfit
//--------
// ask the method smallNumber whether profit is a small number.
If it is a smallNumber
// (meaning smallNumber returns true) print "This is a small number."
// otherwise, print "This is a big number."
//--------
System.out.println ("What is your name. Please type your first and
last name?");
String first = myTerm.next();
String last = myTerm.next();
//--------
// call the oneName method to get the first and last name
together,
// and save that in a full name variable.
//--------
// print the full name followed by the total profit from above.
}
/**
* profitOnOneSale The profit is the price minus the cost.
*
* @param double price
* @param double cost
* @return double profit
*/
public static double profitOnOneSale (double price, double cost)
{
return price - cost;
}
/**
* profitOnManySales The profit is the price minus the cost.
* Multiply that times the quantity sold for the total profit.
*
* @param double price
* @param double cost
* @param int quantity sold
* @return double profit on all items sold
*/
public static double profitOnManySales(double priceIn, double costIn,
int qty)
{
return profitOnOneSale(priceIn, costIn)*qty;
}
/**
* oneName The full name is the first name plus a space plus the last
name
*
* @param String First
* @param String Last
* @return String Full Name
*/
public static String oneName(String first, String last)
{
String full = first + " " + last;
return full;
}
/**
* smallNumber If the number is greater than 20, return true; otherwise
return false.
*
* @param double number to test
* @return boolean True if greater than 20
*/
public static boolean smallNumber(double NumberToTest)
{
return NumberToTest < 20;
}
}