2 Replies - 734 Views - Last Post: 08 October 2011 - 07:29 PM Rate Topic: -----

#1 Joe_  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 08-October 11

ACSL Post Office Question

Posted 08 October 2011 - 03:22 PM

ACSL
American Computer Science League

Junior Division
ACSL POST OFFICE

PROBLEM: The ACSL Post Office is going online and needs you to write the algorithm to determine the postage class for entered mail. Postage class is determined by the size of a piece of mail. The length of a piece of mail is always the side parallel to the written address. The following mutually exclusive definitions are used to determine a postage class:

REGULAR POST CARD: The length must be between 3.5 and 4.25 inches, inclusive. The height must be between 3.5 and 6 inches, inclusive. The thickness must be between .007 and .016 inches, inclusive.

LARGE POST CARD: The length must be between 4.25 and 6 inches. The height must be between 6 and 11.5 inches. The thickness must be between .007 and .016 inches, inclusive.
ENVELOPE: The length must be between 3.5 and 6.125 inches, inclusive. The height must be between 5 and 11.5 inches, inclusive. The thickness must be between .016 and .25 inches.
LARGE ENVELOPE: The length must be between 6.125 inches and 24 inches. The height must be between 11 and 18 inches, inclusive. The thickness must be between .25 and .5 inches, inclusive.
PACKAGE: Use package class when the item exceeds all the rules for large envelope and when the length plus the distance around the other sides of a package equals 84 inches or less.
LARGE PACKAGE: Use large package class when the length plus the distance around the other sides of a package is more than 84 inches but is not more than 130 inches.
UNMAILABLE: Any item that does not conform to any of the above requirements.
INPUT: There will be 5 input lines. Each line will contain 3 rational numbers that represent in order the length, width and thickness of a piece of mail.
OUTPUT: For each input, print the postage class according to the rules above.




Remember ACSL’s prime directive: All data must be entered in one RUN of the program. If your program stops, no other data may be entered. If incorrect data is entered, the data is re-entered from the beginning. We suggest that you design your program so that the output is printed after each set of inputs is entered.
SAMPLE INPUT SAMPLE OUTPUT
1. 4, 4, .009 1. regular post card
2. 5, 7, .013 2. large post card
3. 5, 7, .2 3. envelope
4. 10, 12, .4 4. large envelope
5. 10, 12, 30 5. large package




import java.util.Scanner;

public class PostOffice
{
	public static void main(String[] args)
	{
		//declare variables
		double length;
		double height;
		double thick;
		Scanner kbd = new Scanner(System.in);
		
		//process the data
	for (int k = 1; k <= 5; k++)
		{
		
		//obtained data
		System.out.println(k + ". ");
			
		System.out.println("Enter Mail Length: ");
		length = kbd.nextDouble();
		
		System.out.println("Enter Mail Height: ");
		height = kbd.nextDouble();
		
		System.out.println("Enter Mail Thickness: ");
		thick = kbd.nextDouble();
		
		double perimeter = thick + thick + height + height;
		
		//output results 
		if ((length >= 3.5) && (length <= 4.25) && (height >= 3.5) 
			&& (height <= 6) && (thick >= .007) && (thick <= .016))
			{
				System.out.println();
				System.out.println("REGULAR POST CARD");
				System.out.println();
			}
		else if ((length >= 4.25) && (length <= 6) && (height >= 5) 
			&& (height <= 11.5) && (thick >= .007) && (thick <= .016))
			{	
				System.out.println();
				System.out.println("LARGE POST CARD");
				System.out.println();
			}
		else if ((length >= 3.5) && (length <= 6.125) && (height >= 6) 
			&& (height <= 11.5) && (thick >= .016) && (thick <= .25))
			{
				System.out.println();
				System.out.println("ENVELOPE");
				System.out.println();
			}
		else if ((length >= 6.125) && (length <= 24) && (height >= 11) 
			&& (height <= 18) && (thick >= .25) && (thick <= .5))
			{
			
				System.out.println();
				System.out.println("LARGE ENVELOPE");
				System.out.println();
			}
		else if ((length >= 24) && (height >= 18) && (thick >= .5) 
			&& ((length + perimeter) <=84))  
			{
				System.out.println();
				System.out.println("PACKAGE");
				System.out.println();
			}
		else if ((length + perimeter > 84) && (length + perimeter <= 130))
			{
				System.out.println();
				System.out.println("LARGE PACKAGE");
				System.out.println();
			}
		else
			{
			
				System.out.println();
				System.out.println("UNMAILABLE");
				System.out.println();
			}
			
		}
	}
}



When I try to run, it says "editor does not contain a main type."

Is This A Good Question/Topic? 0
  • +

Replies To: ACSL Post Office Question

#2 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2197
  • View blog
  • Posts: 5,224
  • Joined: 10-September 10

Re: ACSL Post Office Question

Posted 08 October 2011 - 04:45 PM

Your revised post is much improved over your first version.

I do not get the same error when I compile and run your code. In fact, it runs to completion. So you will need to provide more info about the conditions under which the error you describe occurs.

Are you running from the command line? What is the name of the source code file? What commands are you using at the command line to compile the source code and then run the .class file? What is the error exactly? Cut and paste the error into your next post that answers my other questions. (It's unlikely that the word 'editor' appears in an error message, but I suppose it's possible.)

Edit: I've also reviewed your logic and its conformance to the assignment's requirements, and I see that some adjustments must be made. Review the assignment and the Sample Input and Sample Output. I admit that I'm a little confused when I compare the assignment with the sample inputs and outputs, but hopefully you have some additional knowledge that makes it clearer to you.

This post has been edited by GregBrannon: 08 October 2011 - 04:57 PM

Was This Post Helpful? 0
  • +
  • -

#3 immeraufdemhund  Icon User is offline

  • D.I.C Regular

Reputation: 79
  • View blog
  • Posts: 495
  • Joined: 29-March 10

Re: ACSL Post Office Question

Posted 08 October 2011 - 07:29 PM

so what is a piece of mail that is 3.5x5x.016

because it can be a post card, or a envelope with the inclusive. Obviously the cheaper bet is post card... but guessing isn't a good thing.

and I just found another little strange thing that the envelope height max is 0.5 inches bigger than the minimum of large envelope. which yet again you can have a gray area. Does a piece of mail that is 6.125x11.5x.25 get classified by envelope or large envelope. Because it fulfills both categories.

so I made the program according to the specifications outlined in your assignment, and I thought I'd share my output of one :)

Please Enter Length
4.25
Please Enter Width
6.0
Please Enter Depth
.016
Post Card - true
Large Post Card - true
Envelope - true
Large Envelope - false



and my ugly code, although it is not all of it so the OP can't copy and paste

    Mail smallPostCard = new Mail("Post Card",3.5,4.25,3.5,6.0,0.007,0.016);
    Mail largePostCard = new Mail("Large Post Card",4.25,6.0,6.0,11.5,0.007,0.016);
    Mail smallEnvelope = new Mail("Envelope",3.5,6.125,5.0,11.5,0.016,0.25);
    Mail largeEnvelope = new Mail("Large Envelope",6.125,24.0,11.0,18.0,0.25,0.5);
    
    mailCall.add(smallPostCard);
    mailCall.add(largePostCard);
    mailCall.add(smallEnvelope);
    mailCall.add(largeEnvelope);
    
    Scanner key = new Scanner(System.in);
    System.out.println("Please Enter Length");
    double length = key.nextDouble();
    System.out.println("Please Enter Width");
    double width = key.nextDouble();
    System.out.println("Please Enter Depth");
    double depth = key.nextDouble();
    
    for (Mail temp:mailCall)
      System.out.println(temp.toString()+ " - " +temp.isThisMail(length, width, depth));
    
    key.close();


This post has been edited by immeraufdemhund: 09 October 2011 - 03:35 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1