Testing - Sample Program 2

Remember: white box testing means that you look at your code and make sure to test all paths in your program. Black box testing means you look at the specs (like this document or the lab assignment) and test all possibilities it describes.

Description

In this lab you will write a program to compute the cost of a magazine advertisement. The cost of the ad depends on the number of colors used, the number of lines of text, and the number of issues in which the ad will appear.

Input

Your program should read the code for the magazine, the number of lines of print in the ad, the color code for the ad, and the number of issues in which the ad will run.

The magazine codes are:

The color codes are:

Processing

The cost for an ad to appear in one issue starts with a base price of $6499.99 for a black and white full page ad. This will be increased if the ad is in color or if there is a lot of print in the ad.

If the ad is in color there is an additional charge. A three color ad increases the base price by 40%, and a full color ad increases the base price by 60%.

Each ad may contain up to 15 lines of print for the base price. If there are more than 15 lines, then there is an additional cost of $100 for each line over 15.

To get the total cost of the ad, multiply the cost for one issue by the number of issues.

Output

The program will print the following:

In your program, use global named constants for the base price of an ad, and for the three different color codes. Define these constants inside the class and before main.

Black-box Test Data

Make sure to test:

Sample Code

	public static void main(String[] args) {
		Scanner keyin = new Scanner(System.in);
		String magin;
		char magazine;
		int lines;
		int color;
		int issues;
		double issuecost;
		double totcost;
	 	double basecost = 6499.99;

		System.out.print("Enter t (Time), g (TV Guide), s (Sports Illustrated), or v (Vogue): ");
		magin = keyin.next();
		magazine = magin.charAt(0);
		System.out.print("Enter the number of lines in the ad: ");
		lines = keyin.nextInt();
		System.out.print("Enter the color code (1: B/W, 2: 3 color, 3: full color): ");
		color = keyin.nextInt();
		System.out.print("Enter the number of issues the ad will run: ");
		issues = keyin.nextInt();

		System.out.println("\nAd Cost Information\n");
		if (magazine == 't' || magazine == 'T')
			System.out.print("Magazine: Time\n");
		else if (magazine == 'g' || magazine == 'G')
			System.out.print("Magazine: TV Guide\n");
		else if (magazine == 's' || magazine == 'S')
			System.out.print("Magazine: Sports Illustrated\n");
		else if (magazine == 'v' || magazine == 'V')
			System.out.print("Magazine: Vogue\n");

		System.out.println("Number of issues: " + issues);

		if (color == 1)
			System.out.print("Color: Black and White\n");
		if (color == 2)
			System.out.print("Color: Three Color\n");
		if (color == 3)
			System.out.print("Color: Full Color\n");

		System.out.println("Lines of print: " + lines);
		issuecost = colorcost(basecost, color) + linecost(lines);
		System.out.println("Cost per issue: " + issuecost);
		totcost = issuecost * issues;
		System.out.println("Total cost: " + totcost);
	}

	public static int linecost(int lines) {
		if (lines > 15)
			return (lines - 15) * 100;
		else
			return 0;
	}

	public static double colorcost(double basecost, int color) {
		if (color == 1)
			return basecost;
		else if (color == 2)
			return basecost * 1.4;
		else
			return basecost * 1.6;
	}

White-box Test Data

Make sure to test:


Email Me | Office Hours | My Home Page | Department Home | MCC Home Page

© Copyright Emmi Schatz 2013