import java.io.*; //----------------------------------------------------------------- // CS100 P1 Q2 // // This program prompts the user for the weight of an item, the price // of the item per pound, and print of the cost of the item. // // Author : Wei Tsang Ooi (weitsang@cs.cornell.edu) // Date : 2 July 1999 //----------------------------------------------------------------- class Marketplace { //------------------------------------------------------------- // getInput // // input : message to be shown to user // return : the value input by user // // This method prompt the user for input, and return the value // input by the user. //------------------------------------------------------------- private static float getInput(String message) throws IOException { BufferedReader stdin; stdin = new BufferedReader(new InputStreamReader(System.in)); System.out.print(message); String input = stdin.readLine(); Float f = Float.valueOf(input); return f.floatValue(); } //------------------------------------------------------------- // calculatePrice // // input : weight - weight of the item // pricePerPound - price of the item per pound // return : the price of the item //------------------------------------------------------------- private static float calculatePrice(float weight, float pricePerPound) { return weight*pricePerPound; } //------------------------------------------------------------- // output // // input : price on the item // return : none // // Output the price on the screen. //------------------------------------------------------------- private static void output (float price) { System.out.println("The total cost of your item is: " + price); } public static void main(String[] args) throws IOException { float weight = getInput("How many pounds of the item do you have ?"); float pricePerPound = getInput("What is the price per pound of this item ?"); float totalCost = calculatePrice(weight, pricePerPound); output(totalCost); } }