Click here to Skip to main content
15,911,030 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So i got this assignment which requires me to use classes, if's ad for cycles(if needed).
1.Create a class called "Nail" that has variables for storing length and thickness. The store has three types of Nails. Find which nails are the longest and the thickest.


So i've done the first task. Now on the second im lost:

2.Create a class  called "Box" that stores variables for length, width and height of the box(already did this). You need to construct the box in which nails are hammered in every 10 cm if their length is 8 cm or every 15 cm if their length is 10 cm. Calculate how many nails are needed?


3.Add some variables in the "Box" class to the Insert () method, which allows you to change the size of the box - length, width and height. Of which
nails will be needed the most if we increase the box height "x" cm?


I really need some help with this im lost...I need to calculate the area of the box, atleast thats how i think, idk maybe theres another way to calculate all of this...

So heres my code;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace tss
{
    class Nail  //Dont pay attention to weigth
    {
        private int length, thickness, weight;

        public Nail(int naillength, int nailthickness, int nailweight)
        {
            length = naillength;
            thickness = nailthickness;
            weight = nailweight;
        }


        public int TakeLength() { return length; }

        public int TakeThickness() { return thickness; }

        public int TakeWeight() { return weight; }

    }
    class Box
    {
        private int length, wideness, height;

        public Box(int boxlength, int boxwideness, int boxheight)
        {
            length = boxlength;
            wideness = boxwideness;
            height = boxheight;
            length = int.Parse(Console.ReadLine());
            wideness = int.Parse(Console.ReadLine());
            height = int.Parse(Console.ReadLine());

        }


        public int TakeLength() { return length; }

        public int TakeWideness() { return wideness; }

        public int TakeHeight() { return height; }
    }
    class Calculations
    {
        static void Main(string[] args)
        {
            Nail p1;
            p1 = new Nail(8, 5, 4);
            Console.WriteLine("1st - nail length: {0,3:d} cm \n1st - nail thickness {1, 4:d} mm \n1st - nail weigth: {0,5:d} g",
                p1.TakeLength(), p1.TakeThickness(), p1.TakeWeight());

            Nail p2;
            p2 = new Nail(10, 6, 5);
            Console.WriteLine("2nd - nail length: {0,3:d} cm \n2nd - nail thickness: {1, 4:d} mm \n2nd - nail weigth: {0,5:d} g",
                p2.TakeLength(), p2.TakeThickness(), p2.TakeWeight());

            Nail p3;
            p3 = new Nail(12, 7, 6);
            Console.WriteLine("3st - nail length: {0,5:d} cm \n3 - nail thickness: {1, 4:d} mm \n3 - nail weigth: {0,5:d} g",
                p3.TakeLength(), p3.TakeThickness(), p3.TakeWeight());

            /// This finds the biggest value
            Console.WriteLine(Math.Max(Math.Max(p1.TakeLength(), p2.TakeLength()), p3.TakeLength()));
            Console.WriteLine(Math.Max(Math.Max(p1.TakeThickness(), p2.TakeThickness()), p3.TakeThickness()));

            Box d1;
            d1 = new Box(1, 1, 1);
            Console.WriteLine("Box length: {0,5:d} cm \nBox wideness: {1, 4:d} cm \nBox height: {0,5:d}cm",
                d1.TakeLength(), d1.TakeWideness(), d1.TakeHeight());

            }
        }
    }
}

Havent really found a way how to calculate how many nails i need..

What I have tried:

Tried everything. I just need help on how i should build this program.
Posted
Updated 22-Sep-18 1:59am

1 solution

So, you have the length, width, and height of the box. From that, you can determine the "length" of the area you need to nail.
Assuming you need a closed box then you need to nail it all the way round two opposite sides, and along the four remaining edges which join them. So the "Total length" to nail will be
T = (H * 2 + L * 2) * 2 + 4 * W
Then look at what nails you have. The question only lists two sizes: 8cm long, and 10cm long and tells you what spacing to use.

Your job is to work out how many 10cm nails to use, and how many 8 cm nails. start by using the 10cm into each edge, then "fill in the gaps" with 8cm when there isn't enough side to get another 10cm in.

Try it on paper first: it should be clearer.
 
Share this answer
 
Comments
Member 13975230 22-Sep-18 16:32pm    
Ok got it, so how do i write a function which nails every 10cm or 15cm, do i need to use some sort of for cycle?
OriginalGriff 23-Sep-18 3:00am    
Well you will need a loop of some kind, and "for" or "while" are the ones you need to look at.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900