Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6627539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:01:35+00:00 2026-05-25T22:01:35+00:00

I am trying to print multiple Information entries that will be inserted in an

  • 0

I am trying to print multiple Information entries that will be inserted in an array as an object, and I want to use the methods that are available to those objects and print the result. This is my code. I am getting an error in my last two sentences

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

namespace homework2
{

    class Shapes
    {
        protected string ShapeName;
        protected double ShapeWidth;
        protected double ShapeHeight;

        public Shapes(string ShapeName, double ShapeWidth, double ShapeHeight)

        {
            this.ShapeName = ShapeName;
            this.ShapeWidth = ShapeWidth;
            this.ShapeHeight = ShapeHeight;

        }

    }

    class Rectangle : Shapes 
    {
        public Rectangle(string ShapeName, double ShapeWidth, double ShapeHeight)
            : base(ShapeName, ShapeWidth, ShapeHeight) 
        {
            this.ShapeName = ShapeName;
            this.ShapeWidth = ShapeWidth;
            this.ShapeHeight = ShapeHeight;

        }

        public double GetArea()
        {
            if (ShapeName == "Circle")
            {
                ShapeHeight = 3.14;
                double x = ShapeHeight * (ShapeWidth * ShapeWidth);
                return x;
            }
            else
            {

                double Area = ShapeHeight * ShapeWidth;
                return Area;
            }

        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Rectangle Rec = new Rectangle("Circle",5,2);
            System.Console.WriteLine("This is the Rectangle Area :"+Rec.GetArea());

            System.Console.WriteLine("Please Enter How Many Shapes You want To enter:");
            String x =  Console.ReadLine();
            int y = int.Parse(x);
            for (int i = 0; i <= y; i++ )
            {
                System.Console.WriteLine("Enter Name for Shape No."+i+"Please");
                String ShapeName = Console.ReadLine();
                System.Console.WriteLine("Enter width for Shape No." + i + "Please");
                String ShapeWidth = Console.ReadLine();
                int sw = int.Parse(ShapeWidth);
                System.Console.WriteLine("Enter height for Shape No." + i + "Please");
                String ShapeHeight = Console.ReadLine();
                int sh = int.Parse(ShapeHeight);
                for(int j = 0; j < 4; j++)
                {

                      Rectangle[,] z = new Rectangle[y,4];                    
                Rectangle z[i,j] = new Rectangle(ShapeName, sw, sh);
                }


            }
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T22:01:36+00:00Added an answer on May 25, 2026 at 10:01 pm

    Firstly, in your derived class Rectangle, you do not need to reassign the variables in shape as the base constructor will still be called.

    Also, it would make more sense to, instead of passing in a string like “Circle” to create a circle, to create a new class Circle : Shapes that implemented a different GetArea() rather than having your rectangle class calculate the area of a circle.

    The error you are presumably having is with the line:

    Rectangle z[i,j] = new Rectangle(ShapeName, sw, sh);
    

    Because you have already defined z[i,j] as an array this line should read

    z[i,j] = new Rectangle(ShapeName, sw, sh);
    

    (Without the rectangle).

    However, I suspect you want to define your array of Rectangles outside of the first for loop. With the current code, you are going to end up with y 2D arrays with one column filled in for each one. You need to move this: outside of the first for loop
    Rectangle[,] z = new Rectangle[y,4];

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to print a report that contains a bar graph using the
I'm trying to print a WPF canvas over multiple pages. I'm perfectly happy with
I've been trying to figure out a command that will search through 13+ files
I'm trying to print out a number of posts from multiple post types. However,
Im trying to send an email to multiple addresses, so I wrote function that
I'm trying to allow a user to print multiple tables depending on what they
I'm trying to open multiple pages following a certain format using mechanize. I want
I've created a dynamic table that will pull information from a database. However, there
I am new to Java programming, I am trying to print names, read multiple
I am trying to have a program that uses multiple forks. I used this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.