Question

(JAVA) Create a class that represents a Customer. Use good OO programming technique. A Customer has...

(JAVA) Create a class that represents a Customer. Use good OO programming technique. A Customer has a firstName, lastName, customerNumber, emailAddress. You can add some more fields if you want to, but those 4 are a minimum. Override the equals method, and the toString method from the Object class. Implement the Comparable interface. In the main method, create some instances of the Customer class, and demonstrate the use of the accessor and mutator methods, as well as the compareTo method.

Homework Answers

Answer #1

public class HelloWorld{
  
public class Customer
{
private String firstName;
private String lastName;
private int customerNumber;
private String emailAddress;
/* default constructor
public Customer()
{
firstName = "";
lastName = "";
customerNumber = -1;
emailAddress = "";
}*/
//constructor with parameter
public Customer(String firstName, String lastName, int customerNumber, String emailAddress)
{
this.firstName = firstName;
this.lastName = lastName;
this.customerNumber = customerNumber;
this.emailAddress = emailAddress;
}
//accessor for firstName
public String getfirstName()
{
return firstName;
}
//Mutator for firstName
public void setfirstName( String fname )
{
firstName = fname;
}
//accessor for lastName
public String getlastName()
{
return lastName;
}
//Mutator for lastName
public void setlastName( String lname )
{
firstName = lname;
}
//accessor for customerNumber
public int getcustomerNumber()
{
return customerNumber;
}
//Mutator for customerNumber
public void setcustomerNumber( int num )
{
customerNumber = num;
}
//accessor for emailAddress
public String getemailAddress()
{
return emailAddress;
}
//Mutator for emailAddress
public void setemailAddress( String add )
{
emailAddress = add;
}
@Override
public boolean equals(Object c){
if(c == null) return false;
if(!(c instanceof Customer)) return false;
Customer other = (Customer) c;
if(this.customerNumber != other.customerNumber) return false;
if(!this.firstName.equals(other.firstName)) return false;
if(! this.lastName.equals(other.lastName)) return false;
if(! this.emailAddress.equals(other.emailAddress)) return false;
return true;
}
@Override
public String toString(){
String r = getcustomerNumber() + " " + getfirstName() + " " + getlastName()+ " " + getemailAddress();
return r;
}
  
}
public static void main(String []args){
Customer cus = new Customer("A","B",123,"[email protected]");
//cus.setfirstName("A");
//cus.setlastName("B");
//cus.setcustomerNumber(125331);
//cus.emailAddress("[email protected]");
System.out.println(cus.toString(cus));
}
}

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
Consider the following incomplete declaration of a Name class for 2a-2c. public class Name something missing...
Consider the following incomplete declaration of a Name class for 2a-2c. public class Name something missing {    private String first;    private String last;    public Name(String firstName, String lastName)    { first = firstName; last = lastName;    }    //additional methods } 2a) In the first two parts, you will modify the Name class so that it implements the Comparable interface. Show here what should go in place of something missing in the first line of the...
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...
Use Java: Also: Please include screenshots if possible. Create a class called AbstractStackTest. Write an abstract...
Use Java: Also: Please include screenshots if possible. Create a class called AbstractStackTest. Write an abstract method called makeStack that returns a Stack of Strings. Use the Stack interface as the return type, not a specific implementation! Write a class named NodeStackTest that extends your AbstractStackTest class. Implement the makeStack method to return a NodeStack. Repeat parts 1 and 2 for the Queue interface and the NodeQueue implementation. Write a new stack implementation, ArrayStack. It should be generic and use...
*OBJECT ORIENTED PROGRAMMING* * JAVA PROGRAMMING* Create a program that simulates a race between several vehicles....
*OBJECT ORIENTED PROGRAMMING* * JAVA PROGRAMMING* Create a program that simulates a race between several vehicles. Details don't matter must have the following: Design and implement an inheritance hierarchy that includes Vehicle as an abstract superclass and several subclasses. Include a document containing a UML diagram describing your inheritance hierarchy Include at least one interface that contains at least one method that implementing classes must implement. Include functionality to write the results of the race to a file; this will...
(Please use java to write these questions) Q1. Create a class on an object Computer with...
(Please use java to write these questions) Q1. Create a class on an object Computer with two fields and two methods as follows: (5 points) field: cpu and memory, method: compile( ) and execute( ) Q2. Write a source code to activate a class created in Q1. (5 points)
in jGRASP INVENTORY CLASS You need to create an Inventory class containing the private data fields,...
in jGRASP INVENTORY CLASS You need to create an Inventory class containing the private data fields, as well as the methods for the Inventory class (object). Be sure your Inventory class defines the private data fields, at least one constructor, accessor and mutator methods, method overloading (to handle the data coming into the Inventory class as either a String and/or int/float), as well as all of the methods (methods to calculate) to manipulate the Inventory class (object). The data fields...
C# programming Create a class called QuadraticEq that has a custom constructor that takes in a,...
C# programming Create a class called QuadraticEq that has a custom constructor that takes in a, b and c as the quadratic equation coefficients. Implement also the following: A readonly property double Discriminant that represents discriminant to the equation A method double[] GetRealRoots() that returns an array of the real roots of the equation; size can be 2, 1 or 0 Please pay attention to encapsulation concerns. Use your created class in the following way inside a Main method to...
Create a simple Java class for a Month object with the following requirements:  This program...
Create a simple Java class for a Month object with the following requirements:  This program will have a header block comment with your name, the course and section, as well as a brief description of what the class does.  All methods will have comments concerning their purpose, their inputs, and their outputs  One integer property: monthNumber (protected to only allow values 1-12). This is a numeric representation of the month (e.g. 1 represents January, 2 represents February,...
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...
loanCreator.java: /* * Use constants when necessary, define with proper scope * * Create Person class...
loanCreator.java: /* * Use constants when necessary, define with proper scope * * Create Person class with data fields of firstName and lastName these fields can not change. * * Create Loan class with data fields of Person, loan Amount, term and interest rate * If term is not past in then default value is 36 * If interest is not past in then default value is 5.0 * * In Loan class create method to construct output String *...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT