Question

I'm trying to construct this program in C#, I found some similiar problems in Java but...

I'm trying to construct this program in C#, I found some similiar problems in Java but as a beginner, its not very easy to follow along with the Java code.

Create a Console application named RelativesApp to help you remember your relatives’ birthdays.

·Create a Relative class that includes auto-implemented properties for the relative's name, their relationship to you, and two integers to represent their birthday –month, day.

·Declare an array of at least 12 relative objects.

·Fill the array with relatives of your choice.

·Display the contents of the array using a for loop

·Using Sort(), sort the array by month and day

·Display the contents again.

·Using BinarySearch(), search to see if anyone has a birthday on a particular day of the month and display an appropriate message such as: “Ruby’s birthday falls on 11/17!”or“Nobody’s birthday falls on 11/20”

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

Below is the code as per the requirements. It is well explained inside the code using comments:

using System;

namespace RelativesApp
{
    // Relative class
    class Relative : IComparable
    {
        public string Name { get; set; }            // relative name
        public string Relationship { get; set; }    // relationship
        public int BirthdayMonth { get; set; }      // birthday month
        public int BirthdayDate { get; set; }       // birthday date

        // constructor
        public Relative(string n, string r, int mm, int dd)
        {
            Name = n;
            Relationship = r;
            BirthdayMonth = mm;
            BirthdayDate = dd;
        }

        // compare to method for sorting
        public int CompareTo(object obj)
        {
            Relative otherRelative = (Relative)obj;

            int result = BirthdayMonth.CompareTo(otherRelative.BirthdayMonth);

            // if months are equal
            if (result == 0)
                result = BirthdayDate.CompareTo(otherRelative.BirthdayDate);

            return result;
        }
    }

    // main class
    class Program
    {
        // main method
        static void Main(string[] args)
        {
            // declare array of 12 relative objects
            Relative[] relatives = new Relative[12];

            // fill the content
            relatives[0] = new Relative("Percy Shoemaker", "uncle", 5, 12);
            relatives[1] = new Relative("Williemae Milici", "father", 2, 10);
            relatives[2] = new Relative("Nicky Lemmons", "son", 1, 8);
            relatives[3] = new Relative("Darius Dangerfield", "daughter", 7, 2);
            relatives[4] = new Relative("Alba Maricle", "mother", 10, 9);
            relatives[5] = new Relative("Ralph Connally", "grand mother", 7, 23);
            relatives[6] = new Relative("Chester Crownover", "grand son", 6, 11);
            relatives[7] = new Relative("Elfrieda Oconnor", "grand daughter", 3, 16);
            relatives[8] = new Relative("Vada Scarlett", "daughter", 2, 25);
            relatives[9] = new Relative("Collette Symons ", "niece", 8, 28);
            relatives[10] = new Relative("Jonah Askew", "nephew", 12, 19);
            relatives[11] = new Relative("Norma Mccrary", "mother", 8, 17);

            // display the array contents
            display(relatives);

            // sort the array
            Array.Sort(relatives);

            // display the array contents again
            Console.WriteLine("Sorted:");
            display(relatives);

            // search for birthday 7/23
            int index = Array.BinarySearch(relatives, new Relative("", "", 7, 23));

            // display the name, if birthday found
            if (index >= 0)
                Console.WriteLine("\n" + relatives[index].Name + "'s birthday falls on " + relatives[index].BirthdayMonth + "/" + relatives[index].BirthdayDate + "\n");
            else
                Console.WriteLine("\nNobody's birthday falls on " + relatives[index].BirthdayMonth + "/" + relatives[index].BirthdayDate + "\n");
        }

        // displays the content of array
        private static void display(Relative[] relatives)
        {
            Console.WriteLine();
            for (int i = 0; i < 12; i++)
            {
                Console.WriteLine("Name: " + relatives[i].Name + ", Relationship: " + relatives[i].Relationship + ", Birthday: " + relatives[i].BirthdayMonth + "/" + relatives[i].BirthdayDate);
            }
            Console.WriteLine();
        }
    }
}

Below is the sample output:

Name : Nicky Lemmons. Relationship: son, Birthday: 1/8 Name : Darius Dangerfield, Relationship: daughter, Birthday: 7/2 Name:

This completes the requirement. Let me know if you have any queries.

Thanks!

Add a comment
Know the answer?
Add Answer to:
I'm trying to construct this program in C#, I found some similiar problems in Java but...
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
  • Write a Java program with a single-dimension array that holds 11 integer numbers and sort the...

    Write a Java program with a single-dimension array that holds 11 integer numbers and sort the array using a bubble sort. Next, identify the median value of the 11 integers. Here are the steps your program must accomplish. algorithm (either flowchart or pseudocode) that you will use to write the program Step 1. Create an Place the algorithm in a Word document. 6. Ste the Step 2. Code the program in Eclipse and ensure the following steps are accomplished. 1....

  • JAVA Using the data provided in the attachment, create a program that will display a child's...

    JAVA Using the data provided in the attachment, create a program that will display a child's predicted adult height. This program will need to create an array of objects to search. This program needs to validate the input for valid range and input values. If invalid data is given, the program needs to indicate that data is invalid and suggest appropriate values/ranges. However, you do not need to validate alphabetic data given for numeric input. 1. The program will need...

  • 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...

  • Copy the following java codes and compile //// HighArray.java //// HighArrayApp.java Study carefully the design and...

    Copy the following java codes and compile //// HighArray.java //// HighArrayApp.java Study carefully the design and implementation HighArray class and note the attributes and its methods.    Create findAll method which uses linear search algorithm to return all number of occurrences of specified element. /** * find an element from array and returns all number of occurrences of the specified element, returns 0 if the element does not exit. * * @param foundElement   Element to be found */ int findAll(int...

  • Write a Java program in Eclipse that reads from a file, does some clean up, and...

    Write a Java program in Eclipse that reads from a file, does some clean up, and then writes the “cleaned” data to an output file. Create a class called FoodItem. This class should have the following: A field for the item’s description. A field for the item’s price. A field for the item’s expiration date. A constructor to initialize the item’s fields to specified values. Getters (Accessors) for each field. This class should implement the Comparable interface so that food...

  • WRITE THE PROGRAM IN JAVA. gram 3: Olympians I C 1 Goals To write your own...

    WRITE THE PROGRAM IN JAVA. gram 3: Olympians I C 1 Goals To write your own class in a program To write a constructor with parameters, an method and a toString) method. To use ArrayList To use a for-each loo . p *l . To use text file for output 2 The Context This is a single-class project, the first for which I have not given you code to start from. It is not realistic, or useful, but it gives...

  • JAVA Hello I am trying to add a menu to my Java code if someone can...

    JAVA Hello I am trying to add a menu to my Java code if someone can help me I would really appreacite it thank you. I found a java menu code but I dont know how to incorporate it to my code this is the java menu code that i found. import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.ButtonGroup; import javax.swing.JCheckBoxMenuItem; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JRadioButtonMenuItem; public class MenuExp extends JFrame { public MenuExp() { setTitle("Menu Example");...

  • Lab Objectives Be able to write methods Be able to call methods Be able to declare...

    Lab Objectives Be able to write methods Be able to call methods Be able to declare arrays Be able to fill an array using a loop Be able to access and process data in an array Introduction Methods are commonly used to break a problem down into small manageable pieces. A large task can be broken down into smaller tasks (methods) that contain the details of how to complete that small task. The larger problem is then solved by implementing...

  • I need help making this work correctly. I'm trying to do an array but it is...

    I need help making this work correctly. I'm trying to do an array but it is drawing from a safeInput class that I am supposed to use from a previous lab. The safeInput class is located at the bottom of this question I'm stuck and it is not printing the output correctly. The three parts I think I am having most trouble with are in Bold below. Thanks in advance. Here are the parameters: Create a netbeans project called ArrayStuff...

  • C++ Project Modify the Date Class: Standards Your program must start with comments giving your name...

    C++ Project Modify the Date Class: Standards Your program must start with comments giving your name and the name of the assignment. Your program must use good variable names. All input must have a good prompt so that the user knows what to enter. All output must clearly describe what is output. Using the date class, make the following modifications: Make the thanksgiving function you wrote for project 1 into a method of the Date class. It receive the current...

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