import javax.swing.*;

class AtmOop //super class
{
	public static void main(String[] args) 
	{
	    int ch_ac,i,ch_in_out;
	    String ch_acStr,balanceStr,ch_in_outStr;
		double balance=1000000,total,keep_blance=500;

		System.out.println("This program ATM Uses OOP\nWrite By HolyTyrael");
		System.out.println("\nYour Begin Balance = "+balance);

		ch_acStr = JOptionPane.showInputDialog("Input your Account\n1. Saving Account\n2. Checking Account");
		ch_ac = Integer.parseInt(ch_acStr);
		while (ch_ac!=1 && ch_ac!=2) //T = do, F = un do
		{		
		ch_acStr = JOptionPane.showInputDialog("Re Input your Account\n1. Saving Account\n2. Checking Account");
		ch_ac = Integer.parseInt(ch_acStr);
		}

		//balanceStr = JOptionPane.showInputDialog("Input your Balance");
		//balance = Integer.parseInt(balanceStr);
total=balance;

if (ch_ac==1)
{ 
	    System.out.println("\nYou Uses Saving Account");
		SavingAccount pointSaving = new SavingAccount();
		total = pointSaving.saving_calNet(balance);
		System.out.println("You Balance + Net = "+total);
		
		do
		{
				
		ch_in_outStr = JOptionPane.showInputDialog("1.Check IN\n2.Check OUT\n3.Exit");
		ch_in_out = Integer.parseInt(ch_in_outStr);
		while (ch_in_out!=1 && ch_in_out!=2 && ch_in_out!=3)
		{
		ch_in_outStr = JOptionPane.showInputDialog("1.Check IN\n2.Check OUT\n3.Exit");
		ch_in_out = Integer.parseInt(ch_in_outStr);
		}

		if (ch_in_out==1)
		{
			SavingAccount pointSaving1 = new SavingAccount();
			total = pointSaving1.saving_in(total);
			JOptionPane.showMessageDialog(null,"Total Balance = "+total);

		}

		if (ch_in_out==2)
		{
			SavingAccount pointSaving2 = new SavingAccount();
			total = pointSaving2.saving_out(total);
			JOptionPane.showMessageDialog(null,"Total Balance = "+total);
		}

		if (ch_in_out==3)
		{
			System.out.println("\nExit Program");
		}
		
		} while(ch_in_out!=3);
}// if ch_ac==1


if (ch_ac==2)
{
	    System.out.println("\nYou Uses Checking Account");
		//CheckingAccount pointChecking = new CheckingAccount();
		//total = pointChecking.checking_calNet(balance);
	
		do
		{
				
		ch_in_outStr = JOptionPane.showInputDialog("1.Check IN\n2.Check OUT\n3.Exit");
		ch_in_out = Integer.parseInt(ch_in_outStr);
		while (ch_in_out!=1 && ch_in_out!=2 && ch_in_out!=3)
		{
		ch_in_outStr = JOptionPane.showInputDialog("1.Check IN\n2.Check OUT\n3.Exit");
		ch_in_out = Integer.parseInt(ch_in_outStr);
		}

		if (ch_in_out==1)
		{
			CheckingAccount pointChecking1 = new CheckingAccount();
			total = pointChecking1.checking_in(total);
			JOptionPane.showMessageDialog(null,"Total Balance = "+total);

		}

		if (ch_in_out==2)
		{
			CheckingAccount pointChecking2 = new CheckingAccount();
			total = pointChecking2.checking_out(total);
			JOptionPane.showMessageDialog(null,"Total Balance = "+total);
		}

		if (ch_in_out==3)
		{
			System.out.println("\nExit Program");
		}
		
		} while(ch_in_out!=3);
}// if ch_ac==2

System.out.println("Total Balance = "+total);
System.exit (0);
	}// main
}// class


/**
Object for SavingAccount 
Uses by AtmOop
Write By HolyTyrael
*/
class SavingAccount //sub class
{
	public double balanceDouble,balanceIn;

	public double saving_calNet(double rcvBalance)
	{
		balanceDouble = rcvBalance * 101.75 / 100;
		JOptionPane.showMessageDialog(null,"Balance + Net = "+balanceDouble);
		return balanceDouble;
	}

	public double saving_in(double rcvTotal1)
	{
		String inStr = JOptionPane.showInputDialog("Input your Balance IN");
		double in = Double.parseDouble(inStr);
		balanceDouble = in+rcvTotal1;
		System.out.println("You Balance in  = "+in+" Total = "+balanceDouble);
		return balanceDouble;
	}

	public double saving_out(double rcvTotal2)
	{
		String inStr1 = JOptionPane.showInputDialog("Input your Balance OUT");
		double in1 = Double.parseDouble(inStr1);
		if (rcvTotal2 < in1)
		{
			JOptionPane.showMessageDialog(null,"Not Enough Money for OUT");
			balanceDouble = rcvTotal2;
		}
		else
		{
		balanceDouble = rcvTotal2-in1;
		System.out.println("You Balance out = "+in1+" Total = "+balanceDouble);
		}
		return balanceDouble;
	}
}


/**
Object for CheckingAccount
Uses by AtmOop
Write By HolyTyrael
*/
class CheckingAccount //sub class
{
	public double balanceDouble,balanceIn;

	public double checking_calNet(double rcvBalance)
	{
		balanceDouble = rcvBalance * 101.75 / 100;
		JOptionPane.showMessageDialog(null,"Balance + Net = "+balanceDouble);
		return balanceDouble;
	}

	public double checking_in(double rcvTotal1)
	{
		String inStr = JOptionPane.showInputDialog("Input your Balance IN");
		double in = Double.parseDouble(inStr);
		balanceDouble = in+rcvTotal1;
		System.out.println("You Balance in  = "+in+" Total = "+balanceDouble);
		return balanceDouble;
	}

	public double checking_out(double rcvTotal2)
	{
		String inStr1 = JOptionPane.showInputDialog("Input your Balance OUT");
		double in1 = Double.parseDouble(inStr1);
		if (((rcvTotal2-in1)-(rcvTotal2 * 0.05 / 100)) < 0)
		{
			JOptionPane.showMessageDialog(null,"Not Enough Money for OUT");
			balanceDouble = rcvTotal2;
		}
		else
		{
		balanceDouble = (rcvTotal2-in1)-(rcvTotal2 * 0.05 / 100);
		System.out.println("You Balance out = "+in1+" Total = "+balanceDouble);
		}
		return balanceDouble;
	}
}