
Patrick B. answered 11/11/19
Math and computer tutor/teacher
import java.io.*;
class Discounts
{
private double amount;
private Console console;
Discounts()
{
amount = 0;
console = System.console();
}
public double GetAmount() { return(amount); }
public int readValue()
{
int iReturn = 0;
try
{
System.out.print(" Please input the bill value :>");
String inbuff = console.readLine();
amount = Double.parseDouble(inbuff);
}
catch (Exception ex)
{
iReturn = -1;
System.out.println(" Input exception has occured ");
}
return(iReturn);
}
public double calDiscount()
{
double dblReturn = amount;
if (amount>=10000)
{
dblReturn = amount * 0.80;
}
else if (amount>=5000)
{
dblReturn = amount * 0.90;
}
else if (amount >=2000)
{
dblReturn = amount * 0.95;
}
return(dblReturn);
}
public static void main(String args[])
{
Discounts myDiscount = new Discounts();
if (myDiscount.readValue()>=0)
{
System.out.println(" The original amount of the bill is " + myDiscount.GetAmount());
System.out.println(" The discounted amount of the bill is " + myDiscount.calDiscount());
}
}