• Post Reply Bookmark Topic Watch Topic
  • New Topic

Search in bank account arrays is not workable  RSS feed

 
adagio life
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
package Acconting;
public class BankAccount {
//Fields
private Integer number;
private String name;
private double balance;
private double amount;
private boolean overdraft;
private double interest_rate;

//Constructors
public BankAccount(Integer number,String name,double balance,double maximumsum,double depositsum,double creditsum,boolean overdraft){
this.number=number;
this.name=name;
this.balance=balance;
this.amount=amount;
this.interest_rate=interest_rate;
}
public BankAccount(float initialbalance){
this.balance=initialbalance;
}

//Methods
public Integer getnumber() {
return number;
}

public void setNumber(Integer number) {
this.number=number;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name=name;
}

public void getBalance(double balance) {
this.balance=balance;
}

public Boolean hasOverdraft() {if(overdraft);
return true;
}

public boolean clearCheck(double amount) {
if (amount<balance||hasOverdraft()==true);
return true;
}

public void deposit(double a){
this.balance+=a;
}

public void withdraw(double b){
this.balance-=b;
}

public void deposit(String str){
this.balance+=Double.parseDouble(str);
}

public void setAmount(double ammount) {
this.amount=amount;
}


public void setInitial_rate(double interest_rate) {
this.interest_rate=interest_rate;
}

public double getRate () {
return interest_rate;
}

public void addIntestrate (double interest_rate){
this.balance=balance*interest_rate+balance;
}
}



@@@
package Acconting;

import java.util.ArrayList;
import java.util.List;

public class Parser {
BankAccount[] accounts;
Parser(BankAccount[] accounts){
this.accounts=accounts;
}
//Full descriprtion of Account
public void opys(BankAccount BankAccount){
System.out.println("////////////////");
System.out.println("Number:"+BankAccount.getNumber());
System.out.println("Name:"+BankAccount.getName());
System.out.println("Overdraft:"+BankAccount.hasOverdraft());
System.out.println("Balance:"+BankAccount.getBalance());
System.out.println("Rate:"+BankAccount.getRate());
}

//First search method for string
public BankAccount[] searchParametr(String parametr, String value){
List<BankAccount>listOfBankAccount=new ArrayList<BankAccount>();
if(parametr.equals("Name")){
for(int i=0;i<accounts.length;i++){
if(accounts[i].getName().equals(value)){
listOfBankAccount.add(accounts[i]);
}
}
}
return listOfBankAccount.toArray(new BankAccount[listOfBankAccount.size()]);
}
// search method for boolean
public BankAccount[] searchParametr(String parametr, Boolean value){
List<BankAccount>listOfBankAccount=new ArrayList<BankAccount>();
if(parametr.equals("Overdraft")){
for(int i=0;i<accounts.length;i++){
if(accounts[i].hasOverdraft().equals(value)){
listOfBankAccount.add(accounts[i]);
}
}
}
return listOfBankAccount.toArray(new BankAccount[listOfBankAccount.size()]);
}
//First search method for numbers
public BankAccount[] searchParametr(String parametr, Integer value){
List<BankAccount>listOfBankAccount=new ArrayList<BankAccount>();
if(parametr.equals("Number")){
for(int i=0;i<accounts.length;i++){
if(accounts[i].getNumber().equals(value)){
listOfBankAccount.add(accounts[i]);
}
}
}
if(parametr.equals("Balance")){
for(int i=0;i<accounts.length;i++){
if(accounts[i].getBalance()!=0 && accounts[i].getBalance()<value){
listOfBankAccount.add(accounts[i]);
}
}
}
return listOfBankAccount.toArray(new BankAccount[listOfBankAccount.size()]);
}
}


@@@package Acconting;

public class Manipulation {

public static void main(String[] args) {
//Accounts array
BankAccount accounts[]={new BankAccount(100, "Main", 100.00,0.00,true,0.00),
new BankAccount(101, "Auxillary" , 10.00, 5.00,true,0.15),
new BankAccount(102, "Deposit" , 20.0, 10.0,false,0.1),
new BankAccount(103, "Credit1" , 10.0, 10.0,true,0.2),
new BankAccount(104, "Credit2" , 40.0, 10.0,true,0.25),
new BankAccount(105, "Credit3" , 10.0,5.0,true,0.15),
new BankAccount(12.00)};
//parser object
Parser parserobject=new Parser(accounts);
//deposit datas
System.out.print("--------------------- ");
parserobject.opys(accounts[2]);

//Editing with accounts methods
accounts[2].deposit(10);
accounts[2].setName("Deposit1");
accounts[2].addInterestrate(0.1);
//edited code
System.out.print("---------------------");
parserobject.opys(accounts[2]);

//Depsoit search
BankAccount searchedName[]=parserobject.searchParametr("Name", "Deposit");
//іsearch
System.out.print("---------------------");
for(BankAccount b:searchedName){
parserobject.opys(b);
}

//Overdradt search
BankAccount searchedOverdraft[]=parserobject.searchParametr("Overdraft", true);
//іsearch
System.out.print("--------------------outputting after Searching by elevator");
for(BankAccount b:searchedOverdraft){
parserobject.opys(b);
}

//Acounts less than 40
BankAccount searchedBalance[]=parserobject.searchParametr("Balance", 40);
//іsearch
System.out.print("--------------------outputting after Searching by Square");
for(BankAccount b:searchedBalance){
parserobject.opys(b);
}
}
}

I undestand that the issue is in 2 or in 3rd code (file). What to do/ Can you check from your side. As i launched it only at JavaGrasp
 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ItDoesntWorkIsUseless. You need to TellTheDetails
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!