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; } }
run
|
edit
|
history
|
help
0
jb11.0 threads
++a vs a++ and calculations around different variables
클래스의 정의와 인스턴스 생성
Lincoln1_Surafel
strstr() function / indexOf() function
Sum of ODD and EVEN numbers in an array
191fa07131
WM Test
forloop1
Coding Numbers - Duplicate - Array