Using JAVA*
Design a class named Person with fields for holding a person’s
name,
address, and telephone number. Write one or more constructors and
the
appropriate mutator and accessor methods for the class’s
fields.
Next, design a class named Customer, which extends the Person
class. The
Customer class should have a field for a customer number and a
boolean
field indicating whether the customer wishes to be on a mailing
list. Write
one or more constructors and the appropriate mutator and accessor
methods
for the class’s fields. Demonstrate an object of the Customer class
in a simple
program.
1) Add an "age" field to the Person class with appropriate methods to get and set the age.
2) Add an interface (you can call it what you want but a good suggestion would be "AgeCalculator") this will have a calculate method that takes 2 parameters.
3) Create a Lambda Expression with 2 Parameters (not just 1 as we did for the quickcheck) .... you will be calling yours with 2 parameters -- the person's current age which is stored in the Person/Customer object and how many years you want to add to that person's age .
Example : ask the user how many years they want to add to the person's age and say you store it in a variable called futureAge ; assuming you defined your multiple parameter lambda expression (let's say you called it future) and your AgeCalculator interface, you could calculate the future age by saying:
future.calculate(curAge, numYearsAdded) (see page 688 for 1 parameter lambda expression call)
public class Person {
private String name;
private String address;
private long telephoneNumber;
private int age;
public Person() {
this.name="";
this.address="";
this.telephoneNumber=0;
this.age=0;
}
public Person(String name,String address,long phn,int
age){
this.name=name;
this.address=address;
this.telephoneNumber=phn;
this.age=age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public long getTelephoneNumber() {
return telephoneNumber;
}
public void setTelephoneNumber(long telephoneNumber)
{
this.telephoneNumber =
telephoneNumber;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
public class Customer extends Person{
private String customeNumber;
private boolean isOnMailingList;
public Customer() {
this.customeNumber="";
this.isOnMailingList=false;
}
public Customer(String name,String address,long
phn,int age,String custNo,
boolean
isMailingOn){
super(name, address, phn,
age);
this.customeNumber=custNo;
this.isOnMailingList=isMailingOn;
}
public String getCustomeNumber() {
return customeNumber;
}
public void setCustomeNumber(String customeNumber)
{
this.customeNumber =
customeNumber;
}
public boolean isOnMailingList() {
return isOnMailingList;
}
public void setOnMailingList(boolean isOnMailingList)
{
this.isOnMailingList =
isOnMailingList;
}
}
public interface AgeCalculator {
void calculate(int param1,int param2);
}
import java.util.Scanner;
public class TestCustomer {
public static void main(String[] args) {
Customer cust=new Customer("john",
"12-street,LA", 95867263,
25, "CUS123", true);
Scanner sc=new
Scanner(System.in);
System.out.println("Enter no of
years to add to person age: ");
int noOfYears=sc.nextInt();
System.out.println("Age before
calculate: "+cust.getAge());
AgeCalculator future=(int
currAge,int yearsToAdd)->{//lambda function displays future
age
int futureAge=
currAge+yearsToAdd;
System.out.println("Future age is: "+futureAge);
};
future.calculate(cust.getAge(),
noOfYears);//calling lambda calculate method
}
}
Expected output:
Using JAVA* Design a class named Person with fields for holding a person’s name, address, and...
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...
this is java m. please use netbeans if you can. 7. Person and Customer Classes Design a class named Person with fields for holding a person's name, address, and telephone number. Write one or more constructors and the appropriate mutator and accessor methods for the class's fields. Next, design a class named Customer, which extends the Person class. The Customer class should have a field for a customer number and a boolean field indicating whether the cus- tomer wishes to...
JAVA HELP Design a class named Employee. The class should keep the following information in fields: Employee name Employee number in the format XXX–L, where each X is a digit within the range 0–9 and the L is a letter within the range A–M. Hire date then, Write one or more constructors and the appropriate accessor and mutator methods for the class. Next, write a class named ProductionWorker that extends the Employee class. The ProductionWorker class should have fields to...
Write a class named PhoneBookEntry that has fields for a person's name and phone number.The class should have a constructor and appropriate accessor and mutator methods. Thenwrite a program that creates at least five PhoneBookEntry objects and stores them in anArrayLitt. Use a loop to display the contents of each object in the ArrayList.
Room Class....... in JAVA!!!!! Write a class named Room that has the following fields: Length: Double variable that holds the rooms length(in feet). Breadth: The double variable that holds the rooms breadth(in feet). Height: Double variable that holds rooms height in feet. Color: String object that holds the color you want the room to be painted with. The class should have a constructor to initialize the fields for a particular instance (or object) of the class as given: All double...
Phone Book ArrayList Write a class named PhoneBookEntry that has fields for a person’s name and phone number. The class should have a constructor and appropriate accessor and mutator methods. Then write a program that creates at least five PhoneBookEntry objects and stores them in an ArrayList. Use a loop to display the contents of each object in the ArrayList Copyright | Addison-Wesley | Starting Out with Java | [email protected] | Printed from Chegg iOS App
Assignment 6 Due: Apr 12, 2019 at 11:59 PM A6 OOP 3 "PreferredCustomer Class" (need to create Person, Customer classes described in the previous problem) Access A6 from pdf assignment file. Turn in the following files: a6main.java Customer.java Person.java PreferredCustomer.java program compile and run screenshots design document (including UML) A6 7. Person and Customer Classes esign a class named Person with fields for holding a person's name, address, and telephone number. Write one or more constructors and the appropriate mutator...
Language is JAVA. Clarification for the Shape class (highlighted): The following requirements specify what fields you are expected to implement in your Shape class; - A private String color that specifies the color of the shape - A private boolean filled that specifies whether the shape is filled - A private date (java.util.date) field dateCreated that specifies the date the shape was created Your Shape class will provide the following constructors; - A two-arg constructor that creates a shape with...
Problem 2 (36 pts): You are going to design a class named Computer. The class contains: A string field named manufacturer. A string field named serialNumber. A double field named speed (measured in Gigahertz). A constructor that has a parameter for each data field and sets the data fields with these values. A no-arg constructor that sets string fieldsto and numeric fields to 0. Mutator and Accessor methods for each data field. A method toString) that returns each field value...
java Write a class named Car that has the following fields: • yearModel: The yearModel field is an int that holds the car's year model. • make: The make field is a String object that holds the make of the car. • speed: The speed field is an int that holds the car's current speed. In addition, the class should have the following methods: • Constructor: The constructor should accept the car's year model and make as arguments. These values...