10 Replies - 576 Views - Last Post: 27 April 2012 - 08:55 AM Rate Topic: -----

#1 sriganeshk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 26-April 12

Guys please help me to find this

Posted 26 April 2012 - 11:46 PM

I am very new to the development side. Please help me to find the answer for this question. If possible please explain me how to do this.

The following simple bit of C# code creates an ArrayList.

It then adds a number of “BoxesOfWidgets” to the ArrayList, adding Widgets within each box.

The method GetRidOfTheSmallWidgets is meant to get rid of all of the widgets with lengths less than 20. Please add the code into this method to search through the ArrayList of boxes, and remove the small widgets from them.

You may not use foreach loops, iterators, or any other loop construct that is language specific.

Is This A Good Question/Topic? 0
  • +

Replies To: Guys please help me to find this

#2 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1150
  • View blog
  • Posts: 2,528
  • Joined: 05-May 05

Re: Guys please help me to find this

Posted 26 April 2012 - 11:52 PM

What have you tried? We are not a coding writing service.
Was This Post Helpful? 0
  • +
  • -

#3 sriganeshk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 26-April 12

Re: Guys please help me to find this

Posted 26 April 2012 - 11:55 PM

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            ArrayList colBoxesOfWidgets = new ArrayList();

            colBoxesOfWidgets.Add(new BoxOfWidgets("Cardboard"));
            ((BoxOfWidgets)colBoxesOfWidgets[0]).colWidgets.Add(new Widget("The blue widget", 12));
            ((BoxOfWidgets)colBoxesOfWidgets[0]).colWidgets.Add(new Widget("The red widget", 15));
            ((BoxOfWidgets)colBoxesOfWidgets[0]).colWidgets.Add(new Widget("The silver widget", 6));
            ((BoxOfWidgets)colBoxesOfWidgets[0]).colWidgets.Add(new Widget("The green widget", 52));

            colBoxesOfWidgets.Add(new BoxOfWidgets("Metal"));
            ((BoxOfWidgets)colBoxesOfWidgets[1]).colWidgets.Add(new Widget("The gold widget", 9));
            ((BoxOfWidgets)colBoxesOfWidgets[1]).colWidgets.Add(new Widget("The orange widget", 115));
            ((BoxOfWidgets)colBoxesOfWidgets[1]).colWidgets.Add(new Widget("The pink widget", 1));

            colBoxesOfWidgets.Add(new BoxOfWidgets("Metal"));
            ((BoxOfWidgets)colBoxesOfWidgets[2]).colWidgets.Add(new Widget("The grey widget", 12));
            ((BoxOfWidgets)colBoxesOfWidgets[2]).colWidgets.Add(new Widget("The black widget", 15));
            ((BoxOfWidgets)colBoxesOfWidgets[2]).colWidgets.Add(new Widget("The white widget", 19));
            ((BoxOfWidgets)colBoxesOfWidgets[2]).colWidgets.Add(new Widget("The brown widget", 60));
            ((BoxOfWidgets)colBoxesOfWidgets[2]).colWidgets.Add(new Widget("The peach widget", 16));


            GetRidOfTheSmallWidgets(colBoxesOfWidgets);
        }


        public static ArrayList GetRidOfTheSmallWidgets(ArrayList colBoxesOfWidgets){

            //Place your code in here
            //It should remove all widgets that have lengths lower than 20.

            return colBoxesOfWidgets;

        }
    }

    class BoxOfWidgets
    {
        public string boxType;
        public ArrayList colWidgets;

        public BoxOfWidgets(string newBoxType)
        {
            boxType = newBoxType;
            colWidgets = new ArrayList();
        }
    }

    class Widget
    {
        public string name;
        public float length;

        public Widget(string newName, float newLength)
        {
            this.name = newName;
            this.length = newLength;
        }
    }


}


MOD EDIT: Added code tags. When posting code...USE CODE TAGS!!!

:code:

This post has been edited by JackOfAllTrades: 27 April 2012 - 03:59 AM

Was This Post Helpful? 0
  • +
  • -

#4 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1150
  • View blog
  • Posts: 2,528
  • Joined: 05-May 05

Re: Guys please help me to find this

Posted 27 April 2012 - 12:07 AM

Put code in [code] tags. Ok, so you're almost there. Surely, you can up the logic to do this. You've managed to get this far. What algorithm have you come up with?

This post has been edited by blackcompe: 27 April 2012 - 12:07 AM

Was This Post Helpful? 0
  • +
  • -

#5 sriganeshk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 26-April 12

Re: Guys please help me to find this

Posted 27 April 2012 - 12:13 AM

View Postblackcompe, on 27 April 2012 - 12:07 AM, said:

Put code in [code] tags. Ok, so you're almost there. Surely, you can up the logic to do this. You've managed to get this far. What algorithm have you come up with?



Hai,

Thanks for the reply first. Actually I am a undergraduate student. This is the test. I am a basic learner of .net. I tried to this much. But i dont know how to do it without for loop and iterations concept.

I want to create a function tat deletes data..
Was This Post Helpful? 0
  • +
  • -

#6 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1150
  • View blog
  • Posts: 2,528
  • Joined: 05-May 05

Re: Guys please help me to find this

Posted 27 April 2012 - 12:51 AM

They're testing your knowledge of recursion. Try and come up with a solution or some psuedocode at least.
Was This Post Helpful? 0
  • +
  • -

#7 sriganeshk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 26-April 12

Re: Guys please help me to find this

Posted 27 April 2012 - 03:25 AM

View Postblackcompe, on 27 April 2012 - 12:51 AM, said:

They're testing your knowledge of recursion. Try and come up with a solution or some psuedocode at least.


First Arraylist is colBoxesOfWidgets
colBoxesOfWidgets.Add(new BoxOfWidgets("Cardboard"));- This line Adds a new BoxOfWidget item
'CardBoard' and also adds a new Arraylist called colWidgets
The subequent lines add items in the new arraylist colWidgets
so the stucture of the arraylist is
In the 0th location of Arraylist colBoxesOfWidgets there is a new arraylist colWidgets where colwidgets
contains items Cardbox,blue widget,red widget,silver widget etc
In the 1st location of Arraylist colBoxesOfWidgets there is a new arraylist colWidgets where colwidgets
contains items metal,gold widget,orange widget,pink widget etc
Same with the 2nd location as well

I dont know how to write the formal code for this...
Was This Post Helpful? 0
  • +
  • -

#8 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2241
  • View blog
  • Posts: 9,412
  • Joined: 29-May 08

Re: Guys please help me to find this

Posted 27 April 2012 - 04:08 AM

I find it easier when do recursion to start with the base case first.
Was This Post Helpful? 0
  • +
  • -

#9 sriganeshk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 26-April 12

Re: Guys please help me to find this

Posted 27 April 2012 - 04:10 AM

View PostAdamSpeight2008, on 27 April 2012 - 04:08 AM, said:

I find it easier when do recursion to start with the base case first.



Thank you..
Was This Post Helpful? 0
  • +
  • -

#10 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8938
  • View blog
  • Posts: 33,504
  • Joined: 12-June 08

Re: Guys please help me to find this

Posted 27 April 2012 - 07:24 AM

Really? Straight jacking code from 2008? That would probably be the biggest reason why you don't understand what is going on - you didn't write this! A stern wag of the finger for that!
Was This Post Helpful? 0
  • +
  • -

#11 h4nnib4l  Icon User is offline

  • The Noid
  • member icon

Reputation: 1181
  • View blog
  • Posts: 1,673
  • Joined: 24-August 11

Re: Guys please help me to find this

Posted 27 April 2012 - 08:55 AM

Did you receive the majority of this code from your professor with the instructions to write the missing method(s), or did you really just jack all of that code and then ask us how to use it?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1