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

A newspaper company sells advertisement space in their newspaper. Advertisers bu

ID: 3730250 • Letter: A

Question

A newspaper company sells advertisement space in their newspaper. Advertisers buy space based on amount of space wanted in a newspaper page – full page, half page, quarter page and business card size. Customer also indicates how many days the advertisement would run. Advertisers receive a discount based on the total cost of the advertisement sale.

Design:

The classes should be placed in a package with the name edu.ilstu

Non-application classes Advertisement and AdSale should have complete Javadoc comments.

You will need to use the following classes for your program:

Advertisement class

Keeps track of the information for Advertisements. This class should include the following:

Named Constants – Make these privatePrices for advertisement size

Full page at $50

Half-page at $30

Quarter page at $20

Business card size at $10

Methods

Getters for all the constants

A method that accepts the character code for advertisement space size and returns the price for the space. The codes for the advertisement size are:

F – Full page

H – Half-page

Q – Quarter page

B – Business card

A method that accepts the total cost of the sale and returns the discount amount. Total cost of at least $200 but less than $500 receives a 10% discount, a sale of at least $500 will receive a discount of 15%.

AdSale class

Keeps track of the information for the sale of an advertisement space. This class should include the following:

Instance variables

a field to store the adType (F, H, Q, or B)

a field to store first name of customer

a field to store last name of customer

a field to store the number of days the ad would run

a field to store the price of the ad space

Methods

a constructor that accepts values for all instance fields except for price

getters for all instance fields

setter for number of days to run ad and the price of the advertisement space

a method to calculate the cost of the sale based on the price and the number of days to run the ad

A method to return the final cost of the sale based on total cost less the discount amount. This method accepts the discount amount.

A method to run the full description of the advertisement space

F – Full page

H – Half-page

Q – Quarter page

B – Business card size

toString method that formats the Advertisement information – name of customer, ad description, number of days to run ad and price. See sample output run.

AdSalesApp class

This is the starting point for the application, which is the only class to contain a main method. You will use both the Advertisement and AdSale classes here. For this program, the main method handles all of the input and output for the program and will perform the following tasks:

Create the instance of Advertisement class and AdSale.

Follow the sample interaction on what to display for prompts, labels, messages and the flow for screen input and outputs.

Display the Ad space sizes and prices

Ask user for type of ad, name and number of days to run.

Display the billing summary. Discount information should not be displayed if there is no discount.

Review the sample run of the program to determine how the interaction with the user should flow.

Sample output with discount:

Advertisement Options:

     F - Full page ad               50.00

     H - Half page ad               30.00

     Q - Quarter page ad            20.00

     B - Business card page ad      10.00

Please make your selection

Enter ad option (F, H, Q or B): F

Enter first name: Anne

Enter last Name: Smith

Enter number of days ad would run: 12

          Bill Summary

Anne Smith

Ad type: Full page

Days to run ad: 12

Price: $50.00

Total cost: 600.00

Discount: $90.00

Final Cost: $510.00

Explanation / Answer

Hello, I have a solution for you. Implemented everything as per the requirements. Defined following things in this answer.

// Advertisement.java

package edu.ilstu;

public class Advertisement {

                /**

                * defining all required constants

                */

                private static final double FULL_PAGE_PRICE = 50.0;

                private static final double HALF_PAGE_PRICE = 30.0;

                private static final double QUARTER_PAGE_PRICE = 20.0;

                private static final double BUSINESS_CARD_SIZE_PRICE = 10.0;

                /**

                * getter methods for all price constants

                */

                public static double getFullPagePrice() {

                                return FULL_PAGE_PRICE;

                }

                public static double getHalfPagePrice() {

                                return HALF_PAGE_PRICE;

                }

                public static double getQuarterPagePrice() {

                                return QUARTER_PAGE_PRICE;

                }

                public static double getBusinessCardSizePrice() {

                                return BUSINESS_CARD_SIZE_PRICE;

                }

                /**

                * method to return the price of an ad space, given its code

                *

                * @param space

                *            - char code of the ad space (F/H/Q or B)

                * @returns the price of the required ad space

                */

                public double getPriceOfSpace(char space) {

                                switch (space) {

                                case 'F':

                                                return getFullPagePrice();

                                case 'H':

                                                return getHalfPagePrice();

                                case 'Q':

                                                return getQuarterPagePrice();

                                case 'B':

                                                return getBusinessCardSizePrice();

                                }

                                return 0;

                }

                /**

                * method to calculate and return the discount amount

                *

                * @param totalCost

                *            - total cost of the ad

                * @return - discounted total cost

                */

                public double getDiscountAmount(double totalCost) {

                                if (totalCost >= 200 && totalCost < 500) {

                                                // applying 10% discount

                                                return totalCost * 0.10;

                                } else if (totalCost >= 500) {

                                                // applying 15% discount

                                                return totalCost * 0.15;

                                } else {

                                                return 0;

                                }

                }

                /**

                * method to print a description menu. I think this method is more suited in

                * this class than AdSale class

                */

                public void printDescription() {

                                System.out.println("F – Full page " + getFullPagePrice());

                                System.out.println("H – Half-page " + getHalfPagePrice());

                                System.out.println("Q – Quarter page " + getQuarterPagePrice());

                                System.out.println("B – Business card size "

                                                                + getBusinessCardSizePrice());

                }

}

