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...
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...
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....
JAVA Learning Objectives: To be able to code a class structure with appropriate attributes and methods....
JAVA Learning Objectives: To be able to code a class structure with appropriate attributes and methods. To demonstrate the concept of inheritance. To be able to create different objects and use both default and overloaded constructors. Practice using encapsulation (setters and getters) and the toString method. Create a set of classes for various types of video content (TvShows, Movies, MiniSeries). Write a super or parent class that contains common attributes and subclasses with unique attributes for each class. Make sure...
Java programming. Write a public Java class called WriteToFile that opens a file called words.dat which...
Java programming. Write a public Java class called WriteToFile that opens a file called words.dat which is empty. Your program should read a String array called words and write each word onto a new line in the file. Your method should include an appropriate throws clause and should be defined within a class called TextFileEditor. The string should contain the following words: {“the”, “quick”, “brown”, “fox”}
Use the class definition below to answer the following questions. public class TrafficLight { String stopLight...
Use the class definition below to answer the following questions. public class TrafficLight { String stopLight = "red"; String waitLight; String goLight; public void setStopLight(String colour) { stopLight = colour; } public String getGreenLight() { return goLight; } } 1. How many field attributes are there in the TrafficLight class? 2. Name a field attribute for this class. 3. What is the name of the method that is an accessor? 4. What is the name of the method that is...
Use the class definition below to answer the following questions. [Total 8 Marks] public class TrafficLight...
Use the class definition below to answer the following questions. [Total 8 Marks] public class TrafficLight { String stopLight = "red"; String waitLight; String goLight; public void setStopLight(String colour) { stopLight = colour; } public String getGreenLight() { return goLight; } } 1 :How many field attributes are there in the TrafficLight class? 2 :Name a field attribute for this class. 3 :What is the name of the method that is an accessor? 4 :What is the name of the...
Shapes2D Write the following four classes to practice using an abstract class and polymorphism. Submit all...
Shapes2D Write the following four classes to practice using an abstract class and polymorphism. Submit all four classes. Shape2D class For this class, include just an abstract method name get2DArea() that returns a double. Rectangle2D class Make this class inherit from the Shape2D class. Have it store a length and a width as fields. Provide a constructor that takes two double arguments and uses them to set the fields. Note, the area of a rectangle is the length times the...