# Advertisment for Class

Printable View

• April 9th, 2013, 09:37 AM
grave7
Advertisment for Class
Below are the instructions for the project then below them is my code did I do this correctly or does he want the actual pricing within the code having a hard time understanding the instructions. I'd like to know if I'm getting the desired output the instructions say and if, I'm suppose to hard code the values an numbers the instructions say they have me confused if my instructor wants the code to just run or if he wants them to have the output hes stated.

A local advertising firm has the following ad restrictions:

(Note: The idea of implementing loops or repetition structures are found in Chapter 5)

1. Size of the Ad:

MIN_WIDTH is 2 inches, MAX_WIDTH is 6 inches, MAX_CHAR=1440 and CHAR_PER_INCH =10

2. Vendor Costs (Basically there are the 2 categories of vendors that we deal with: Playperson {P} or Outdoors {O}):

PLAYPERSON_COST is \$200.00 and OUTDOORS_COST=\$900.00

3. Additional Costs:

EXCESS_COSTS is \$20.00 for each line over EXCESS_LIMIT which is currently 6

1. Set up named constants for the above items.

2. Prompt the user for the Vendor (i.e. P,p, O,o). Loop until valid vendor.

3. Prompt the user for the width. Loop until valid width.

4. Prompt the user for the number of characters. Loop until valid number of characters.

5. Calculate the following:

Length of Line: CHAR_PER_INCH times width

Number of Lines = number of characters divided by Length of Line

Add 1 to Number of Lines if there is a remainder

Excess Line Cost is EXCESS_COST times (Number of Lines above EXCESS_LIMIT) or 0

Total Cost is Vendor Cost +Additional Cost

6. Produce the following output where appropriate variables are substituted:

Cost for a 4 inch ad consisting of 255 characters for Play Person is:

Number of Lines xx

Vendor Cost \$xxxx.xx

Excess Line Cost \$xxxx.xx

Total Cost \$xxxx.xx

Code java:

public static void main (String arg[])
{
Scanner s=new=new Scanner(System.in);
System.out.printin("Enter the vendor");
String vendor=s.next().toLowerCase();
of(!(vendor.equals("p"||vender.equals("o")))
{
System.out.printIn("Enter the valid vendor");
vendor=s.next();
}
System.out.printIn('Enter the Width:');
int width=s.nextInt();
while(width<0)
{
System.out.printIn("Enter the valid width")
width=s.nextInt();
}
int noOfCharacters;
System.out.printIn("Enter No. of characters:");
noOfCharacters=s.nextInt();
while(noOfCharacters<0)
{
System.out.println("Enter the valid no of characters");
noOfCharacters=s.nextInt();
}
int lengthOfLine=CHAR_PER_INCH*width;
int noOfLines= noOfCharacters/lengthOfLine;
if(noOfCharacters%lengthOfLine!=0)
{
noOfLines++;
}
int excessLineCost=(int)(EXCESS_COSTS*(noOfLines-EXCESS_LIMIT));
int totalCost=(int)PLAYPERSON_COST+(int)OUTDOORS_COST;
System.out.println("Cost for a 4 in. Advertisement Consisting Of 255 Characters for Play Person is:");
System.out.println("Number of Lines "+noOflines);
System.out.println("Vendor Cost \$"+totalCost);
System.out.println("Excess Line Cost \$"+excessLineCost);
System.out.println("Total Cost \$"+totalCost);
}
}
}

• April 9th, 2013, 10:25 AM
Norm
Re: Advertisment for Class
Please describe your problem. Which part are you unsure about?
Your run-on sentences are are to follow.

Please edit your post and wrap your code with code tags:
[code=java]
<YOUR CODE HERE>
[/code]
to get highlighting and preserve formatting.
• April 9th, 2013, 10:33 AM
grave7
Re: Advertisment for Class
I've Edited an added more to what I would like to know thank for any help in advance
• April 9th, 2013, 10:37 AM
Norm
Re: Advertisment for Class
If the code is to just run with no user input, then it will need to have the input values hardcoded.
Here is a technique I use: Put the answers in the Scanner class's constructor:
Code :

Scanner s=new Scanner("the answers go here\nwith\nfor end of lines\n"); //System.in);