Bank of America Interview Question for Java Developers


Country: United States




Comment hidden because of low score. Click to expand.
0
of 0 vote

package com.sa.dtoTest;

import java.math.BigDecimal;
import java.math.MathContext;

public class caluculator implements CostCaluculator{

@Override
public CostDTO add(CostDTO arg1, CostDTO arg2) {
BigDecimal bD;
if(arg1.equals(arg2)){
MathContext mc = new MathContext(4);
bD = arg1.costAmount.add(arg2.costAmount,mc);
System.out.println(bD);
return arg1;
}else{
try {
throw new IdnotMatchException("Not equals");
} catch (IdnotMatchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}

@Override
public CostDTO subtract(CostDTO arg1, CostDTO arg2) {
BigDecimal bD;
if(arg1.costid==arg2.costid){
MathContext mc = new MathContext(4);
bD = arg1.costAmount.subtract(arg2.costAmount,mc);
System.out.println(bD);
return arg1;
}else{
try {
throw new IdnotMatchException("Not equals");
} catch (IdnotMatchException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return null;
}


}

//costDTo.java
package com.sa.dtoTest;

import java.math.BigDecimal;

import javapractice.date;

public class CostDTO {

String costid;
BigDecimal costAmount;
date effectiveDate;

public CostDTO(String costid,BigDecimal costAmount, date effectiveDate) {
this.costid=costid;
this.costAmount=costAmount;
this.effectiveDate=effectiveDate;
}

@Override
public boolean equals(Object obj) {
if(obj==this)
return true;
if(!(obj instanceof CostDTO))
return false;
CostDTO c = (CostDTO) obj;
return c.costid.equalsIgnoreCase(this.costid);
}

@Override
public int hashCode() {

int result =17;
result =31 * result + costid.toLowerCase().hashCode();
return result;
}
}
//interface

package com.sa.dtoTest;

public interface CostCaluculator {

public CostDTO add(CostDTO arg1, CostDTO arg2);
public CostDTO subtract(CostDTO arg1, CostDTO arg2);
}
//test
package com.sa.dtoTest;

import java.math.BigDecimal;

import javapractice.date;

public class test {

public static void main(String[] args) {
CostDTO cD = new CostDTO("gold",new BigDecimal("40.732"),new date());

CostCaluculator c = new caluculator();
c.add(cD, new CostDTO("Gold",new BigDecimal("40.732"),new date()));
}
}

- aditya July 12, 2017 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More