Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Advertisment for Class

  1. #1
    Junior Member
    Join Date
    Apr 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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

    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);
    		}
    			}
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,620
    Thanks
    45
    Thanked 1,958 Times in 1,932 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Apr 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Advertisment for Class

    I've Edited an added more to what I would like to know thank for any help in advance

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,620
    Thanks
    45
    Thanked 1,958 Times in 1,932 Posts

    Default 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:
    Scanner s=new Scanner("the answers go here\nwith\nfor end of lines\n"); //System.in);
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 2
    Last Post: November 18th, 2012, 01:09 PM
  2. need to make basic class and implementation class (base class without void main)
    By javanewbie101 in forum Object Oriented Programming
    Replies: 1
    Last Post: September 19th, 2012, 08:03 PM
  3. create a test class (main method) to start(run) the class in Java
    By curious725 in forum Java Theory & Questions
    Replies: 5
    Last Post: August 1st, 2012, 03:21 AM
  4. Replies: 3
    Last Post: June 17th, 2012, 06:22 PM
  5. Replies: 3
    Last Post: April 13th, 2011, 03:30 PM