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...
Casting class objects 1.2 Compile and execute the code listed below as it is written. Run...
Casting class objects 1.2 Compile and execute the code listed below as it is written. Run it a second time after uncommenting the line obj.speak();. public class AnimalRunner {    public static void main(String[] args)    {       Dog d1 = new Dog("Fred");       d1.speak();       Object obj = new Dog("Connie");       // obj.speak();    } } The uncommented line causes a compile error because obj is an Object reference variable and class Object doesn’t contain a speak() method. This...
Design a class with the following requirements: 1- give the class a name from your choice....
Design a class with the following requirements: 1- give the class a name from your choice. 2- write some code that creates three instance variables, choose a name and type for each one of them. (must have two private and one public variables) 3- Initialize the variables using two different constructors. 4- Use mutator and accessor methods (set and get) for the private data members. 5- Display the value of each member variable using a method. 6- In the main,...
Java Programming In this lab students continue to write programs using multiple classes. By the end...
Java Programming In this lab students continue to write programs using multiple classes. By the end of this lab, students should be able to Write classes that use arrays and ArrayLists of objects as instance variables Write methods that process arrays and ArrayLists of objects Write getter and setter methods for instance variables Write methods using object parameters and primitive types Question- class StringSet. A StringSet object is given a series of up to 10 String objects. It stores these...
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...
Classes/ Objects(programming language java ) in software (ATOM) Write a Dice class with three data fields...
Classes/ Objects(programming language java ) in software (ATOM) Write a Dice class with three data fields and appropriate types and permissions diceType numSides sideUp The class should have A 0 argument (default) constructor default values are diceType: d6, numSides: 6, sideUp: randomValue 1 argument constructor for the number of sides default values are diceType: d{numSides}, sideUp: randomValue 2 argument constructor for the number of sides and the diceType appropriate accessors and mutators *theoretical question: can you change the number of...
Complete the redblacktree in Java. Add a public boolean isBlack field to the Node inner class....
Complete the redblacktree in Java. Add a public boolean isBlack field to the Node inner class. Make every Node object have a false isBlack field, all new node is red by default. In the end of the insert method, set the root node of your red black tree to be black. Implement the rotate() and recolor() functions, and create tests for them in a separate class. import java.util.LinkedList; public class BinarySearchTree<T extends Comparable<T>> { protected static class Node<T> { public...
In java create a dice game called sequences also known as straight shooter. Each player in...
In java create a dice game called sequences also known as straight shooter. Each player in turn rolls SIX dice and scores points for any sequence of CONSECUTIVE numbers thrown beginning with 1. In the event of two or more of the same number being rolled only one counts. However, a throw that contains three 1's cancels out player's score and they mst start from 0. A total of scores is kept and the first player to reach 100 points,...
***Programming language is Java. After looking at this scenario please look over the requirements at the...
***Programming language is Java. After looking at this scenario please look over the requirements at the bottom (in bold) THIS IS ALL THAT WAS PROVIDED. PLEASE SPECIFY ANY QUESTIONS IF THIS IS NOT CLEAR (don't just say more info, be specific)*** GMU in partnership with a local sports camp is offering a swimming camp for ages 10-18. GMU plans to make it a regular event, possibly once a quarter. You have been tasked to create an object-oriented solution to register,...
Cpp Task: Create a class called Mixed. Objects of type Mixed will store and manage rational...
Cpp Task: Create a class called Mixed. Objects of type Mixed will store and manage rational numbers in a mixed number format (integer part and a fraction part). Details and Requirements Your class must allow for storage of rational numbers in a mixed number format. Remember that a mixed number consists of an integer part and a fraction part (like 3 1/2 – “three and one-half”). The Mixed class must allow for both positive and negative mixed number values. A...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT