Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6539381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:51:11+00:00 2026-05-25T10:51:11+00:00

I have an assignment that I’m not quite sure where to start. This is

  • 0

I have an assignment that I’m not quite sure where to start. This is what I’m supposed to do.

  • Create an abstract class DiscountPolicy. It will have a single abstract method computeDiscount that will return the discount for the purchase of a given number of a single item. The method has two parameters, count (int) and itemCost (float)
  • Derive a class BulkDiscount from Discount Policy. It will have a constructor that has two parameters, minimum and percent. It will define a method computeDiscount so that if the quantity purchased of an item is more than the minimum, the discount is the percent for the class. ComputeDiscount will return the total discount.
  • Derive a class BuyNItemsGetOneFree from DiscountPolicy. The class will have a constructor that has a single parameter n. In addition, the class will define the method computeDiscount so that every nth item is free. For example:
  • If n is 3 and the item cost is $10. There is no discount for the first 2 items. There is a $10 discount for items 3 – 5, there is a $20 discount for the 6th item, etc.
  • For BuyNItemsGetOneFree – the computeDiscount method will receive the total items bought and the cost for an item, and will return the total discount if applicable.
  • In your main program, show that the computeDiscount method works for the BulkDiscount and BuyNItemsGetOneFree classes.

This is how I began to set it up. I want to make my methods and parameters are in the correct locations and am wondering where I define the parameters that my teacher wants me to pass.

public class Ex1012 {
    public static void main(String[] args) {
    // TODO Auto-generated method stub

        DiscountPolicy bulk = new BulkDiscount();

        System.out.println();

        DiscountPolicy bngo = new BuyNItemsGetOneFree();        
    }
}

public abstract class DiscountPolicy {  
    abstract void computeDiscount(int count, float itemCost){

        return discount;
    }
}


public class BuyNItemsGetOneFree extends DiscountPolicy {

    BuyNItemsGetOneFree() { 
    }

    BuyNItemsGetOneFree(int n){
        DiscountPolicy.computeDiscount(int count, float itemCost);
        //set n to a variable here??
        //calculations go here
        //Where to set count and itemCost??
    }   
}

public class BulkDiscount extends DiscountPolicy {

    public BulkDiscount(int minimum, float percent){
        if (quantity > minimum){
            super.ComputeDiscount(int count, float itemCost);
        //calculations go here
            //Where to define count, itemCost, minimum, and percent??
        }       
    }   
}

I’m simply worried about the relationship between the classes and the parameters themselves because I get confused once I have multiple classes such as these. Any insight would be greatly appreciated. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:51:11+00:00Added an answer on May 25, 2026 at 10:51 am

    Abstract methods may not have a body, so your definition of computeDiscount(...) should be:

    abstract void computeDiscount(int count, float itemCost);
    

    In each of the concrete classes that extend the abstract class, you’d then have to implement that method. Generally, abstract methods behave like methods defined in interfaces to some extent (they are declared but without a default implementation), yet still have differences (can be protected or package private as well, can only be implemented by subclasses etc.).

    In most cases you have an abstract class that provides some default logic and just requires the subclasses to fill in some “holes” that depend on the concrete implementation.

    So basically, you store the parameters to BuyNItemsGetOneFree and BulkDiscount as instance variables and use them when computeDiscount(...) is called. You’re calling it in the constructor, which is most likely the wrong place. I guess your main should call the method on the objects you create directly, e.g.

    DiscountPolicy bngo = new BuyNItemsGetOneFree(5); 
    double discountForFour = bngo.computDiscount(4,4.95f);
    double discountForFive = bngo.computDiscount(5,4.95f);
    

    Note that your computeDiscount(...) method should return a value, according to your assignment:

    …a single abstract method computeDiscount that will return the discount for the purchase of a given number of a single item…

    Edit:

    //Where to set count and itemCost??

    As I said above, you don’t “set” (store) them, but use them for the calculation only.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For a school assignment I have to create a C++ program that will create
I have an assignment that is supposed to be written in C (not C++),
I have quite a large XSL document for an assignment that does a number
I have an assignment in which I need to create a function that tells
I have an assignment that requires us to implement a doubly linked list class.
I have this programming assignment that converts between meters and feet, and between kilograms
I have this assignment due that requires the usage of FLTK. The code is
For my Operating Systems class I have an assignment due that is built onto
My boss has given me an assignment that I'm not sure is possible since
I have a homework assignment that I am supposed to write a http server

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.