import java.text.*;
import javax.swing.*; // All the methods that belong to the class Swing are imported
public class TestFoodItem
{
public static void main(String args[])
{
String output = "";
String foodName = "";
String foodWeight = "";
String foodPrice = "";
foodName = JOptionPane.showInputDialog( "What you bought?" );
foodWeight = JOptionPane.showInputDialog( "Enter the weight of the item?" );
Float f = new Float(foodWeight); // First Convert the weight from string to float
double weigh = f.doubleValue(); // Then Convert the float to double
foodPrice = JOptionPane.showInputDialog( "Enter the price of the item?");
Float g = new Float(foodPrice); // First Convert the weight from string to float
double price = g.doubleValue(); // Then Convert the float to double
FoodItem MyShopping = new FoodItem(foodName, weigh, price);
output = "Description of the item: " + MyShopping.getDesc() + "\n";
output = output + "weight of the item: " + MyShopping.getWeight() + "\n";
output = output + "Price per kg $ " + MyShopping.getPrice() + "\n";
output = output + "Total Price of the item $:" + MyShopping.calcTotalPrice() + "\n";
JOptionPane.showMessageDialog( null, output, MyShopping.getDesc(), JOptionPane.INFORMATION_MESSAGE);
// forcing decimal place to two digits
DecimalFormat df = new DecimalFormat("#0.00");
//df.setMinimumFractionDigits(2);
output = "";
output = "Description of the item: " + MyShopping.getDesc() + "\n";
output = output + "weight of the item: " + MyShopping.getWeight() + "\n";
String formatedPrice = df.format(MyShopping.calcTotalPrice());
output = output + "Price per kg $ " + formatedPrice + "\n";
String formatedTotalPrice = df.format(MyShopping.calcTotalPrice());
output = output + "Total Price of the item $:" + formatedTotalPrice + "\n";
JOptionPane.showMessageDialog( null, output, MyShopping.getDesc(), JOptionPane.INFORMATION_MESSAGE);
}
}
Subscribe to:
Post Comments (Atom)
Carlo Cipolla's Laws of Stupidity
"By creating a graph of Cipolla's two factors, we obtain four groups of people. Helpless people contribute to society but are...
-
To install pngwrite we need to install to helper library before we install pngwriter. 1. libpng 2. freetype2 We can use fink or macport to i...
-
"By creating a graph of Cipolla's two factors, we obtain four groups of people. Helpless people contribute to society but are...
-
Use 'Disk Utility' application to format the USB drive in MS-DOS (FAT) format Download the windows ISO file from the Windows websit...
No comments:
Post a Comment