Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Don\'t use ArrayList I think we should have possibility of a single owner having

ID: 3841276 • Letter: D

Question

Don't use ArrayList

I think we should have possibility of a single owner having multiple accounts.
The beginning of a 'project' that will be in a banking context with accounts and their owners with deposits , withdrawals, interest etc

A java project that will use console I/O to implement Cayman Dodge Banking System
A) Create (or more generally CRUD) 'accounts' each of which will have
        - owner (account number)
        - balance
        - type (checking / savings)

      - associated interest

B) Generate reports regarding our accounts via menu
        Overall report (sorted by ... ? )
        Individual report for account by name or #
        Application of interest rate to update account (time period ?)

Explanation / Answer


public class Accounts {
   int Account_number;
   int balance;
   String type;
   int intrest;
   Accounts(){
       Account_number=0;
       balance=0;
       type=null;
       intrest=0;
   }
   Accounts(int Account_number,int balance,String type,int intrest){
       setAccount_number(Account_number);
       setbalance(balance);
       settype(type);
       setintrest(intrest);
      
   }
   public void setintrest(int intrest) {
       this.intrest=intrest;
      
      
   }
   public void settype(String type) {
       // TODO Auto-generated method stub
       this.type=type;
      
   }
   public void setbalance(int balance) {
       // TODO Auto-generated method stub
       this.balance=balance;
      
   }
   private void setAccount_number(int Account_number) {
       // TODO Auto-generated method stub
       this.Account_number=Account_number;
      
   }
   public int getAccount_number(){
       return Account_number;
   }
   public int getbalance(){
       return balance;
   }
   public String gettype(){
       return type;
   }
   public int getintrest(){
       return intrest;
   }
}

