Question

Haviing trouble with my homework (java) 1)Write the class CustomerAccount, which has fields/attributes called custID of...

Haviing trouble with my homework

(java)

1)Write the class CustomerAccount, which has fields/attributes called custID of type String, custName of type String and checkingBalance of type double and savingBalance of type double

2)Write the constructor for CustomerAccount class. The constructor takes parameters to initialize custID, custName, checkingBalance and savingBalance.

3)Write the mutator method for all attributes of the class CustomerAccount. then Write the toString method for class CustomerAccount.

Homework Answers

Answer #1

I have created a project named CustomerAccount in NetBeans IDE.

package customeraccount;

public class CustomerAccount {

    String custID;
    String custName;
    double checkingBalance;
    double savingBalance;

    //default constructor
    public CustomerAccount() {
        this.custID = "";
        this.custName = "";
        this.checkingBalance = 0;
        this.savingBalance = 0;
    }

    //parameterized constructor
    public CustomerAccount(String custID, String custName, double checkingBalance, double savingBalance) {
        this.custID = custID;
        this.custName = custName;
        this.checkingBalance = checkingBalance;
        this.savingBalance = savingBalance;
    }

    //mutator method for custID 
    public void setCustID(String custID) {
        this.custID = custID;
    }

    //mutator method for custName 
    public void setCustName(String custName) {
        this.custName = custName;
    }

    //mutator method for checkingBalance 
    public void setCheckingBalance(double checkingBalance) {
        this.checkingBalance = checkingBalance;
    }

    //mutator method for savingBalance 
    public void setSavingBalance(double savingBalance) {
        this.savingBalance = savingBalance;
    }

    //tostring method
    @Override
    public String toString() {
        return "CustomerAccount{" + "custID=" + custID + ", custName=" + custName + ", checkingBalance=" + checkingBalance + ", savingBalance=" + savingBalance + '}';
    }

    //accessor method for custID
    public String getCustID() {
        return custID;
    }

    //accessor method for custName
    public String getCustName() {
        return custName;
    }

    //accessor method for checkingBalance
    public double getCheckingBalance() {
        return checkingBalance;
    }

    //accessor method for savingBalance
    public double getSavingBalance() {
        return savingBalance;
    }

    public static void main(String[] args) {
        
        //reate object of CustomerAccount class 
        //invoke parameterized constructor and set value
        CustomerAccount c = new CustomerAccount("A1","Henry",1000.0,500.3);
        
        //invoke mutator of custName
        c.setCustName("David");
        
        //print the result returned by accessor of savingBalance
        System.out.println("SavingBalance: "+ c.getSavingBalance());
        
        //print the result returned by toString() method
        System.out.println("" + c.toString());   
       }
}

OUTPUT:

Know the answer?
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
Similar Questions
Write the following problem in Java Create a class Dog, add name, breed, age, color as...
Write the following problem in Java Create a class Dog, add name, breed, age, color as the attributes. You need to choose the right types for those attributes. Create a constructor that requires no arguments. In this constructor, initialize name, breed, age, and color as you wish. Define a getter and a setter for each attribute. Define a method toString to return a String type, the returned string should have this information: “Hi, my name is Lucky. I am a...
Java: Write a class Cow with attributes name (string) and numLegs (int). Do not make the...
Java: Write a class Cow with attributes name (string) and numLegs (int). Do not make the attributes private. Make a constructor with two parameters to instantiate the attributes, and a toString method that prints only the name, a comma, a space, and the number of legs (e.g. Bossie, 3). Add a main method that makes two cows, Bossie with 3 legs and Elsie with 4 legs, and puts them into an ArrayList. Print the ArrayList, one element per line, using...
The following is for a Java Program Create UML Class Diagram for these 4 java classes....
The following is for a Java Program Create UML Class Diagram for these 4 java classes. The diagram should include: 1) All instance variables, including type and access specifier (+, -); 2) All methods, including parameter list, return type and access specifier (+, -); 3) Include Generalization and Aggregation where appropriate. Java Classes description: 1. User Class 1.1 Subclass of Account class. 1.2 Instance variables __ 1.2.1 username – String __ 1.2.2 fullName – String __ 1.2.3 deptCode – int...
JAVA Write a Student class with a String name and double gpa class members. Write a...
JAVA Write a Student class with a String name and double gpa class members. Write a constructor, get and set methods, and a toString method.
in JAVA Write a class Store which includes the attributes: store name and sales tax rate....
in JAVA Write a class Store which includes the attributes: store name and sales tax rate. Write another class encapsulating a Yarn Store, which inherits from Store. A Yarn Store has the following additional attributes: how many skeins of yarn are sold every year and the average price per skein. Code the constructor, accessors, mutators, toString and equals method of the super class Store and the subclass Yarn Store; In the Yarn Store class, also code a method returning the...
Please show fully functioning java code and outputs. Design a Java Animal class (assuming in Animal.java...
Please show fully functioning java code and outputs. Design a Java Animal class (assuming in Animal.java file) and a sub class of Animal named Cat (assuming in Cat.java file).   The Animal class has the following protected instance variables: boolean vegetarian, String eatings, int numOfLegs and the following public instance methods: constructor without parameters: initialize all of the instance variables to some default values constructor with parameters: initialize all of the instance variables to the arguments SetAnimal: assign arguments to all...
Part 1 Given the following code: public class MyClass { private double score; private String studentID;...
Part 1 Given the following code: public class MyClass { private double score; private String studentID; //code of the class ..... } //end of MyClass Code a default constructor and an overloaded constructor of MyClass that will assign values to its two instance fields: Please write in JAVA Part 2 Continue from question about, code an mutator of instance field called studentID:
Write the Game class, Java lanuage. A Game instance is described by three instance variables: gameName...
Write the Game class, Java lanuage. A Game instance is described by three instance variables: gameName (a String), numSold (an integer that represents the number of that type of game sold), and priceEach (a double that is the price of each of that type of Game). I only want three instance variables!! The class should have the following methods: A constructor that has two parameter – a String containing the name of the Game and a double containing its price....
Write a Java class called Rectangle that represents a rectangular two-dimensional region. It should have following...
Write a Java class called Rectangle that represents a rectangular two-dimensional region. It should have following 4 fields: int x (x-coordinate for its top left corner) int y (y coordinate for its top left corner) double height (height of the rectangle) double width (width of the rectangle) Your rectangle objects should have the following methods: public Rectangle(int newx, int newy, int newwidth, int newheight) Constructor that initializes the x-coordinate, y-coordinate for the top left corner and its width and height....
1. Circle: Implement a Java class with the name Circle. It should be in the package...
1. Circle: Implement a Java class with the name Circle. It should be in the package edu.gcccd.csis. The class has two private instance variables: radius (of the type double) and color (of the type String). The class also has a private static variable: numOfCircles (of the type long) which at all times will keep track of the number of Circle objects that were instantiated. Construction: A constructor that constructs a circle with the given color and sets the radius to...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT