3 Replies - 5735 Views - Last Post: 12 November 2012 - 08:02 PM Rate Topic: -----

#1 tmohney   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 12-November 12

Help with C# homework assignment. Carpenter Desk Program.

Posted 12 November 2012 - 02:35 PM

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

2. Create properties for each field as required.
a. the property for the total cost of the desk should be read only
3. Create a Method to calculate the cost of the desk
4. 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?

Is This A Good Question/Topic? 0
  • +

Replies To: Help with C# homework assignment. Carpenter Desk Program.

#2 Atli   User is offline

  • Enhance Your Calm
  • member icon

Reputation: 4240
  • View blog
  • Posts: 7,216
  • Joined: 08-June 10

Re: Help with C# homework assignment. Carpenter Desk Program.

Posted 12 November 2012 - 02:38 PM

Moved to the C# forum. Please try to post your questions in the correct forums.
Was This Post Helpful? 0
  • +
  • -

#3 danzar   User is offline

  • D.I.C Head
  • member icon

Reputation: 9
  • View blog
  • Posts: 108
  • Joined: 10-December 08

Re: Help with C# homework assignment. Carpenter Desk Program.

Posted 12 November 2012 - 07:27 PM

TotalCost was never assigned to the total cost of the items.
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 6406
  • View blog
  • Posts: 21,976
  • Joined: 05-May 12

Re: Help with C# homework assignment. Carpenter Desk Program.

Posted 12 November 2012 - 08:02 PM

Actually even worse, the Main method's code refers to a TotalCost property that does not even exist on the Desk class.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1