Accounts_main
import java.util.*;
import java.util.Comparator;
import java.util.Collections;
public class Accounts_main {
//static Map<Integer,Accounts>alist=new HashMap<Integer,Accounts>();
static List<Accounts>alist=new LinkedList<Accounts>();
static Scanner sc=new Scanner(System.in);
   public static void main(String[] args) {
       // TODO Auto-generated method stub
Accounts s1=new Accounts(103,10000,"savings",1000);
Accounts s2=new Accounts(102,90000,"credit",900);
Accounts s3=new Accounts(101,80000,"savings",300);
Accounts s4=new Accounts(104,70000,"savings",600);
alist.add( s1);
alist.add( s2);
alist.add( s3);
alist.add( s4);
while(true){
   System.out.println("enter choice: 1.overall report 2.individual report 3.update balance: 4.exit");
   int ch=sc.nextInt();
   switch(ch){
   case 1:overallreport();
   break;
   case 2:individualreport();
   break;
   case 3:update();
   break;
   case 4:System.exit(0);
   }
}
   }
   private static void update() {
       System.out.println("enter Account number to update intrest:");
       int updates=sc.nextInt();
       System.out.println("enter intrest amount:");
       int intst=sc.nextInt();
       for(int i=0;i<alist.size();i++){
           Object o=(Object)alist.get(i);
           Accounts a=(Accounts)o;
           if(a.getAccount_number()==updates){
               a.setintrest(intst);
               break;
           }
       }
      
   }
   private static void individualreport() {
       System.out.println("1. by Account_number 2. by balance 3. by intrest:");
       int ind=sc.nextInt();
       if(ind==1){
           System.out.println("enter Account number:");
           int accnum=sc.nextInt();
           for(int i=0;i<alist.size();i++){
           Object o=(Object)alist.get(i);
           Accounts sss=(Accounts)o;
           if(sss.getAccount_number()==accnum){
               System.out.println(sss.getAccount_number()+" "+sss.getbalance()+" "+sss.gettype()+" "+sss.intrest);
               break;
           }
           }
       }else if(ind==2){
           System.out.println("enter balance:");
           int accbal=sc.nextInt();
           for(int i=0;i<alist.size();i++){
           Object o=(Object)alist.get(i);
           Accounts sss=(Accounts)o;
           if(sss.getbalance()==accbal){
               System.out.println(sss.getAccount_number()+" "+sss.getbalance()+" "+sss.gettype()+" "+sss.intrest);
               break;
           }
           }
          
       }else if(ind==3){
           System.out.println("enter intrest:");
           int accint=sc.nextInt();
           for(int i=0;i<alist.size();i++){
           Object o=(Object)alist.get(i);
           Accounts sss=(Accounts)o;
           if(sss.getintrest()==accint){
               System.out.println(sss.getAccount_number()+" "+sss.getbalance()+" "+sss.gettype()+" "+sss.intrest);
               break;
           }
           }
       }
      
   }
   public static void overallreport(){
       System.out.println("1. sort by Account_number 2.sort by balance 3.sort by intrest:");
       int opt=sc.nextInt();
       if(opt==3){
       Collections.sort(alist,new AccountComparator());
       for(int i=0;i<alist.size();i++){
           Object o=(Object)alist.get(i);
           Accounts ac=(Accounts)o;
           System.out.println(ac.getAccount_number()+" "+ac.getbalance()+" "+ac.gettype()+" "+ac.intrest);
       }
       }
       else if(opt==2){
           Collections.sort(alist,new AccountComparatorbal());
           for(int i=0;i<alist.size();i++){
               Object o=(Object)alist.get(i);
               Accounts ac=(Accounts)o;
               System.out.println(ac.getAccount_number()+" "+ac.getbalance()+" "+ac.gettype()+" "+ac.intrest);
           }
       }
       else if(opt==1){
           Collections.sort(alist,new AccountComparatoracc_number());
           for(int i=0;i<alist.size();i++){
               Object o=(Object)alist.get(i);
               Accounts ac=(Accounts)o;
               System.out.println(ac.getAccount_number()+" "+ac.getbalance()+" "+ac.gettype()+" "+ac.intrest);
           }
       }
  
              
      
   }
}
class AccountComparator implements Comparator<Accounts>{
   public int compare(Accounts o1,Accounts o2){
      
      
           return o1.getintrest()-o2.getintrest();
  
   }
}
class AccountComparatorbal implements Comparator<Accounts>{
   public int compare(Accounts o1,Accounts o2){
      
      
      
           return o1.getbalance()-o2.getbalance();
  
   }
}
class AccountComparatoracc_number implements Comparator<Accounts>{
   public int compare(Accounts o1,Accounts o2){
  
      
      
           return o1.getAccount_number()-o2.getAccount_number();
  
   }
}

output:
enter choice:
1.overall report
2.individual report
3.update balance:
4.exit
2
1. by Account_number    2. by balance    3. by intrest:
1
enter Account number:
101
101 80000 savings 300
enter choice:
1.overall report
2.individual report
3.update balance:
4.exit
2
1. by Account_number    2. by balance    3. by intrest:
2
enter balance:
10000
103 10000 savings 1000
enter choice:
1.overall report
2.individual report
3.update balance:
4.exit
2
1. by Account_number    2. by balance    3. by intrest:
3
enter intrest:
900
102 90000 credit 900
enter choice:
1.overall report
2.individual report
3.update balance:
4.exit
3
enter Account number to update intrest:
102
enter intrest amount:
200
enter choice:
1.overall report
2.individual report
3.update balance:
4.exit
1
1. sort by Account_number    2.sort by balance    3.sort by intrest:
1
101 80000 savings 300
102 90000 credit 200
103 10000 savings 1000
104 70000 savings 600
enter choice:
1.overall report
2.individual report
3.update balance:
4.exit
1
1. sort by Account_number    2.sort by balance    3.sort by intrest:
3
102 90000 credit 200
101 80000 savings 300
104 70000 savings 600
103 10000 savings 1000
enter choice:
1.overall report
2.individual report
3.update balance:
4.exit

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote