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
{
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());
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.