Java Programming : Airtime Left balance calculator.
import javax.swing.JOptionPane;
public class Airtime {
public static void main(String args[]){
double Amount =0;
double Duration =0;
double CallCostPerMinute =0;
boolean goodInput = false;
boolean good = false;
boolean Good = false;
String AmountString=JOptionPane.showInputDialog(null, "Enter the amout of Airtime you have :",JOptionPane.ERROR_MESSAGE);
do
{
try
{
Amount=Double.parseDouble(AmountString);
goodInput = true;
}
catch (NumberFormatException nfe)
{
AmountString = JOptionPane.showInputDialog(null, "'"+AmountString+"'" + " is an Invalid Amount"+" Please Enter the correct Amount \nEg. Enter 29.55 for R29.55cents:","Error!",JOptionPane.ERROR_MESSAGE);
}
}
while (!goodInput);
String DurationString=JOptionPane.showInputDialog(null, "How long are you going to call for :\n(Minutes)","Call Duration",JOptionPane.QUESTION_MESSAGE);
do
{
try
{
Duration=Double.parseDouble(DurationString);
good = true;
}
catch (NumberFormatException nfe)
{
DurationString = JOptionPane.showInputDialog(null, DurationString + " is not in a Valid time Format. Please Enter the Call Duration :",JOptionPane.ERROR_MESSAGE);
}
}
while (!good);
String CallCostPerMinuteString=JOptionPane.showInputDialog(null, "How much does the call cost per minute :","Call Cost",JOptionPane.QUESTION_MESSAGE);
do
{
try
{
CallCostPerMinute=Double.parseDouble(CallCostPerMinuteString);
Good = true;
}
catch (NumberFormatException nfe)
{
CallCostPerMinuteString = JOptionPane.showInputDialog(null, CallCostPerMinuteString + "is not a Valid Call Cost:\nEg. Enter 1.20 for R1.20cents","Call Cost Per Minute",JOptionPane.ERROR_MESSAGE);
}
}
while (!Good);
double Cost =CallCostPerMinute* Duration;
double AmountLeft=(Amount-Cost);
if (AmountLeft <0){
JOptionPane.showMessageDialog(null,"You don't have enough money to call for "+DurationString+ "Minututes with R"+AmountString+
"\nYou are R"+ AmountLeft+"0"+" short.","INSUFFICIENT FUNDS!",JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(null, "The call is going to cost you R"+ Cost,"Call Cost", JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
else
JOptionPane.showMessageDialog(null, "The call is going to cost you R"+ Cost+"0","Call Cost", JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null, "The amount left will be R"+AmountLeft+"0", "Amount Left",JOptionPane.INFORMATION_MESSAGE);
{
while (!goodInput);
}
while (!goodInput);
}
}
public class Airtime {
public static void main(String args[]){
double Amount =0;
double Duration =0;
double CallCostPerMinute =0;
boolean goodInput = false;
boolean good = false;
boolean Good = false;
String AmountString=JOptionPane.showInputDialog(null, "Enter the amout of Airtime you have :",JOptionPane.ERROR_MESSAGE);
do
{
try
{
Amount=Double.parseDouble(AmountString);
goodInput = true;
}
catch (NumberFormatException nfe)
{
AmountString = JOptionPane.showInputDialog(null, "'"+AmountString+"'" + " is an Invalid Amount"+" Please Enter the correct Amount \nEg. Enter 29.55 for R29.55cents:","Error!",JOptionPane.ERROR_MESSAGE);
}
}
while (!goodInput);
String DurationString=JOptionPane.showInputDialog(null, "How long are you going to call for :\n(Minutes)","Call Duration",JOptionPane.QUESTION_MESSAGE);
do
{
try
{
Duration=Double.parseDouble(DurationString);
good = true;
}
catch (NumberFormatException nfe)
{
DurationString = JOptionPane.showInputDialog(null, DurationString + " is not in a Valid time Format. Please Enter the Call Duration :",JOptionPane.ERROR_MESSAGE);
}
}
while (!good);
String CallCostPerMinuteString=JOptionPane.showInputDialog(null, "How much does the call cost per minute :","Call Cost",JOptionPane.QUESTION_MESSAGE);
do
{
try
{
CallCostPerMinute=Double.parseDouble(CallCostPerMinuteString);
Good = true;
}
catch (NumberFormatException nfe)
{
CallCostPerMinuteString = JOptionPane.showInputDialog(null, CallCostPerMinuteString + "is not a Valid Call Cost:\nEg. Enter 1.20 for R1.20cents","Call Cost Per Minute",JOptionPane.ERROR_MESSAGE);
}
}
while (!Good);
double Cost =CallCostPerMinute* Duration;
double AmountLeft=(Amount-Cost);
if (AmountLeft <0){
JOptionPane.showMessageDialog(null,"You don't have enough money to call for "+DurationString+ "Minututes with R"+AmountString+
"\nYou are R"+ AmountLeft+"0"+" short.","INSUFFICIENT FUNDS!",JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(null, "The call is going to cost you R"+ Cost,"Call Cost", JOptionPane.INFORMATION_MESSAGE);
System.exit(0);
}
else
JOptionPane.showMessageDialog(null, "The call is going to cost you R"+ Cost+"0","Call Cost", JOptionPane.INFORMATION_MESSAGE);
JOptionPane.showMessageDialog(null, "The amount left will be R"+AmountLeft+"0", "Amount Left",JOptionPane.INFORMATION_MESSAGE);
{
while (!goodInput);
}
while (!goodInput);
}
}
Comments
Post a Comment
Be real!