Orphaned Case Error The following are the tasks which will be done in the program:-
- Accept Deposit from a customer and update the balance.
- Display the balance.
- Compute and deposit the compound interest.
- Permit withdrawal and update the balance.
- Check for the minimum balance, impose penalty, if necessary and update the balance
I am getting an "orphaned case" error for
case1: S1.Display();
case1: S2.Display();
Please help. This is the Code:
import java.util.*;
class Account
{
String custname;
double accno;
double bal;
Account(String c, double a, double b)
{custname = c;
accno = a;
bal = b;
}
void Display()
{System.out.println("Account Holder: "+custname);
System.out.println("Account Number "+accno);
System.out.println("Balance : "+bal);
}
void Deposit()
{double dep;
Scanner sc = new Scanner(System.in);
System.out.println("Please Enter the amount your want to deposit:");
dep = sc.nextDouble();
bal = bal + dep;
System.out.println("Updated Details....");
Display();
}
void Withdraw()
{double wth;
Scanner sc = new Scanner(System.in);
System.out.println("Please enter the amount you want to withdraw");
wth = sc.NextDouble();
bal = bal - wth;
System.out.println("Updated details....");
Display();
}
}
class SavAccount extends Account
{ String acctype;
SavAccount(String c, double a, double b)
{Super(c, a, b);
acctype = "Savings";
}
void ComInt()
{int months;
Scanner sc = new Scanner(System.in);
System.out.println("Please enter the duration of the account in months");
months = sc.NextInt();
double rate, inte;
rate = 0.04;
inte = months *rate * bal;
bal = bal + inte;
System.out.println("Compund Interest : "+inte);
}
void Display()
{System.out.println("Account Holder: "+custname);
System.out.println("Account Number "+accno);
ComInt();
System.out.println("Balance : "+bal);
System.out.println("Account Type: "+acctype);
}
}
class CurAccount extends Account
{String acctype;
CurAccount(String c, double a, double b)
{Super(c, a, b);
acctype = "Current";
}
void Penalty()
{
if(bal<5000.00)
{bal = bal - 100.00;
System.out.println("Fine deducted Rs.100/-");
}
}
void Display()
{System.out.println("Account Holder: "+custname);
System.out.println("Account Number "+accno);
Penalty();
System.out.println("Balance : "+bal);
System.out.println("Account Type: "+acctype);
if(bal<=5000.00)
{System.out.println("Warning!! Please maintain balance above Rs.5000/-");
}
}
}
class Accmain
{public static void main(Strings args[])
{SavAccount S1 = new SavAccount("Aniruddha", 134.00, 15000.00)
;
CurAccount S2 = new CurAccount("Tyrel" , 135.00, 6000.00);
int num = 2;
String c = "y";
int n;
double temp;
double accs[] = new double[10];
accs[0] = S1.accno;
accs[1] = S2.accno;
Scanner sc = new Scanner(System.in);
while (c == "y");
{System.out.println("Please enter your Account number:");
temp = sc.nextDouble();
if(accs[0] == temp)
{System.out.println("Welcome "+ S1.custname);
System.out.println("Account Type: "+ S1.acctype);
System.out.println("1.Display");
System.out.println("2.Withdraw");
System.out.println("3.Deposit");
n = sc.nextInt();
Switch(n)
;
{
case 1 : S1.Display();
case 2 : S1.Withdraw();
case 3 : S1.Deposit();
default :System.out.println("Bad Choice ");
c = "n";
}
}
else if(accs[1] == temp)
{System.out.println("Welcome "+ S2.custname);
System.out.println("Account Type: "+ S2.acctype);
System.out.println("1.Display");
System.out.println("2.Withdraw");
System.out.println("3.Deposit");
n = sc.nextInt()
;
Switch(n);
{
case 1 : S2.Display();
case 2 : S2.Withdraw();
case 3 : S2.Deposit();
default :System.out.println("Bad Choice ");
c = "n";
}
}
}
}
}