Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a class \"customer\" that has data fields \"name\" and \"lastName.\" In ad

ID: 3848081 • Letter: W

Question

Write a class "customer" that has data fields "name" and "lastName." In addition, the accessor methods "get name" and "get last name" should print out the customer name. The class should contain a nested class CreditCard that has a single method "pay." The CreditCard method "pay" should print "Paid." The customer class constructor should take in parameters "name" and "last name." The customer class should have a method "pay" that calls the nested class pay method. Create a test customer class that instigates the constructor and then calls the pay customer method.

Explanation / Answer

package sample1;

import java.util.Scanner;

import java.io.*;

public class testcustomer {

    public static void main(String args[]) throws IOException
     {
       Customer c=new Customer("john","lewis");
       System.out.println(c.getName()+" "+c.getLastName()+" ");
       c.pay();
       }
}

package sample1;

public class Customer {
private String name;
private String lastName;
public Customer(String name, String lastName) {
   super();
   this.name = name;
   this.lastName = lastName;
}
public Customer(){
  
}
public String getName() {
   return name;
}
public void setName(String name) {
   this.name = name;
}
public String getLastName() {
   return lastName;
}
public void setLastName(String lastName) {
   this.lastName = lastName;
}
//nested class start
public class CreditCard{
   public String pay(){
       return "Paid";
   }
}
//nested class end

public void pay(){
   System.out.println(new CreditCard().pay());
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote