Question

In: Computer Science

Complete the following Customer class below. Also, add the equals method that would compare each field....

Complete the following Customer class below. Also, add the equals method that would compare each field.

Please pay attention to the format of the equals method as it needs to have the same format as shown below.

public class Customer {

      private int id; //customer id

      private String name; //customer's name

      private int discount; //discount rate in percent

     

      //construct a new customer

      public Customer(int id, String name, int discount) {

            

      }

      //returns the field values

      public int getId () {

            

             }

     

      public String name () {

            

             }

     

      public int discount () {

            

             }

     

      //returns String for customer. Eg: "Mary, id:1111, discount 10%"

     

      public String toString () {

            

      }

     

      public boolean equals (Object other) {

      if (other instanceof some_class) {

             //do casting

             return logical_statement_for_comparison;

      } else {

             return false;

      }

      }

Solutions

Expert Solution

package assignment1;

public class Customer {

    private int id; //customer id

    private String name; //customer's name

    private int discount; //discount rate in percent

    public Customer(int id, String name, int discount) {
        this.id = id;
        this.name = name;
        this.discount = discount;
    }


    //returns the field values

    public int getId() {
        return id;
    }


    public String name() {
        return name;
    }


    public int discount() {
        return discount;
    }


    //returns String for customer. Eg: "Mary, id:1111, discount 10%"


    public String toString() {
        return name+", id:"+id+", discount "+discount+"%";

    }


    public boolean equals(Object other) {

        if (other instanceof Customer) {

            //do casting
            other = (Customer) other;

            return (((Customer) other).id == id) && (((Customer) other).discount == discount) && (((Customer) other).name.equals(name));

        } else {

            return false;

        }

    }
}

Related Solutions

Add the following method below to the CardDeck class, and create a test driver to show...
Add the following method below to the CardDeck class, and create a test driver to show that they work correctly. int cardsRemaining() //returns a count of the number of undealt cards remaining in the deck. Complete in Java programming language. // Models a deck of cards. Includes shuffling and dealing. //---------------------------------------------------------------------- package Homework4; import java.util.Random; import java.util.Iterator; import javax.swing.ImageIcon; public class CardDeck { public static final int NUMCARDS = 52; protected ABList<Card> deck; protected Iterator<Card> deal; public CardDeck() { deck...
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...
Please add the following method as a part of the UnorderedList class definition: •print_list: the method...
Please add the following method as a part of the UnorderedList class definition: •print_list: the method prints the elements of the list using the same format as a Python list (square brackets and commas as separators). In the main function of the modified UnorderedList.py, please test the new method to demonstrate that it works as expected. Please leave comments in the code to show what is done UnorderList.py file # Implementation of an Unordered List ADT as a linked list....
Add a CountGroups method to the linked list class below (OurList). It returns the number of...
Add a CountGroups method to the linked list class below (OurList). It returns the number of groups of a value from the list. The value is passed into the method. A group is one or more values. Examples using strings: A list contains the following strings: one, one, dog, dog, one, one, one, dog, dog, dog, dog, one, one, dog, one    CountGroup(“one”) prints 4 groups of one's    CountGroup(“dog”) prints 3 groups of dog's Do not turn in the...
Add a CountGroups method to the linked list class below (OurList). It returns the number of...
Add a CountGroups method to the linked list class below (OurList). It returns the number of groups of a value from the list. The value is passed into the method. A group is one or more values. Examples using strings: A list contains the following strings: one, one, dog, dog, one, one, one, dog, dog, dog, dog, one, one, dog, one    CountGroup(“one”) prints 4 groups of one's    CountGroup(“dog”) prints 3 groups of dog's Do not turn in the...
USING JAVA: complete the method below in the BasicBioinformatics class. /** * Class BasicBioinformatics contains static...
USING JAVA: complete the method below in the BasicBioinformatics class. /** * Class BasicBioinformatics contains static methods for performing common DNA-based operations in * bioinformatics. * * */ public class BasicBioinformatics { /** * Calculates and returns the number of times each type of nucleotide occurs in a DNA sequence. * * @param dna a char array representing a DNA sequence of arbitrary length, containing only the * characters A, C, G and T * * @return an int array...
Complete java program below. Complete non-recursive version nthFibonacciWithLoop() method. Complete recursive version nthFibonacciWithRecursion() method. public class...
Complete java program below. Complete non-recursive version nthFibonacciWithLoop() method. Complete recursive version nthFibonacciWithRecursion() method. public class Fibonacci { // Fib(N): N N = 0 or N = 1 // Fib(N-1) + Fib(N-2) N > 1 // For example, // Fib(0) = 0 // Fib(1) = 1 // Fib(2) = Fib(1) + Fib(0) = 1 + 0 = 1 // Fib(3) = Fib(2) + Fib(1) = Fib(2) + 1 = (Fib(1) + Fib(0)) + 1 = 1 + 0 + 1...
To the TwoDArray class, add a method called sumCols() that sums the elements in each column...
To the TwoDArray class, add a method called sumCols() that sums the elements in each column and displays the sum for each column. Add appropriate code in main() of the TwoDArrayApp class to execute the sumCols() method. /** * TwoDArray.java */ public class TwoDArray { private int a[][]; private int nRows; public TwoDArray(int maxRows, int maxCols) //constructor { a = new int[maxRows][maxCols]; nRows = 0; } //****************************************************************** public void insert (int[] row) { a[nRows] = row; nRows++; } //****************************************************************** public...
Given the LinkedStack Class as covered in class add a method to the LinkedStack class called...
Given the LinkedStack Class as covered in class add a method to the LinkedStack class called PushBottom which will add a new item to the bottom of the stack. The push bottom will increase the number of items in the stack by 1
Also please add comments on the code and complete in C and also please use your...
Also please add comments on the code and complete in C and also please use your last name as key. The primary objective of this project is to increase your understanding of the fundamental implementation of Vigenere Cipher based program to encrypt any given message based on the Vignere algorithm. Your last name must be used as the cipher key. You also have to skip the space between the words, while replicating the key to cover the entire message. Test...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT