Question
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 persons name, address, and telephone nu
0 0
Add a comment Improve this question Transcribed image text
Answer #1

//Solution 7

public class Person {
//Fields
private String name;
private String address;
private String phoneNumber;

//Default constructor
public Person()
{
name ="";
address ="";
phoneNumber = "";
}

//Overload Constructor

public Person(String name, String address, String phoneNumber) {
this.name = name;
this.address = address;
this.phoneNumber = phoneNumber;
}
//getters and Setters

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 String getPhoneNumber() {
return phoneNumber;
}

public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}

@Override
public String toString() {
return "Name: "+name+", Address: "+address+", Phone: "+phoneNumber;
}
}

//==============================

public class Customer extends Person {
private int customerNumber;
private boolean isMailingList;
//Default Customer
public Customer()
{
//call super class constructor
super();
isMailingList = false;
customerNumber =0;
}
//Overload Constructor

public Customer(String name, String address, String phoneNumber, int customerNumber, boolean isMailingList) {
super(name, address, phoneNumber);
this.customerNumber = customerNumber;
this.isMailingList = isMailingList;
}

//getters and setters

public int getCustomerNumber() {
return customerNumber;
}

public void setCustomerNumber(int customerNumber) {
this.customerNumber = customerNumber;
}

public boolean isMailingList() {
return isMailingList;
}

public void setMailingList(boolean mailingList) {
isMailingList = mailingList;
}

@Override
public String toString() {
return super.toString()+"\nCustomer Number: "+customerNumber+", Wishing to add mailing list: "+isMailingList;
}
}

//=====================================

public class TestCustomer {
public static void main(String[] args)
{
//Create a customer using overload constructor
Customer customer1 = new Customer("John","2- abc street, City","456-799-9090",101,true);
//Print info using toString()
System.out.println(customer1);
//Create another customer using default Constructor
Customer customer2 = new Customer();
//set Customer attributes
customer2.setCustomerNumber(102);
customer2.setMailingList(false);
customer2.setAddress("New york City");
customer2.setName("Mike");
customer2.setPhoneNumber("890-4567-900");
System.out.println();
//Print info using toString()
System.out.println(customer2);
}
}

//Output

C:\Program Files\Java\jdk1.8.0_221\bin\java.exe Name: John, Address: 2- abc street, City, Phone: 456-799-9090 Customer Numb

//=========================

import java.text.DecimalFormat;

public class PreferredCustomer extends Customer {
private double amount;
private double discount;

//Default customer
public PreferredCustomer()
{
amount =0;
discount =0;
}

//Overload constructor

public PreferredCustomer(String name, String address, String phoneNumber, int customerNumber, boolean isMailingList, double amount) {
super(name, address, phoneNumber, customerNumber, isMailingList);
this.amount = amount;
discount = calculateDiscount();

}
//getters

public double getAmount() {
return amount;
}

public double getDiscount() {
return discount;
}

/**
*
* @return discount based on customer spends
*/
public double calculateDiscount()
{
if(amount>=500 && amount<1000)
discount = 0.05;
else if(amount >= 1000 && amount <1500)
discount = 0.06;
else if(amount >=1500 && amount < 2000)
discount = 0.07;
else if(discount >= 2000)
discount = 0.10;
else
discount =0;
return discount;
}
//setters

public void setAmount(double amount) {
this.amount = amount;
}

/**
*
* @return String representation of object
*/
@Override
public String toString() {
return super.toString()+"\nAmount spends: $"+String.format("%.2f",amount)+", Discount Earned: "+calculateDiscount()*100+"%" ;
}
}

//===============================

public class TestPreferedCustomer {
public static void main(String[] args)
{
//Create customer
PreferredCustomer preferredCustomer=
new PreferredCustomer("Tim Marker","Pie Street, City Enclave","567-8904=900",1001,true,1400);
//Print info using toString()
System.out.println(preferredCustomer);
}
}

//Output

C:\Program Files\Java\jdk1.8.@_221\bin\java.exe .. Name: Tim Marker, Address: Pie Street, City Enclave, Phone: 567-8904=900

//If you need any help regarding this solution...... please leave a comment.... thanks

Add a comment
Know the answer?
Add Answer to:
this is java m. please use netbeans if you can. 7. Person and Customer Classes Design...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Assignment 6 Due: Apr 12, 2019 at 11:59 PM A6 OOP 3 "PreferredCustomer Class" (need to...

    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...

  • This must be written in C# with overloaded constructors and member initialization list 4. Person and...

    This must be written in C# with overloaded constructors and member initialization list 4. Person and Customer Classes Design a class named Person with properties for holding a person's name, address, and telephone number. Next, design a class named Customer, which is derived from the Person class. The Customer class should have a property for a customer number and a Boolean property indicating whether the customer wishes to be on a mailing list. Demonstrate an object of the Customer class...

  • Design a class named Person with fields for holding a person's name, address, and telephone number...

    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...

  • Using JAVA* Design a class named Person with fields for holding a person’s name, address, and...

    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...

  • JAVA HELP Design a class named Employee. The class should keep the following information in fields:...

    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...

  • Language is JAVA. Clarification for the Shape class (highlighted): The following requirements specify what fields you...

    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...

  • need code for this in java Design a set of classes that work together to simulate the Stock Transaction System. You should design the following classes: 1. the StockMarket class. This class si...

    need code for this in java Design a set of classes that work together to simulate the Stock Transaction System. You should design the following classes: 1. the StockMarket class. This class simulates the stock market such as Nasdaq, NYSD, or other stock market. The class's responsibility are as follows: -To know the stock market abbreviation, full name, location, an arraylist of stocks for this market 2. the Company class: this class simulates a company that has stock released on...

  • (PLEASE UPLOAD ALL PARTS TO THE QUESTION) (IE: PSEUDO CODE AND JAVA CODE TOGETHER NOT ONE...

    (PLEASE UPLOAD ALL PARTS TO THE QUESTION) (IE: PSEUDO CODE AND JAVA CODE TOGETHER NOT ONE OR THE OTHER) Design an Employee class that fields for the following pieces of information: 1) Employee name 2) Employee number Next design a class named ProductionWorker that extends the Employee class. The ProductionWorker class should have fields to hold the following information: 1) Shift number (an integer, such as 1, 2, or 3) 2)Hourly pay The workday is divided into two shifts day...

  • (PLEASE UPLOAD ALL PARTS TO THE QUESTION) (IE: PSEUDO CODE AND JAVA CODE TOGETHER NOT ONE...

    (PLEASE UPLOAD ALL PARTS TO THE QUESTION) (IE: PSEUDO CODE AND JAVA CODE TOGETHER NOT ONE OR THE OTHER) Design an Employee class that fields for the following pieces of information: 1) Employee name 2) Employee number Next design a class named ProductionWorker that extends the Employee class. The ProductionWorker class should have fields to hold the following information: 1) Shift number (an integer, such as 1, 2, or 3) 2)Hourly pay The workday is divided into two shifts day...

  • Develop a set of classes for a college to use in various student service and personnel applications. Classes you need to design include the following: • Person — A Person contains the following fields...

    Develop a set of classes for a college to use in various student service and personnel applications. Classes you need to design include the following: • Person — A Person contains the following fields, all of type String: firstName, lastName, address, zip, phone. The class also includes a method named setData() that sets each data field by prompting the user for each value and a display method that displays all of a Person’s information on a single line at the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT