Ask Java Expert


Home >> Java

Follow the steps detailed below. Make sure your provide good Javadoc comments for all your classes and methods.

Step 1: Create BankAccount class
Create a new eclipse project titled Lab6-JUnit. Create BankAccount class under package core. It should have the following attributes and methods:
• accountNumber - String
• accountHolder - String
• balance - double (balance without interest added)
• accountType - int (Account type can be either 1 - Savings, 2 - Award Savers, 3 - Checking,
or 4 for Credit Card, anything other than these values should set to 0)
• Two constructors:
- default constructor (no parameters): Set balance=0, accountType=0, accountNum- ber="none", accountHolder="Unknown"
- Other constructor accepts user entered values for all attributes
• Gets and sets for all attributes (You don't have to type up all the get and set methods. Use
Eclipse to generate them automatically. Click on Source → Generate Getters and Setters).
• Method find outTotalBalance() - returns the balance of the account after the interest has been applied. Formula for calculating the balance is: totalBalance = balance + (balance ∗
interestRate/100). The interest rate depends on the accountType: - Savings: interest is 0.5%
- Award Savings: interest is 4.5%
- Checking: interest is 1.0%
- CreditCard: interest is 15%
- Other: return 0
• Method getInterestRate that returns the interest rate depending on the type of account
????
Step 2: Create a TestCase
Create a TestCase class titled BankAccountTest (New → Java → JUnitTestCase) under pack- age test. Check appropriate method stubs you would like to create. You can create setUp(), tearDown() methods are run before and after, respectively, each test case is run. You can create setUpBeforeClass(), tearDownAfterClass() methods only run when the test case class is first in- stantiated and terminated respectively. You can browse the application to the class that you wish to test and select appropriate methods that you plan to test, or this could be left blank if you will generate the class while creating the test. Test find outTotalBalance and getInterestRate methods of BankAccount class.
Below is a test case template that tests a List class. This test class demonstrates the basic func- tionality of the setUp() and tearDown() methods, and gives ex test cases.
import org.junit.Assert.*;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
public class SampleTest {
private List emptyList;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
}
/**
* Sets up the test fixture (Called before every test case method.)
*/
public void setUp() throws Exception {
emptyList = new ArrayList();
}
/**
* Tears down the test fixture (Called after every test case method.)
*/
public void tearDown() throws Exception {
emptyList = null;
}
?

@Test
public void testSomeBehavior() {
assertEquals("Empty list should have 0 elements", 0, emptyList.size());
}
@Test
public void testAnotherBehavior() {
assertTrue(emptyList.size() == 0);
}
}

Step 3: Create a TestSuite
A TestSuite is a simple way of running one program that, in turn, runs all test cases at one time. Create a TestSuite class titled Lab6TestSuite under package test. You have to provide names of test classes you would like to include in the test suite using the annotation @SuiteClasses (Test1.class, Test2.class, Test3.class).
Below is a test suite template. This test suite demonstrates the basic functionality of the suite() method, which is what you add each of the test cases to the suite in. This should all be generated for you by Eclipse if you use the eclipse wizard to create the Test Suite as describeed above. Do not forget to change the class name to Lab6TestSuite.
import org.junit.runners.Suite.SuiteClasses;
import org.junit.runners.Suite;
import org.junit.runner.RunWith;
@RunWith(Suite.class)
@SuiteClasses({ BankAccountTest.class })
public class Lab6TestSuite {
}
Execute the test cases by right clicking on Lab6TestSuite, Select Run → JUnitTestCase. Make sure the tests run successfully.
Step 4: Create Customer class
Create another class titled Customer under package core. It should have the following attributes and methods:
• name - String
• streetAddress - String • city - String
• state - String
• zip - String
• age - int
• Constructor that accepts name and address values and sets the attributes.
• Gets and sets for all attributes (You don't have to type up all the get and set methods. Use
Eclipse to generate them automatically. Click on Source → Generate Getters and Setters).
• Method displayAddress() - returns a string that has the complete formatted address with
street address, city, state, and zip (you can choose how you want to format it).
• Method displayAddressLabel() - returns a string that has the Customer's name along with
the complete formatted address (you can choose how you want to format it).
Also create a TestCase class titled CustomerTest to test displayAddress and displayAddressLabel methods. Add this test case to Lab6TestSuite and run the tests. Make sure all tests are successful.
Assertion Statement Reference
This is a list of the different types of assertion statements that are used to test your code. Any Java data type or object can be used in the statement. These assertions are from the JUnit API. Refer to the API for more details.
assertEquals(expected, actual)
assertEquals(message, expected, actual)
assertEquals(expected, actual, delta) - used on doubles or floats,
where delta is the difference in precision
assertEquals(message, expected, actual, delta) - used on doubles or floats,
where delta is the difference in precision
assertFalse(condition)
assertFalse(message, condition)
assertNotNull(object)
assertNotNull(message, object)
assertNotSame(expected, actual)
assertNotSame(message, expected, actual)
assertNull(object)
assertNull(message, object)
assertSame(expected, actual)
assertSame(message, expected, actual)
assertTrue(condition)
assertTrue(message, condition)
fail()
fail(message)
failNotEquals(message, expected, actual)
failNotSame(message, expected, actual)
failSame(message)

Deliverables:
Submit the following :
• Compress your Eclipse project titled as name-Lab6.zip 

Java, Programming

  • Category:- Java
  • Reference No.:- M983116

Have any Question?


Related Questions in Java

Chatbotscreate a small networked chat application that is

Chatbots Create a small, networked chat application that is populated by bots. Introduction On an old server park, filled with applications from the early days of the internet, a few servers still run one of the earliest ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

In relation to javaa what is constructor the purpose of

(In relation to Java) A. What is constructor? the purpose of default constructor? B. How do you get a copy of the object but not the reference of the object? C. What are static variables and instance variables? D. Compar ...

Project descriptionwrite a java program to traverse a

Project Description: Write a java program to traverse a directory structure (DirWalker.java) of csv files that contain csv files with customer info. A simple sample in provided in with the sample code but you MUST will r ...

Fundamentals of operating systems and java

Fundamentals of Operating Systems and Java Programming Purpose of the assessment (with ULO Mapping) This assignment assesses the following Unit Learning Outcomes; students should be able to demonstrate their achievements ...

Assessment -java program using array of Assessment -JAVA Program using array of objects

Assessment -JAVA Program using array of objects Objectives This assessment item relates to the course learning outcomes as stated in the Unit Profile. Details For this assignment, you are required to develop a Windowed G ...

Applied software engineering assignment 1 -learning

Applied Software Engineering Assignment 1 - Learning outcomes - 1. Understand the notion of software engineering and why it is important. 2. Analyse the risk factors associated with phases of the software development lif ...

Retail price calculatorwrite a java program that asks the

Retail Price Calculator Write a JAVA program that asks the user to enter an item's wholesale cost and its markup percentage. It should then display the item's retail price. For example: (If an item's wholesale cost is 5. ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As