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

Another problem with my output! The question: A retail store has a preferred cus

ID: 3591676 • Letter: A

Question

Another problem with my output!

The question:

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, they get a 5% discount on all
future purchases.

When a preferred customer spends $1,000, they get a 6% discount on all
future purchases.

When a preferred customer spends $1,5000, they get a 7% discount on all
future purchases.

When a preferred customer spends $2,000, they get a 10% discount on all
future purchases.



Design a class named PreferredCustomer, which inherits from the Customer class
you created in Exercise 7. The preferredCustomer class should have int fields
for the amount of the customer's purchases and the customer's discount level.

Write a constructor that initializes these fields as well as accessor and
mutator methods.

Desmonstrate the class in a program that prompts the user to input the
customer's name, address, phone number, customer number, whether they want to
recieve mail, and the amount they've spent, and then uses that information
to create a PreferredCustomer object and print its information. (Use string
formatting to print the amount spent.)

Create all of the classes in the same file by not delcaring any of them public.

The code

class Customer

{


    private String name;

    private double itemNo;

    private double quantity;


    public String getName()

    {

        return name;

    }


    public void setName(String name)

    {

        this.name = name;

    }


    public double getItemNo()

    {

        return itemNo;

    }


    public void setItemNo(double itemNo)

    {

        this.itemNo = itemNo;

    }


    public double getQuantity()

    {

        return quantity;

    }


    public void setQuantity(double quantity)

    {

        this.quantity = quantity;

    }

}


class PreferredCustomer extends Customer

{


    double purchases;

    double discount;


    public PreferredCustomer()

    {

        purchases = 0.00;

        discount = 0.00;

    }


    public PreferredCustomer(double purchases, double discount)

    {

        this.purchases = purchases;

        this.discount = discount;

    }


    public double getPurchases()

    {

        return purchases;

    }

    public void setPurchases(double purchases)

    {

        this.purchases = purchases;

    }


    public double getDiscount()

    {

        if (purchases >= 500.00 && purchases <= 1000.00)

            discount = 0.05;

        else if (purchases > 1000.00 && purchases<1500.00)

            discount = 0.06;

        else if (purchases >1500.00 && purchases <= 2000.00)

            discount = 0.07;

        else

            discount = 0.10;

        return discount;

    }

}


class testPreferredCustomer

{


    public static void main(String[] args)

    {


        PreferredCustomer pCust = new PreferredCustomer();


        pCust.setPurchases(600.00);


        System.out.println(" Amount purchase: " + pCust.getPurchases());


        System.out.println("Discount: " + pCust.getDiscount());


        System.out.println("Total Amount: " + (pCust.getPurchases() - (pCust.getPurchases()*pCust.getDiscount())));


        pCust.setPurchases(1600.00);


        System.out.println(" Amount purchase: " + pCust.getPurchases());


        System.out.println("Discount: " + pCust.getDiscount());


        System.out.println("Total Amount: " + (pCust.getPurchases() - (pCust.getPurchases()*pCust.getDiscount())));

    }

}

The output

Problems Detected: The contents of your standard output is incorrect. Given the following was entered from the keyboard: Bebe Hart 5041 Crystal Bank Oconomowoc, Minnesota 551714 218-775-5416 567310954 yes 1894 you displayed 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?:Enter amount customer has spent: Customer: Name: Bebe Hart Address: 5041 Crystal Bank Oconomowoc, Minnesota 551714 Phone Number: 218-775-5416 Customer Number: 567310954 Recieve Mail?: true Amount Purchased: $1894.00 Percent off: 7% Failed 5 out of 5 test runs.

Explanation / Answer

Customer.java

public class Customer {

private String name, address, phone_nbr;

private double itemNo; // can be removed as not mentioned in user input

private double quantity; // can be removed as not mentioned in user input

private boolean isMail;

private int custr_nbr;

  

public String getPhone_nbr() {

return phone_nbr;

}

public int getCustr_nbr() {

return custr_nbr;

}

public void setPhone_nbr(String phone_nbr) {

this.phone_nbr = phone_nbr;

}

public void setCustr_nbr(int custr_nbr) {

this.custr_nbr = custr_nbr;

}

public String getAddress() {

return address;

}

public boolean isMail() {

return isMail;

}

public void setAddress(String address) {

this.address = address;

}

public void setMail(boolean isMail) {

this.isMail = isMail;

}

public String getName()

{

return name;

}

public void setName(String name)

{

this.name = name;

}

public double getItemNo()

{

return itemNo;

}

public void setItemNo(double itemNo)

{

this.itemNo = itemNo;

}

public double getQuantity()

{

return quantity;

}

public void setQuantity(double quantity)

{

this.quantity = quantity;

}

}

PreferredCustomer.java

public class PreferredCustomer extends Customer {

double purchases;

double discount;

public PreferredCustomer()

{

purchases = 0.00;

discount = 0.00;

}

public PreferredCustomer(double purchases, double discount)

{

this.purchases = purchases;

this.discount = discount;

}

public double getPurchases()

{

return purchases;

}

public void setPurchases(double purchases)

{

this.purchases = purchases;

}

public double getDiscount()

{

if (purchases >= 500.00 && purchases < 1000.00)

discount = 0.05;

else if (purchases >= 1000.00 && purchases < 1500.00)

discount = 0.06;

else if (purchases >= 1500.00 && purchases < 2000.00)

discount = 0.07;

else

discount = 0.10;

return discount;

}

}

TestPreferredCustomer.java

import java.text.DecimalFormat;

import java.util.Scanner;

public class testPreferredCustomer {

public static void main(String args[]) {

PreferredCustomer pCust = new PreferredCustomer();

DecimalFormat df = new DecimalFormat("#.00");

Scanner sc = new Scanner(System.in);

String name,address,email,phone_nbr;

int custr_nbr;

boolean isMail=false;;

double purchases;

System.out.println("Enter name of the customer:");

name = sc.nextLine();

pCust.setName(name);

System.out.println("Enter address of the customer:");

address = sc.nextLine();

pCust.setAddress(address);

System.out.println("Enter phone number of the customer:");

phone_nbr = sc.nextLine();

pCust.setPhone_nbr(phone_nbr);

System.out.println("Enter Customer number:");

custr_nbr = sc.nextInt();

sc.nextLine();

pCust.setCustr_nbr(custr_nbr);

System.out.println("Enter yes/no -- does the customer want to recieve mail?");

email = sc.nextLine();

if("yes".equalsIgnoreCase(email)) {

isMail = true;

}else if ("no".equalsIgnoreCase(email)) {

isMail = false;

}

pCust.setMail(isMail);

System.out.println("Enter amount customer has spent:");

purchases = sc.nextDouble();

pCust.setPurchases(purchases);

  

System.out.println("Customer:");

System.out.println("Name: " + pCust.getName());

System.out.println("Address: " + pCust.getAddress());

System.out.println("Phone Number: " + pCust.getPhone_nbr());

System.out.println("Customer Number: " + pCust.getCustr_nbr());

System.out.println("Recieve Mail?: " + pCust.isMail());   

System.out.println("Amount Purchased: $" + df.format(pCust.getPurchases()));

System.out.println("Percent off: " + Math.round(pCust.getDiscount()*100)+"%");

System.out.println("Total Amount: $" + df.format(pCust.getPurchases() - (pCust.getPurchases()*pCust.getDiscount())));

}

}