// AdSale.java

package edu.ilstu;

public class AdSale {

                /**

                * Defining all required attributes

                */

                private char adType;

                private String firstName;

                private String lastName;

                private int numDays;

                private double price;

                /**

                * constructor to initialize all fields except price

                *

                * @param adType

                *            - F/H/Q or B

                * @param firstName

                *            - first name of customer

                * @param lastName

                *            - last name of customer

                * @param numDays

                *            - number of days ad should run

                */

                public AdSale(char adType, String firstName, String lastName, int numDays) {

                                this.adType = adType;

                                this.firstName = firstName;

                                this.lastName = lastName;

                                this.numDays = numDays;

                }

                /**

                * all required getter methods

                */

                public char getAdType() {

                                return adType;

                }

                public String getFirstName() {

                                return firstName;

                }

                public String getLastName() {

                                return lastName;

                }

                public int getNumDays() {

                                return numDays;

                }

                public double getPrice() {

                                return price;

                }

                /**

                * setter methods for number of days and price

                */

                public void setNumDays(int numDays) {

                                this.numDays = numDays;

                }

                public void setPrice(double price) {

                                this.price = price;

                }

                /**

                * method to calculate the original cost

                *

                * @return the original cost, without discount

                */

                public double calculateCost() {

                                return price * numDays;

                }

                /**

                * returns the discounted cost

                *

                * @param discount

                *            - discount amount

                * @return- discounted cost

                */

                public double calculateFinalCost(double discount) {

                                return calculateCost() - discount;

                }

                /**

                * method to print a description. This method is probably unnecessary, as

                * the Advertisement class has one

                */

                public void printDescription() {

                                System.out.println("F – Full page");

                                System.out.println("H – Half-page");

                                System.out.println("Q – Quarter page");

                                System.out.println("B – Business card size");

                }

                /**

                * returns a properly formatted string containing all data

                */

                @Override

                public String toString() {

                                String data = firstName + " " + lastName + " ";

                                data += "Ad type:";

                                switch (adType) {

                                case 'F':

                                                data += "Full page ";

                                                break;

                                case 'H':

                                                data += "Half page ";

                                                break;

                                case 'Q':

                                                data += "Quarter page ";

                                                break;

                                case 'B':

                                                data += "Business card size ";

                                                break;

                                }

                                data += "Days to run ad: " + numDays + " ";

                                data += "Price: $" + price + " ";

                                data += "Total cost: $" + String.format("%.2f", calculateCost()) + " ";

                                return data;

                }

}

// AdSalesApp.java

package edu.ilstu;

import java.util.Scanner;

public class AdSalesApp {

                public static void main(String[] args) {

                                /**

                                * Defining an advertisement and adsale object

                                */

                                Advertisement advertisement = new Advertisement();

                                AdSale adSale;

                                /**

                                * Scanner to read input

                                */

                                Scanner scanner = new Scanner(System.in);

                                System.out.println("Advertisement Options:");

                                /**

                                * displaying the menu, we cant call the method if it is in AdSale class

                                * as it is not initialized and will need more info to be initialized

                                */

                                advertisement.printDescription();

                                System.out.println("Please make your selection: ");

                                System.out.println("Enter ad option (F, H, Q or B):");

                                char adType = scanner.nextLine().charAt(0);

                                if (adType == 'F' || adType == 'H' || adType == 'Q' || adType == 'B') {

                                                /**

                                                * Valid selection, getting further details

                                                */

                                                System.out.println("Enter first name");

                                                String firstName = scanner.nextLine();

                                                System.out.println("Enter last name");

                                                String lastName = scanner.nextLine();

                                                System.out.println("Enter number of days ad would run:");

                                                int numDays = Integer.parseInt(scanner.nextLine());

                                                /**

                                                * initializing AdSale instance

                                                */

                                                adSale = new AdSale(adType, firstName, lastName, numDays);

                                                /**

                                                * setting price

                                                */

                                                double price = advertisement.getPriceOfSpace(adType);

                                                adSale.setPrice(price);

                                                /**

                                                * finding total space

                                                */

                                                double totalCost = adSale.calculateCost();

                                                /**

                                                * finding discount

                                                */

                                                double discount = advertisement.getDiscountAmount(totalCost);

                                                /**

                                                * finding discounted price

                                                */

                                                double discountedFinalCost = adSale.calculateFinalCost(discount);

                                                /**

                                                * Displaying the bill

                                                */

                                                System.out.println("Bill Summary");

                                                System.out.println(adSale);

                                                System.out.printf("Discount: $%.2f ", discount);

                                                System.out.printf("Final Cost: $%.2f ", discountedFinalCost);

                                } else {

                                                /**

                                                * Invalid ad type

                                                */

                                                System.out.println("Invalid ad type");

                                }

                }

}

/*OUTPUT*/

Advertisement Options:

F – Full page                      50.0

H – Half-page                    30.0

Q – Quarter page             20.0

B – Business card size    10.0

Please make your selection:

Enter ad option (F, H, Q or B):

F

Enter first name

Anne

Enter last name

Smith

Enter number of days ad would run:

12

Bill Summary

Anne Smith

Ad type:Full page

Days to run ad: 12

Price: $50.0

Total cost: $600.00

Discount: $90.00

Final Cost: $510.00

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote