Write a program that accepts as input three positive integers representing the diameter of the cigarettes to be packed

and the dimensions of the pack to be used.

The required output is the maximum number of cigarettes that can be packed without damaging/re-sizing the cigarettes or packs

NOTE: the diameter of cigarette is 1 and 2 only.

Example: Diameter is: 1 and dimension1: 2 and dimension2: 4

the output is. Maximum number of cigarettes can be put on the pack is 6.

ex.2 diameter is 2 and dimension is 10 and dimension2 is 17

the output is. The maximum number of cigarettes can be put on pack is 40.

ex.3 diameter is 2 and dimension is 5 and dimension2 is 7

the output is. The maximum number of cigarettes can be put on pack is 6.

THANKS IN ADVANCE! I just need the formula to get the number of cigarettes that can be put inside on the pack on its dimension

sorry for my bad grammar lol.

- 1

I'm not sure you're going to get the help you're looking for here. We are NotACodeMill and will not do the work for you. Particularly if it's homework, when we encourage you to DoYourOwnHomework.

The best way to get help is to show us what you've done or tried so far, and tell us exactly the problem you're facing right now.

Tim Driven Development

But if my diameter is 2 i really have a hard time to get it. sorry

But ignoring that...

If you have a box that is eight units wide, and each object takes two units of space, how many object can you put across the width?

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors

- 1

mark patindol wrote:the No.1 example on my work is easy to understand. just multiply the dimension1 which is 2 and dimension 2 which is 4. then multiply on the diameter which is 1. so that the maximum number of cigarettes can be put on the pack is 8.

But if my diameter is 2 i really have a hard time to get it. sorry

How many 2s are there in 4? How many 2s are there in 6? How many 2s are there in 7? Those are very simple calculations that involve a basic arithmetic operation.

*Practice only makes habit, only perfect practice makes perfect.
Practice mindfully by doing the right things and doing things right.*— Junilu

[How to Ask Questions] [How to Answer Questions]

*Practice only makes habit, only perfect practice makes perfect.
Practice mindfully by doing the right things and doing things right.*— Junilu

[How to Ask Questions] [How to Answer Questions]

Just look at one of the examples given in the opening post.

When D = 2, d1 = 10 and d2 = 17, then, according to the

answer given, 40 cigarettes fit. So it is not necessary to

go the complex honeycomb way, that Fred was also hinting

at. So, to OP, look at Junilu's first reply. That's how to proceed.

/********************************/

However, as an easy to calculate upperbound for the number:

what, given a diameter D, is the area of a cigarette, and

what is the area of the package, given dimensions d1 and d2?

According to this view, 54 cigarettes would fit.

(all as seen from above!)

But this is an upperbound. Take D = 1 and d1 = d2 = 1.4.

The formula now gives 2, but only one fits.

And of course, we have the requirements:

d1 >= D AND d2 >= D, otherwise no cigarette will fit.

Greetz,

Piet

Junilu Lacar wrote:I don't know if you are supposed to consider the fact that cigarettes can be arranged in honeycomb pattern in a pack.

That was my thought too.

Oddly enough, manufacturers (at least I assume it was them) came up with a very neat solution to one of the tax hikes on tobacco in Belgium by reducing the number of cigarettes in a pack from 20 to 19, presumably so they could still sell them for the same price. All they needed to do was change the configuration from 7-6-7 (20) to 6-7-6 (19), and everything else - in particular, package size - remained the same.

Stupid piece of trivia for you .... and, of course it only works

*once*.

Winston

"Leadership is nature's way of removing morons from the productive flow" - Dogbert

Articles by Winston can be found here

Junilu Lacar wrote:

mark patindol wrote:the No.1 example on my work is easy to understand. just multiply the dimension1 which is 2 and dimension 2 which is 4. then multiply on the diameter which is 1. so that the maximum number of cigarettes can be put on the pack is 8.

But if my diameter is 2 i really have a hard time to get it. sorry

How many 2s are there in 4? How many 2s are there in 6? How many 2s are there in 7? Those are very simple calculations that involve a basic arithmetic operation.

thanks i got it know. but the output of my program is always 0 i think i have a wrong code.

What's more is that you are both multiplying and dividing dimensionOne, the result of that is that the multiplying and division cancel each other out, so what you are effectively left with is:

In your example dimensionTwo is greater than diameter, therefore due to the way java handles integer division you will get 0.

Also for next time copy and paste your code into your post, just use code tags, or hit the code button on top to automatically create code tags.