Answer to Question #275159 in Java | JSP | JSF for joy

Question #275159

The Customer class models a customer using as shown in the class diagram below. Write the codes for the Customer class and a test driver to test all the public methods. Note that a discount is given as a percentage. The toString() method should output the customer information including the ID, name and discount

1
Expert's answer
2021-12-04T01:28:03-0500


SOLUTION CODE


package com.company;

class Customer {
    private String name;
    private int ID;
    private int discount;

            //constructor to set the values
    public Customer(String name, int ID, int discount) {
        this.name = name;
        this.ID = ID;
        this.discount = discount;
    }

    //defining the to string method
    public String toString(){//overriding the toString() method  
        return this.name + ", ID " +   this.ID + "discount"+discount+ "%";
    }
   
}
//driver class
class Main {
    public static void main(String[] args)
    {
       Customer c = new Customer("kelly", 100, 10);
       c.toString();
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS