Question: Getting stuck on my homework. The problem is two parts. Person and Customer Classes Design a class named Person with fields for holding a persons
Getting stuck on my homework.
The problem is two parts.
Person and Customer Classes Design a class named Person with fields for holding a persons name, address, and telephone number. Write one or more constructors and the appropriate mutator and accessor methods for the classs 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 classs fields. Demonstrate an object of the Customer class in a simple program.
PreferredCustomer Class
A retail store has a preferred customer plan where customers can earn discounts on all their purchases. The amount of a customer's discount is determined by the amount of the customer's cumulative purchases in the store as follows:
* When a preferred customer spends $500, he or she gets a 5 percent discount on all future purchases.
* When a preferred customer spends $1,000, he or she gets a 6 percent discount in all future purchase.
* When a preferred customer spends $1,500, he or she gets a 7 percent discount in all future purchase.
* When a preferred customer spends $2,000 or more, he or she gets a 10 percent discount in all future purchase.
Design a class named PreferredCustomer, which extends the Customer class you created earlier. The PreferredCustomer class should have fields for a number of the customer's purchases and the Customer's discount level. Write one or more constructors and the appropriate mutator and accessor methods for the class's fields. Demonstrate the class in a simple program.
Person.java
public class Person { private String name; protected String phone;
public Person(String name,String phone) { this.name = name; this.phone = phone; }
public String getName() { return name; } public void setName(String name) { this.name=name; }
public String getPhone() { return phone; } public void setPhone(String phone) { this.phone=phone; } }
Customer.java
import java.util.Scanner;
class Customer extends Person { String CustomerNumber; boolean mail; public Customer(String name, String address,String phone,String number,boolean mail) { super(name,address,phone,mail); this.CustomerNumber=phone; this.mail=mail; } public String getCustomerNumber() { return CustomerNumber; } public void setCustomerNumber(String CustomerNumber) { this.CustomerNumber=CustomerNumber; } public boolean isMail() { return mail; } public void setMail(boolean mail) { this.mail=mail; }
//// public void setAddress() { return }
public static void main(String args[]) { Scanner keyboard = new Scanner(System.in); System.out.println("Enter Customer Name: "); String name=keyboard.nextLine(); System.out.println("Enter Address: "); String address=keyboard.nextLine(); System.out.println("Enter Phone Number: "); String customerNumber=keyboard.nextLine(); System.out.println("Recieve Mail? Enter Yes/No "); boolean mail=keyboard.nextBoolean(); Customer customer= new Customer(name,address,phone,customerNumber,mail); System.out.println("Customer: "); System.out.println("Name: "+customer.name); System.out.println("Address: "+customer.address); System.out.println("Phone number: "+customer.phone);
System.out.println("Recieve Mail?: "+customer.mail); } }
Address.java
public class Address { private String city; private String state; private String zipCode; private String country; public Address() { city = state = zipCode = ""; } public Address(String city, String state, String zipCode) { this.city = city; this.state = state; this.zipCode = zipCode; } public void setCity(String city) { this.city = city; } public void setState(String state) { this.state = state; } public void setZipCode(String zipCode) { this.zipCode = zipCode; } public String getCity() { return city; } public String getState() { return state; } public String getZipCode() { return zipCode; } public String toString() { String str = "The address is " + city + ", " + state + ", " + zipCode + ", " + country; return str; public String setAddress() { }
PreferredCustomer.java
public class PreferredCustomer extends Customer{ private double numPurchased; private double discount;
public PreferredCustomer(String name, String address,String phone,boolean mail,double numPurchased){ super(mail,name,address,phone); setNumPurchased(numPurchased); }
public double getNumPurchased() { return numPurchased; } public void setNumPurchased(double numPurchased) { this.numPurchased=numPurchased; if (numPurchased >= 500 && numPurchased <= 999) { this.discount= 5; } else if (numPurchased >= 1000 && numPurchased <= 1499) { this.discount = 6; } else if (numPurchased >=1500 && numPurchased <= 1999 ) { this.discount = 7; } else if (numPurchased >= 2000) { this.discount = 10; } else { this.discount = 0; } } public double getDiscount() { return discount; } public void setDiscount(double discount){ this.discount=discount; }
public String toString() { return super.toString() + " Number Purchased: " + numPurchased + " % Discount: " + discount; }
}
CustomerTest.java
import java.util.Scanner;
public class CustomerTest { public static void main(String[] args) { Scanner input=new Scanner(System.in); String name; String address; String phone; boolean sendMail; String mail; System.out.print("Enter customer name: "); name=input.nextLine(); System.out.print("Enter customer address: "); address=input.nextLine(); System.out.print("Enter telephone number: "); phone=input.nextLine(); //check if customer wishes to be on mailing list System.out.print("Is the customer on mailing list [Y/N]: "); mail=input.nextLine(); if(mail.toUpperCase().equals("Y")) sendMail=true; else sendMail=false; //create an object to customer class Customer custobj=new Customer(sendMail,name,address,phone); //using the getter methods print the customer details System.out.println("Name: "+custobj.getName()); System.out.println("Address: "+custobj.getAddress()); System.out.println("Telephone Number: "+custobj.getPhone()); if(custobj.getsendMail()) System.out.print("Is on Mailing List"); else System.out.print("Is not on Mailing List"); } }
PreferredCustomerTest.java
import java.util.Scanner;
public class PreferredCustomerTest {
public static void main(String[] args) { Scanner input=new Scanner(System.in); String name; String address; String phone; boolean sendMail; double purchases; String mail;
System.out.print("Enter customer name: "); name=input.nextLine(); System.out.print("Enter customer address: "); address=input.nextLine(); System.out.print("Enter telephone number: "); phone=input.nextLine(); System.out.print("Is the customer on mailing list [Y/N]: "); mail=input.nextLine(); if(mail.toUpperCase().equals("Y")) sendMail=true; else sendMail=false; //prompt and read purchases amount System.out.print("Enter purchases: "); purchases=input.nextDouble(); //create an object to PreferredCustomer class PreferredCustomer pcustObj=new PreferredCustomer(name,address,phone,sendMail,purchases); //print the customer details using getter methods System.out.print("Name: "+pcustObj.getName()); System.out.print("Address: "+pcustObj.getAddress()); System.out.print("Telephone Number: "+pcustObj.getPhone()); if(pcustObj.getsendMail()) System.out.print("Is on Mailing List"); else System.out.print(Is not on Mailing List");
System.out.print(" Amount of Purchases: "+pcustObj.getNumPurchased()); System.out.print(" The discount for future purchases is: "+pcustObj.getDiscount()+"%"); }
This is a intro java class. The get properties are making me stuck. Our professor wants us to have address as a seperate method and not part of the person class. Mostly having trouble with displaying the string in address
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
