Design a class named Person with fields for holding a person

Design a class named Person with fields for holding a person\'s name , address, and
telephone number (all as Strings ). Write a constructor that initializes all of these
values , and mutator and accessor methods for every field.

Next, design a class named Customer, which inherits from the Person class . The Customer
class should have a String field for the customer number and a boolean field indicating
whether the customer wishes to be on a mailing list. Write a constructor that
initializes these values and the appropriate mutator and accessor methods for
the class \'s fields.

Demonstrate the Customer class in a program that prompts the user to enter values
for the customer\'s name , address, phone number, and customer number, and then
asks the user whether or not the customer wants to recieve mail. Use this information
to create a customer object and then print its information.

Put all of your classes in the same file. To do this, do not declare them public.
Instead, simply write:

class Person { ... }
class Customer { ... }

SAMPLE RUN #1: java Driver

Standard Output

Enter·name·of·customer:Enter·address·of·customer:Enter·phone·number·of·customer:Enter·customer·number:Enter·yes/no·--·does·the·customer·want·to·recieve·mail?:
Customer:·
Name:·Julia·Stevens
Address:·77·Massachusetts·Ave·Cambridge,·MA·02139
Phone·Number:·617-777-7777
Customer·Number:·928734502
Recieve·Mail?:·false

What is wrong with this code:

import java.util.Scanner;
class Person {
   private String name;
   private String address;
   private String number;
   public Person(String name, String address, String number)
   {
   super();
   this.name = name;
   this.address = address;
   this.number = number;
   }
   public String getName()
   {
   return name;
   }
   public void setName(String name)
   {
   this.name = name;
   }
   public String getAddress()
   {
   return address;
    
   }
   public void setAddress(String a)
   {
   address = a;
    
   }
   public String getNumber()
   {
   return number;
   }
   public void setNumber(String number){
   this.number = number;
   }

}
class Customer extends Person {
   private String custNumber;
   private boolean wants;
   public Customer(String name, String address, String number, String custNumber, boolean wants)
   {
   super(name, address, number);
   this.custNumber = custNumber;
   this.wants = wants;
   }
    
   public String getcustNumber()
   {
   return custNumber;
   }
   public boolean isWants()
   {
   return wants;
   }
   public void setWants(boolean wants)
   {
   this.wants = wants;
   }
}
class Driver {

       public static void main(String[] args) {
           String name, address, number;
   String custNumber;
   String decide;
   String decision;
   boolean wants = false;
   Scanner keyboard = new Scanner(System.in);
   System.out.print(\"Enter name of customer:Enter address of customer:Enter phone number of customer:Enter yes/no -- does the customer want to recieve mail?:\");
   System.out.println(\"Customer:\");
   System.out.print(\"Name:\");

   name = keyboard.nextLine();
   System.out.print(\"Address:\");
   address = keyboard.nextLine();
   System.out.print(\"Phone Number:\");
   number = keyboard.nextLine();
   System.out.print(\"Customer Number:\");
   custNumber = keyboard.nextLine();
   System.out.print(\"Recieve Mail?:\");
   decide = keyboard.nextLine();

   Customer one = new Customer(name, address, number, custNumber,wants); // creates new Customer Object.
   System.out.println(\"Given the following was entered from the keyboard:\");
   System.out.println(one.getName());
   System.out.println(one.getAddress());
   System.out.println(one.getNumber());
   //wants = decide.equals(\"yes\");

   if(one.isWants()==true)
   decision=\"Yes\";
   else
   decision=\"No\";
   System.out.println(decision);

       }

   }

Problems Detected:
          The contents of your standard output is incorrect.

Given the following was entered from the keyboard:
Stacy Jones
200 Eastern Pkwy, New York, NY 11238
718-638-5000
359921457
yes
you displayed:
Enter name of customer:Enter address of customer:Enter phone number of customer:Enter yes/no -- does the customer want to recieve mail?:Customer:
Name:Address:Phone Number:Customer Number:Recieve Mail?:Given the following was entered from the keyboard:
Stacy Jones
200 Eastern Pkwy, New York, NY 11238
718-638-5000
No

instead of:
Enter name of customer:Enter address of customer:Enter phone number of customer:Enter customer number:Enter yes/no -- does the customer want to recieve mail?:
Customer:
Name: Stacy Jones
Address: 200 Eastern Pkwy, New York, NY 11238
Phone Number: 718-638-5000
Customer Number: 359921457
Recieve Mail?: true


          Failed 4 out of 4 test runs.

Solution

Did some small modifications is main method:

       public static void main(String[] args) {
           String name, address, number;
   String custNumber;
   String decide;
   String decision;
   boolean wants = false;
   Scanner keyboard = new Scanner(System.in);
   System.out.print(\"Enter name of customer:\");
   name = keyboard.nextLine();
   System.out.print(\"Enter address of customer:\");
   address = keyboard.nextLine();
   System.out.print(\"Enter phone number of customer:\");
   number = keyboard.nextLine();
   System.out.print(\"Enter customer number:\");
   custNumber = keyboard.nextLine();
   System.out.print(\"Enter yes/no -- does the customer want to recieve mail?:\");
   decide = keyboard.nextLine();

   wants = decide.equalsIgnoreCase(\"yes\");

   Customer one = new Customer(name, address, number, custNumber,wants); // creates new Customer Object.
   System.out.println(\"Customer: \");
   System.out.println(\"Name: \" + one.getName());
   System.out.println(\"Address: \" + one.getAddress());
   System.out.println(\"Phone Number: \" + one.getNumber());
   System.out.println(\"Customer Number: \"+ one.getcustNumber());
   System.out.println(\"Recieve Mail?: \" + one.isWants());

       }

Design a class named Person with fields for holding a person\'s name , address, and telephone number (all as Strings ). Write a constructor that initializes all
Design a class named Person with fields for holding a person\'s name , address, and telephone number (all as Strings ). Write a constructor that initializes all
Design a class named Person with fields for holding a person\'s name , address, and telephone number (all as Strings ). Write a constructor that initializes all
Design a class named Person with fields for holding a person\'s name , address, and telephone number (all as Strings ). Write a constructor that initializes all

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site