Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Account JAVA Cpa
//'main' method must be in a class 'Rextester'. //openjdk version '11.0.5' import java.util.*; import java.lang.*; class Account{ private int accountNumber; private String accountName; private String accountType; private double accountBalance; public Account(int no,String n,String tp,double bal) { accountNumber=no; accountName=n; accountType=tp; accountBalance=bal; } public String getAccountName() { return accountName; } public double getAccountBalance() { return accountBalance; } } class Rextester { public static void main (String[] args) throws java.lang.Exception { Scanner sc=new Scanner(System.in); Account[] ac=new Account[4]; for(int i=0;i<4;i++) { int num=sc.nextInt(); sc.nextLine(); String name=sc.nextLine(); String type=sc.nextLine(); double balance=sc.nextDouble(); sc.nextLine(); ac[i]=new Account(num,name,type,balance); } String newname=sc.nextLine(); double newbalance=sc.nextDouble(); int ans1=countAccountsByName(newname,ac); if(ans1==0) System.out.println("No Account found with given account name"); else System.out.println(ans1); Account[] ans2=searchAccountsByBalance(newbalance,ac); if(ans2==null) System.out.println("No such Account exists"); else{ for(int i=0;i<ans2.length;i++) { System.out.println(ans2[i].getAccountName()); } } } public static int countAccountsByName(String name,Account a[]) { int ans=0; for(int i=0;i<4;i++) { if((a[i].getAccountName()).equals(name)) ans++; } return ans; } public static Account [] searchAccountsByBalance(double amt,Account a[]) { int size=0; for(int i=0;i<4;i++) { if((a[i].getAccountBalance())>=amt) size++; } if(size==0) return null; Account arr[]=new Account[size]; int k=0; for(int i=0;i<4;i++) { if((a[i].getAccountBalance())>=amt) { arr[k++]=arr[i]; } } Account t=null; for(int i=0;i<size;i++) { for(int j=i;j<size;j++) { if((arr[i].getAccountBalance())>(arr[j].getAccountBalance())) { t=arr[i]; arr[i]=arr[j]; arr[j]=t; } } } return arr; } } /* link=>https://codebashers10.blogspot.com/2021/04/TCS-Xplore-CPA-10-April-2021-Shift-1-and-2-Java-Coding-Solution.html Input 107 Ashutosh Loan Account 21300.4 101 Rahul Demat Account 7000.0 102 Rahul Savings Account 3000.5 104 Sachin Retirement Account 10000.01 Rahul 10000 */
run
|
edit
|
history
|
help
0
webPage to string
Brainf*ck Interpreter (Java)
innerclss
Date_From_Str
3e
Lexisort
To check whether a given number is smith number or not
// Java Coding Challenge - 08: Reversing a Number using Mathematical Operations
float
3.F