Question

Complete the following definition of the method below so that it creates and returns an array of 10 InterestAccount objects.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you will feel any problem with the solution, then feel free to ask it in comments.

Happy Learning

public class HomeworkLib16

{

public static void main(String[] args)

{

InterestAccount[] Sample = createSampleInterestAccounts();

display(Sample);

}

public static InterestAccount[] createSampleInterestAccounts()

{

// IA[] is an array of 10 InterestAccount objects

InterestAccount[] IA = new InterestAccount[10];

// Initial customer number and balance for 1st customer

int customer_no = 0;

int bal = 2000;

// run the loop upto,all 10 cusomers generated

while(customer_no<10)

{

// create InterestAccount for customer-i

IA[customer_no] = new InterestAccount();

// assign name

IA[customer_no].setName("customer"+Integer.toString(customer_no));

// assign banlance

IA[customer_no].setBalance(bal);

// assign interest_rate = 1.23 for customer0

if(customer_no==0)

IA[customer_no].setInterestRate((float)1.23);

// assign interest_rate = 4.56 for customers 1 to 9

else

IA[customer_no].setInterestRate((float)4.56);

// increase customer number by 1 for next customer

customer_no++;

// increase bal by 1000 for next customer

bal +=1000;

}

// ceturn array of InterestAccount

return IA;

}

// Display Accounts

public static void display(InterestAccount[] IA)

{

System.out.printf("%-15s%-15s%-15s\n","Name","Balance","Intrest Rate");

System.out.println("------------------------------------------");

for(int i=0; i<IA.length; ++i)

{

System.out.printf("%-15s%-15d%-15.2f\n",IA[i].getName(),IA[i].getBalane(),IA[i].getInterstRate());

}

System.out.println("------------------------------------------");

}

}

/*

* IntrestAccount is a class which stores the Account details

* It stores 3 things

* name: name of customer

* balance: the amount present in account

* intereste_rate: rate of interest in balance

* setter and getter methods for all variables

*/

class InterestAccount

{

private String name;

private int balance;

private float interest_rate;

public void setName(String name)

{

this.name = name;

}

public void setBalance(int balance)

{

this.balance = balance;

}

public void setInterestRate(float interest_rate)

{

this.interest_rate = interest_rate;

}

public String getName()

{

return this.name;

}

public int getBalane()

{

return this.balance;

}

public float getInterstRate()

{

return this.interest_rate;

}

}

Add a comment
Know the answer?
Add Answer to:
Complete the following definition of the method below so that it creates and returns an array...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Use the definition shown below for the "jumpSearch" method of the SkipSearch class. Notice that t...

    Use the definition shown below for the "jumpSearch" method of the SkipSearch class. Notice that the method is delcared static. Therefore, you do not need to create a new instance of the object before the method is called. Simply use "SkipSearch.jumpSearch(...)" with the appropriate 4 parameter values. When objects are compared, you should use the "compareTo" method as in the following example. item.compareTo(array[k]) However, not every type of object implements the compareTo method of the Comparable interface. This is resolved...

  • Check if an array is a heap in Java. Complete the method isHeapTree Together, these methods...

    Check if an array is a heap in Java. Complete the method isHeapTree Together, these methods are meant to determine if an array of objects corresponds to a heap. The methods are generic, and they should work with an array of any type T that implement Comparable<T>. Implement the second method so that it uses recursion to process the complete tree/subtree whose root is at position i in the array arr. The method should return true if that tree/subtree is...

  • he class definition for a Hank Account class, contains the following private data nembers: the name,...

    he class definition for a Hank Account class, contains the following private data nembers: the name, account number (both are character arrays of 30 elements each) alance, and interest rate Cbolth are double). It also have the following public member unctions Bank AccountO: This function is the default constructor. deposito: subsequently adjusts the balance. (balance- balance + amt) withdrawo: This function is passed an amount to withdraw and subsequently adjusts the balance. (balance balance- amt). cale interestO: This function calculates...

  • Java - data structures Suppose that in the array-based stack, the array doubles in size after...

    Java - data structures Suppose that in the array-based stack, the array doubles in size after multiple push operations. But later on, fewer than half of the array’s locations might actually be used by the stack due to pop operations. Revise the implementation so that its array also can shrink in size as objects are removed from the stack. Accomplishing this task will require two new private methods, as follows: The first new method checks whether we should reduce the...

  • Variable Size Array with Classes, Testing. Study Code and Object Definition Windows of Microsoft ...

    Variable Size Array with Classes, Testing. Study Code and Object Definition Windows of Microsoft Visual Studio described here. As you work on the below project, demonstrate to the instructor the usage of this feature. Create a project titled Lab11_VarArrayTest. Implement the dynamically expanding and contracting array of doubles described in the previous lab as a class. You should use this class definition. The class attributes are a pointer to the dynamically allocated array dAarray and the array size size This...

  • You will write the following files: mystack.h - contains the class definition for the mystack class....

    You will write the following files: mystack.h - contains the class definition for the mystack class. mystack.cpp - contains the definitions for member functions of the mystack class. inpost.cpp - contains your convert() function. inpost.h - contains the function prototype for convert() so that the main() can call it. Each of the files (with the exception of inpost.h) is described in more detail below. All header files should contain header guards to prevent them from being included multiple times in...

  • 3. Write Java methods to accomplish each of the following Write a method named simpleAry which...

    3. Write Java methods to accomplish each of the following Write a method named simpleAry which accepts and return nothing. It creates an array that can hold ten integers. Fill up each slot of the array with the number 113. Then, display the contents of the array on the screen. You must use a loop to put the values in the array and also to display them. Write a method named sury which accepts an array of type double with...

  • What if you had to write a program that would keep track of a list of...

    What if you had to write a program that would keep track of a list of rectangles? This might be for a house painter to use in calculating square footage of walls that need paint, or for an advertising agency to keep track of the space available on billboards. The first step would be to define a class where one object represents one rectangle's length and width. Once we have class Rectangle, then we can make as many objects of...

  • Need some help with this C++ code. Please screenshot the code if possible. Purpose: Demonstrate the...

    Need some help with this C++ code. Please screenshot the code if possible. Purpose: Demonstrate the ability to create and manipulate classes, data members, and member functions. This assignment also aims at creating a C++ project to handle multiple files (one header file and two .cpp files) at the same time. Remember to follow documentation and variable name guidelines. Create a C++ project to implement a simplified banking system. Your bank is small, so it can have a maximum of...

  • Lab Topics • The basics of Array object Use the following Coding Guidelines • When declaring...

    Lab Topics • The basics of Array object Use the following Coding Guidelines • When declaring a variable, you usually want to initialize it. Remember you cannot initialize a number with a string. Remember variable names are case sensitive. Use tabs or spaces to indent code within blocks (code surrounded by braces). Use white space to make your program more readable. Use comments after the ending brace of classes, methods, and blocks to identify to which block it belongs. Problem...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT