Question

Modern language elements Write a string store class to manage string value in a member variable named        string. The variable’s value should be setable and retrievable using a property named Data....

Modern language elements

Write a string store class to manage string value in a member variable named        string. The variable’s value should be setable and retrievable using a property named Data. The string store class must also publish an event which is emitted if the data field’s value is changed to null. The event must provide the number of times the value was changed to null (including the current case) as its parameter. The event should not be emitted if the previous value was also null.

Provide the complete c# code of the String store class as well as a short code snippet that creates an instance of it. Subscribes to the event and prints the number of times the value was changed to null as reported by the event. Don’t use specialized event types define.

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

// C# program to count occurrences of null element
using System;
class LinkedList
{
   Node head; // head of list

   /* Linked list Node*/
   public class Node
   {
       public int data;
       public Node next;
       public Node(int d) {data = d; next = null; }
   }

   /* Inserts a new Node at front of the list. */
   public void push(int new_data)
   {
       /* 1 & 2: Allocate the Node &
               Put in the data*/
       Node new_node = new Node(new_data);

       /* 3. Make next of new Node as head */
       new_node.next = head;

       /* 4. Move the head to point to new Node */
       head = new_node;
   }

   /* Counts the no. of occurrences of a node
   (search_for) in a linked list (head)*/
   int count(int search_for)
   {
       Node current = head;
       int count = 0;
       while (current != null)
       {
           if (current.data == search_for)
               count++;
           current = current.next;
       }
       return count;
   }

   /* Drier function to test the above methods */
   public static void Main(String []args)
   {
       LinkedList llist = new LinkedList();

       /* Use push() to construct below list
        null->2->null->3->null */
       llist.push( );
       llist.push(2);
       llist.push( );
       llist.push(3);
       llist.push( );

       /*Checking count function*/
       Console.WriteLine("Count of 'null' is "+llist.count( ));
   }
}
// This code is contributed by Arnab Kundu

Add a comment
Know the answer?
Add Answer to:
Modern language elements Write a string store class to manage string value in a member variable named        string. The variable’s value should be setable and retrievable using a property named Data....
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
  • IN JAVA PLEASE Lab 28.1 Add a class named Purchase with: an instance (String) variable for...

    IN JAVA PLEASE Lab 28.1 Add a class named Purchase with: an instance (String) variable for the customer's name an instance (double) variable for the customer's balance a member method public String toString() that returns the object's instance variable data as a single String; e.g., Cathy has a balance of $100.00 Lab 28.2 Add a main class named Store; . Then, add code that: declares and creates an ArrayList of Purchase objects named purchases (make sure to add import java.util.ArrayList...

  • HW60.1. Using Maps Implement a public final class named wordCounter. WordCounter should provide a single static...

    HW60.1. Using Maps Implement a public final class named wordCounter. WordCounter should provide a single static method countwords, which takes a string and returns a Map from strings to Integers. Each entry in the map should have a value (Integer) representing how many times that key (String) appeared in the String that was passed to countWords. For example: MapString, Integer» counts = Wordcounter.countilords ("cs 125 is awesome"); System.out.println(counts.get("CS")); // prints 1 System.out.println(counts.get( "125")); // prints 1 System.out.println(counts.get("225")); // prints null...

  • Implement the Message class using a header and implementation file named Message.h and Message.cpp respectively. In...

    Implement the Message class using a header and implementation file named Message.h and Message.cpp respectively. In addition to the two Message class files, you must write a driver. The driver must create a Message array that is capable of holding 100 messages (make sure that you don’t exceed the maximum number of Messages). It then must read all Messages from a file named messages.txt (ordered date\n sender\n recipient\n body\n), sort the Messages based on date, find a Message based on...

  • § In BlueJ, create “New Project” named LASTNAME-company Use good programming style and Javadoc documentation standards...

    § In BlueJ, create “New Project” named LASTNAME-company Use good programming style and Javadoc documentation standards Create a “New Class…” named Company to store the employee mappings of employee names (Key) to employee ids (Value) Declare and initialize class constants MIN and MAX to appropriate values Declare and instantiate a Random randomGenerator field object Declare a String field named name for the company’s name Declare a HashMap<String, String> field named employees Add a constructor with only 1 parameter named name...

  • You are to write a class called Point – this will represent a geometric point in...

    You are to write a class called Point – this will represent a geometric point in a Cartesian plane (but x and y should be ints). Point should have the following: Data:  that hold the x-value and the y-value. They should be ints and must be private. Constructors:  A default constructor that will set the values to (3, -5)  A parameterized constructor that will receive 2 ints (x then y) and set the data to what is...

  • Class StringImproved public class StringImproved extends java.lang.Object This program replaces the string class with a mutable...

    Class StringImproved public class StringImproved extends java.lang.Object This program replaces the string class with a mutable string. This class represents a character array and provide functionalities need to do basic string processing. It contains an array of characters, representing a textual string. Overview In Java, Strings are a great device for storing arrays of characters. One limitation of Strings in Java, however (there is always at least one), is that they are immutable (ie. they cannot be changed once created)....

  • DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to...

    DESCRIPTION Create a C++ program to manage phone contacts. The program will allow the user to add new phone contacts, display a list of all contacts, search for a specific contact by name, delete a specific contact. The program should provide the user with a console or command line choice menu about possible actions that they can perform. The choices should be the following: 1. Display list of all contacts. 2. Add a new contact. 3. Search for a contact...

  • Help C++ Write a string class. To avoid conflicts with other similarly named classes, we will...

    Help C++ Write a string class. To avoid conflicts with other similarly named classes, we will call our version MyString. This object is designed to make working with sequences of characters a little more convenient and less error-prone than handling raw c-strings, (although it will be implemented as a c-string behind the scenes). The MyString class will handle constructing strings, reading/printing, and accessing characters. In addition, the MyString object will have the ability to make a full deep-copy of itself...

  • Set-Up · Create a new project in your Eclipse workspace named: Lab13 · In the src...

    Set-Up · Create a new project in your Eclipse workspace named: Lab13 · In the src folder, create a package named: edu.ilstu · Import the following files from T:\it168\Labs\lab13. Note that the .txt file must be in the top level of your project, not inside your src folder. o Student.java o StudentList.java o students.txt Carefully examine the Student.java and StudentList.java files. You are going to complete the StudentList class (updating all necessary Javadoc comments), following the instruction in the code....

  • Copy the program AmusementRide.java to your computer and add your own class that extends class AmusementRide....

    Copy the program AmusementRide.java to your computer and add your own class that extends class AmusementRide. Note: AmusementRide.java contains two classes (class FerrisWheel and class RollerCoaster) that provide examples for the class you must create. Your class must include the following. Implementations for all of the abstract methods defined in abstract class AmusementRide. At least one static class variable and at least one instance variable that are not defined in abstract class AmusementRide. Override the inherited repair() method following the...

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