Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ********************************************************
- // BaconEater.java
- //
- // Computes the price of a bacon given the weight
- // (in pounds) and price per pound -- prints a label,
- // nicely formatted, for the item.
- //
- // ********************************************************
- import java.util.Scanner;
- public class BaconEater {
- // ---------------------------------------------------
- // main reads in the price per pound of the sales price
- // and number of lbs of a bacon then computes
- // the total price and prints a "label" for the item
- // --------------------------------------------------
- public static void main(String[] args) {
- // create a pricePerPound variable of type double
- // create a weightPounds variable of type double
- // create a weight variable of type double
- // create a totalPrice variable of type double
- // create a Scanner object that takes in input from the keyboard
- // Declare money as a NumberFormat object and use the
- // getCurrencyInstance method to assign it a value
- // Declare fmt as a DecimalFormat object and instantiate
- // it to format numbers with at least one digit to the left of the
- // decimal and the fractional part rounded to two digits.
- // prompt the user and read in each input
- // read in the price per pound
- // read in the weight
- // Compute the total price
- // Print the label using the formatting objects
- // fmt for the weight in pounds and money for the prices
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment