Question

1- Write a code for a banking program. a) In this question, first, you need to...

1- Write a code for a banking program.

a) In this question, first, you need to create a Customer class, this class should have:

• 2 private attributes: name (String) and balance (double)

• Parametrized constructor to initialize the attributes

• Methods:

i. public String toString() that gives back the name and balance

ii. public void addPercentage; this method will take a percentage value and

add it to the balance

b) Second, you will create a driver class and ask the user to enter 5 customers’ information

and then you will create an array of Customer objects.

c) Then you use this array used for various operations as shown in the output.

• Using the array of customer objects, you need to search for all customers who

have more than $100

• Using the array of customer objects, you need to get the average balance of the

balances in this array

• Using the array of customer objects, you need to get the customer with the

highest balance

• Using the array of customer objects, you need to show all accounts after a 5%

balance increase

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

Hello,

The code is given below as well as the screenshots of compiled and executed program.

_____________________________________________________________________

//Customer Class ----------------------------------

public class Customer {

private String name;

private double balance;

public Customer(String name, double balance ){

this.name = name;

this.balance = balance;

}

public Customer() {

// TODO Auto-generated constructor stub

}

public String toString(Customer objs[]){

String res = "";

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

//Storing all the information in a string

res = res + objs[i].name +" \t " + Double.toString(objs[i].balance) + "\n";

}

return res;

}

public void addPercentage(Customer objs[], double percentValue){

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

//Adding the percentage

objs[i].balance = objs[i].balance + (objs[i].balance*percentValue/100);

}

}

}

//Driver Class----------------------------------

import java.util.Scanner;

public class Driver {

public static void main(String args[]){

Scanner sc = new Scanner(System.in);

Customer cs = new Customer();

System.out.println("Enter the Customers Information:");

Customer customers[] = new Customer[5];

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

String name = sc.next();

double balance = sc.nextDouble();

customers[i] = new Customer(name,balance);

}

// To fetch all the records

String result = cs.toString(customers);

String data[] = result.split("\n");

// To find all customers having balance more than 100

System.out.println("\nCustomers with balance more than $100");

System.out.println("Name \t Balance");

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

String temp[] = data[i].split("\t");

if(Double.parseDouble(temp[1]) > 100){

System.out.println(data[i]);

}

}

//To find the average balance

double avg = 0;

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

String temp[] = data[i].split("\t");

avg += Double.parseDouble(temp[1]);

}

avg = avg / customers.length;

System.out.println("\nThe average balance is = " + avg);

// To find the customer with highest balance

double max = Double.MIN_VALUE;

int maxIndex = -1;

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

String temp[] = data[i].split("\t");

double bal = Double.parseDouble(temp[1]);

if(bal > max){

max = bal;

maxIndex = i;

}

}

System.out.println("\nThe user with Maximum balance is");

System.out.println("Name \t Balance");

System.out.println(data[maxIndex]);

//Increase balance with 5% to all users

cs.addPercentage(customers,5d);

result = cs.toString(customers);

System.out.println("\nBalance of all customers after adding 5% of balance");

System.out.println("\nName \t Balance");

System.out.println(result);

}

}

______________________________________________________________________________________________

____________________________________________________________________________________________

Please give yours valuable feedback.

Thanks.

Add a comment
Know the answer?
Add Answer to:
1- Write a code for a banking program. a) In this question, first, you need to...
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
  • Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the...

    Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the concept of a college course, assuming that a course has following attributers: code (for instance COSC1337), a description, and a number of credits (for instance 3). Include a constructor, the accessors, mutators and methods ‘toString’, ‘equals’, and ‘finalize’. Write a client class to test the behavior of the class and its methods. The outline of the class is given as follows: public class Course...

  • In Java Code Needed is Below the Question Using Program 3: Encapsulating Dogs, modify this program...

    In Java Code Needed is Below the Question Using Program 3: Encapsulating Dogs, modify this program to create a database of dogs of your own. You will also include File I/O with this program. You will create 3 classes for this assignment. The first class: Create a Class representing the information that is associated with one item (one dog) of your database. Name this class Dog. Using Lab 3, this will include the information in regard to one dog. The...

  • Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram)

    Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram) Author -name:String -email:String -gender:char +Author(name:String, email:String, gender:char) +getName():String +getEmail):String +setEmail (email:String):void +getGender():char +tostring ):String . Three private instance variables: name (String), email (String), and gender (char of either 'm' or 'f'): One constructor to initialize the name, email and gender with the given values . Getters and setters: get Name (), getEmail() and getGender (). There are no setters for name and...

  • Instructions Using the BCException.java and the BankCustomer.java from the first part of the assignment you will...

    Instructions Using the BCException.java and the BankCustomer.java from the first part of the assignment you will implement a driver class called Bank.java to manipulate an ArrayList of BankCustomer objects. Your code should read bank customers’ information from the user. It will then create a bank customer objects and add them to an arraylist in a sorted fashion (sorted by account number). The arraylist should be sorted in ascending order at all times. The arraylist should not contain null objects at...

  • Here is a sample run of the tester program: Make sure your program follows the Java...

    Here is a sample run of the tester program: Make sure your program follows the Java Coding Guidelines. Consider the following class: /** * A store superclass with a Name and Sales Tax Rate */ public class Store {      public final double SALES_TAX_RATE = 0.06;      private String name;           /**      * Constructor to create a new store      * @param newName      */      public Store(String newName)      {           name = newName;      }     ...

  • Book: - title: String - price: double +Book() +Book(String, double) +getTitle(): String +setTitle(String): void +getPrice(): double...

    Book: - title: String - price: double +Book() +Book(String, double) +getTitle(): String +setTitle(String): void +getPrice(): double +setPrice(double): void +toString(): String The class has two attributes, title and price, and get/set methods for the two attributes. The first constructor doesn’t have a parameter. It assigns “” to title and 0.0 to price; The second constructor uses passed-in parameters to initialize the two attributes. The toString() method returns values for the two attributes. Notation: - means private, and + means public. 1....

  • Use inheritance to create a new class AudioRecording based on Recording class that: it will retain...

    Use inheritance to create a new class AudioRecording based on Recording class that: it will retain all the members of the Recording class, it will have an additional field bitrate (non-integer numerical; it cannot be modified once set), its constructors (non-parametrized and parametrized) will set all the attributes / fields of this class (reuse code by utilizing superclass / parent class constructors): Non-parametrized constructor should set bitrate to zero, If arguments for the parametrized constructor are illegal or null, it...

  • code in java please:) Part I Various public transporation can be described as follows: A PublicTransportation...

    code in java please:) Part I Various public transporation can be described as follows: A PublicTransportation class with the following: ticket price (double type) and mumber of stops (int type). A CityBus is a PublicTransportation that in addition has the following: an route number (long type), an begin operation year (int type), a line name (String type), and driver(smame (String type) -A Tram is a CityBus that in addition has the following: maximum speed (int type), which indicates the maximum...

  • In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in...

    In a project named 'DogApplication', create a class called 'Dog' 1. declare two instance variables in 'Dog' : name (String type) age (int type) 2. declare the constructor for the 'Dog' class that takes two input parameters and uses these input parameters to initialize the instance variables 3. create another class called 'Driver' and inside the main method, declare two variables of type 'Dog' and call them 'myDog' and 'yourDog', then assign two variables to two instance of 'Dog' with...

  • I have a java class that i need to rewrite in python. this is what i...

    I have a java class that i need to rewrite in python. this is what i have so far: class Publisher: __publisherName='' __publisherAddress=''    def __init__(self,publisherName,publisherAddress): self.__publisherName=publisherName self.__publisherAddress=publisherAddress    def getName(self): return self.__publisherName    def setName(self,publisherName): self.__publisherName=publisherName    def getAddress(self): return self.__publisherAddress    def setAddress(self,publisherAddress): self.__publisherAddress=publisherAddress    def toString(self): and here is the Java class that i need in python: public class Publisher { //Todo: Publisher has a name and an address. private String name; private String address; public Publisher(String...

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