Hello,
I am taking my first basic computer programming course. We are learning how to use C# in Visual Studio. Recently we started learning about classes and how they work in OOP. I get the idea of what they are and what they do. I am having a problem writing the code that is needed for my homework assignment. Here is the assignment.
A local carpenter creates desks according to customers orders. The cost of the desk is based on the following:
1. the desk length and width in inches
2. the type of wood
3. the number of drawers
The price is calculated as follows:
1 Minimum charge of 250.00
2.If surface area is greater than 720 square inches, there is an additional 50.00 added.
3. The charge for different kinds of wood are as follows:
a. Pine - no charge
b. Mahogany - 160.00
c. Oak - 110.00
4. The basic desk has no drawers. For each drawers added, there is an additional 35.00 charge
5. There is a sales tax of 9%
THE DESK CLASS
1. Create an object oriented class named Desk that has fields for the following:
a. desk length
b. desk width
c. type of wood
d. number of drawers
e. cost for mahogany
f. cost for oak
g. surface charge
h. drawer charge
i. total cost of desk
- Create properties for each field as required.
a. the property for the total cost of the desk should be read only - Create a Method to calculate the cost of the desk
- Note:
a. All calculations are done by the Desk class
b. No user inputs our outputs are done by the Desk class
THE PROGRAM CLASS:
1. Accepts user inputs for all values required to determine the final cost of the desk. Each input must be preceded by a prompt
2. Creates and uses an object of the Desk class to
a. pass the inputs to the correct properties of the object
b. retrieve the total cost of the desk from the object
3. Displays the user inputs as well as the final cost of the Desk.
4. Note:
a. The program class provides for all inputs/outputs of the program
b. The program class does no calculations.
HERE IS THE CODE I HAVE WRITTEN FOR THE PROGRAM CLASS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Desk newDesk = new Desk();
Console.WriteLine("Please enter the length you would like the desk to be in inches.");
newDesk.DeskLength = Convert.ToInt32 (Console.ReadLine());
Console.WriteLine("Please enter the width you would like the desk to be in inches.");
newDesk.DeskWidth = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("What type of wood would you like? Pine, Mahogany (+$160.00), or Oak (+$110.00).");
newDesk.DeskWood =Convert.ToString( Console.ReadLine());
Console.WriteLine("There is a $30.00 charge for each drawer. How many drawers would you like?");
newDesk.DeskDrawers = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Total Cost is,{0}", newDesk.TotalCost );
Console.ReadKey();
}
}
}
HERE IS THE CODE I HAVE WRITTEN FOR THE DESK CLASS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
public class Desk
{
int deskLength;
int deskWidth;
string deskWood;
int deskDrawers;
int mahogcost = 160;
int oakCost = 110;
int surfaceCharge;
int drawerCost;
double taxAmt = 0.09;
int totalCost;
public int DrawerCost
{
get{return drawerCost;}
set{drawerCost = value;}
}
public int DeskLength
{
get { return deskLength; }
set { deskLength = value;
CalculateAreacost(); }
}
public int DeskWidth
{
get { return deskWidth; }
set { deskWidth = value;
CalculateAreacost(); }
}
public string DeskWood
{
get { return deskWood; }
set { deskWood = value; }
}
public int DeskDrawers
{
get { return deskDrawers; }
set { deskDrawers = value;
CalculateDrawer(); }
}
public int SurfaceCharge
{
get { return surfaceCharge; }
set { surfaceCharge = value; }
}
public void CalculateDrawer()
{
drawerCost = 30 * DeskDrawers;
}
public void CalculateAreacost()
{
if (DeskLength * DeskWidth > 720) surfaceCharge = 50;
else surfaceCharge = 0;
}
}
}
I had my friend help me with a few of the things, he is no longer available though. The main issue I am running into is
1. Creating code that takes the user input given for the wood type and assigning it to a value such as 110 for oak or 160 for mahogany.
2. How to create a method in the Desk class that adds wood type, drawer charge, surface charge, 250.00, 9% sales tax. Then being able to take the total amount and return it and all original user inputs back to main and be able to display them.
Every time I believe to be making progress and write some code. I go to test it in main by plugging it into a readline. Based on user inputs it should calculate a total, however I always yield 0. The reason I posted the full assignment is to see what my specific instructions are. I don't believe I should have as many variables declared in the Desk class. But based upon the instructions, I feel I have to?