Question

I'm trying to finish debugging this C# problem. It will compile, but throws a warning: warning...

I'm trying to finish debugging this C# problem. It will compile, but throws a warning: warning CS0649: Field `DebugTen2.Street.name' is never assigned to, and will always have its default value `null'. I've tried a few ways to fix it, but the street names are still not coming out properly.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DebugTen2
{
class Class
{
public static void Main()
{

OneWayStreet oak = new OneWayStreet("Oak Avenue", "east");
TwoWayStreet elm = new TwoWayStreet("Elm Street", "south");
Console.WriteLine("On " + oak.Name + " " + oak.MakeUTurn());
Console.WriteLine("On " + oak.Name + " " + oak.MakeUTurn());
Console.WriteLine("On " + elm.Name + " " + elm.MakeUTurn());
Console.WriteLine("On " + elm.Name + " " + elm.MakeUTurn());
Console.ReadKey();
}
}

abstract class Street
{
public string name;
public string direction;
public Street(string name, string Direction)
{
name = Name;
direction = Direction;
}
public string Name
{
get
{
return name;
}
}
public string Direction
{
get
{
return direction;
}
}
public abstract string MakeUTurn();
}
class OneWayStreet : Street
{
public OneWayStreet(string name, string direction)
: base(name, direction)
{
}
public override string MakeUTurn()
{
string temp = "U Turn is illegal! Was going and still going " + direction;
return temp;
}
}
class TwoWayStreet : Street
{
public TwoWayStreet(string name, string direction)
: base(name, direction)
{
}
public override string MakeUTurn()
{
string wasGoing = Direction;
string[] directions = { "north", "south", "east", "west" };
string[] oppDirections = { "south", "north", "west", "east" };
for (int x = 0; x < directions.Length; ++x)
{
if (direction.Equals(directions[x]))
{
direction = oppDirections[x];
x = directions.Length;
}
}
string temp = "U Turn successful. Was going " + wasGoing +
". Now going " + direction;
return temp;
}

}


}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

/**
*C sharp program is demonstrates the Street and OneWayStreet classes.
* The changes made to the Stree class are shown in bold letters.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DebugTen2
{
    class Class
    {
        public static void Main()
        {

            OneWayStreet oak = new OneWayStreet("Oak Avenue", "east");
            TwoWayStreet elm = new TwoWayStreet("Elm Street", "south");
            Console.WriteLine("On " + oak.Name + " " + oak.MakeUTurn());
            Console.WriteLine("On " + oak.Name + " " + oak.MakeUTurn());
            Console.WriteLine("On " + elm.Name + " " + elm.MakeUTurn());
            Console.WriteLine("On " + elm.Name + " " + elm.MakeUTurn());
            Console.ReadKey();
        }
    }
}


------------------------------------------------------------------------------------------

//Street.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DebugTen2
{
    abstract class Street
    {
        public string name;
        public string direction;
       /*Get values of name and direction for the constructor of Stree class*/
        public Street(string name, string direction)
       {
           //Set values for name and direction of this class
            this.name = name;
            this.direction = direction;
       }
        public string Name
        {
           //Create set method for Name property
            set { name = value; }
           get{return name;}
        }
        public string Direction
        {
           //Create set method for Direction property
            set { name = value; }
           get{return direction;}
        }
        public abstract string MakeUTurn();
    }
}

------------------------------------------------------------------------------------------

//OneWayStreet.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DebugTen2
{
    class OneWayStreet : Street
    {
        public OneWayStreet(string name, string direction)
            : base(name, direction)
        {
        }
        public override string MakeUTurn()
        {
            string temp = "U Turn is illegal! Was going and still going " + direction;
            return temp;
        }
    }
    class TwoWayStreet : Street
    {
        public TwoWayStreet(string name, string direction)
            : base(name, direction)
        {
        }
        public override string MakeUTurn()
        {
            string wasGoing = direction;
            string[] directions = { "north", "south", "east", "west" };
            string[] oppDirections = { "south", "north", "west", "east" };
            for (int x = 0; x < directions.Length; ++x)
            {
                if (direction.Equals(directions[x]))
                {
                    direction = oppDirections[x];
                    x = directions.Length;
                }
            }
            string temp = "U Turn successful. Was going " + wasGoing +
            ". Now going " + direction;
            return temp;
        }

    }
}

------------------------------------------------------------------------------------------

Sample Output:

On Oak Avenue U Turn is illegal! Was going and still going east On Oak Avenue U Turn is illegal! Was going and still going On

Add a comment
Know the answer?
Add Answer to:
I'm trying to finish debugging this C# problem. It will compile, but throws a warning: warning...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C# Hey I am having trouble implementing additonal function to this assignment: Problem: Implement three IComparer classes on Employee - NameComparer, AgeComparer, and PayComparer - that allow Employee...

    C# Hey I am having trouble implementing additonal function to this assignment: Problem: Implement three IComparer classes on Employee - NameComparer, AgeComparer, and PayComparer - that allow Employees to be compared by the Name, Age, and Pay, respectively. Code: Employee.Core.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Employees { partial class Employee { // Field data. private string empName; private int empID; private float currPay; private int empAge; private string empSSN = ""; private string empBene...

  • #2 You are going to add more code to carClass.cpp. 0. Make sure you finished the...

    #2 You are going to add more code to carClass.cpp. 0. Make sure you finished the lab part: goForward, turnRight(), getDirection(), getXO, getY() and get Modelo 1. Preparation: In the last lab, we tested our functions using cl. Comment out that section. Create c2 with any make and model. int main() Car cl("Toyota", "Camry") 77777777777777 lereate c2 here Tested the functions in the last lab cout <<cl.getModel() << endl; Comment out this section cout <<cl.getX() <<"*«<cl.getY() << endl; return 0;...

  • Hello in C#. I need help understanding and knwoing what i missed in my program. The...

    Hello in C#. I need help understanding and knwoing what i missed in my program. The issue is, the program is supposed to have user input for 12 family members and at the end of the 12 it asks for user to input a name to search for. When i put a correct name, it always gives me a relative not found message. WHat did i miss. And can you adjust the new code so im able to see where...

  • For this problem, we are going to revisit the Online Company exercise from lesson 3. In...

    For this problem, we are going to revisit the Online Company exercise from lesson 3. In lesson 3, we created 3 classes, a superclass Company, a subclass OnlineCompany and a runner class CompanyTester. You can take your solutions from lesson 3 for the Company and OnlineCompany, but we are going to redesign the CompanyTester in this exercise. Your task is to create a loop that will allow users to enter companies that will then get stored in an ArrayList. You...

  • C#: Implement a multiplayer Battleship game with AI The rules are the same as before. The...

    C#: Implement a multiplayer Battleship game with AI The rules are the same as before. The game is played on an NxN grid. Each player will place a specified collection of ships: The ships will vary in length (size) from 2 to 5; There can be any number or any size ship. There may be no ships of a particular size; EXCEPT the battleship – which there will always be 1 and only 1. Player order will be random but...

  • The Problem A robot is asked to navigate a maze. It is placed at a certain...

    The Problem A robot is asked to navigate a maze. It is placed at a certain position (the starting position) in the maze and is asked to try to reach another position (the goal position). Positions in the maze will either be open or blocked with an obstacle. Positions are identified by (x,y) coordinates. At any given moment, the robot can only move 1 step in one of 4 directions. Valid moves are: ● Go North: (x,y) -> (x,y-1) ●...

  • guys need help please im super lost anyone save me do programming exercise top_div_array.cpp: Winning Division...

    guys need help please im super lost anyone save me do programming exercise top_div_array.cpp: Winning Division app (top_div.cpp) revisited to use arrays This is the same program done last week but using and passing arrays instead of individual variables. Start with the following file / cODE BELOW: // Name: top_div_array.cpp // Description: // This app inputs sales for four regional division and displays the highest. // To accomplish this, use two arrays of equal length - one for sales and...

  • please write the code in C++ 2 Base class File 3 Derived class PDF 3.1 Class...

    please write the code in C++ 2 Base class File 3 Derived class PDF 3.1 Class declaration • The class PDF inherits from File and is a non-abstract class 1. Hence objects of the class PDF can be instantiated. 2. To do so, we must override the pure virtual function clone) in the base class • The class declaration is given below. • The complete class declaration is given below, copy and paste it into your file. . It is...

  • ------------------------------------------------------------------------------------------------------------ CODE ALREADY HAVE BELOW--------------------------------------------------------------------------------------- public class LinkedQueue<T>

    ------------------------------------------------------------------------------------------------------------ CODE ALREADY HAVE BELOW--------------------------------------------------------------------------------------- public class LinkedQueue<T> implements QueueADT<T> {    private int count;    private LinearNode<T> head;    private LinearNode<T> tail;               public LinkedQueue()    {        count = 0;        head = null;        tail = null;    }    @Override    public void enqueue(T element)    {        LinearNode<T> node = new LinearNode<T> (element);        if(isEmpty())            head = node;        else           ...

  • Please help with my car traffic simulator! Code that I already have below, I do not know how to...

    Please help with my car traffic simulator! Code that I already have below, I do not know how to start it off! public class IntersectionSimulation { private final static int EAST_WEST_GREEN_TIME = 30 ; private final static int[] NORTH_SOUTH_GREEN_TIMES = { 20, 24, 30, 42 } ; private final static int[] CAR_INTERSECTION_RATES = { 3, 5, 10 } ; private final static int[] CAR_QUEUEING_RATES = { 5, 10, 30 } ; private final static int[] EXPERIMENT_DURATIONS = { 3*60, 5*60,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT