Question

In: Computer Science

Design and implement a class called circle_location to keep track of the position of a single...

Design and implement a class called circle_location to keep track of the position of a single point that travels around a circle. An object of this class records the position of the point as an angle, measured in a clockwise direction from the top of the circle. Include these public member functions:
• A default constructor to place the point at the top of the circle.
• Another constructor to place the point at a specified position.
• A function to move the point a specified number of degrees around the circle. Use a positive argument to move clockwise, and a negative argument to move counterclockwise.
• A function to return the current position of the point, in degrees, measured clockwise from the top of the circle. Your solution should include a separate header file, implementation file,
and an example of a main program using the new class.

Solutions

Expert Solution

This program is created in C# language on Microsoft .NET platform.

Created in Visual Studio provided by Microsoft.

Detailed classes with description in comments marked as double slash "//"

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

  1. Class Circle_Location

public class circle_location

    {

        // location variable

        public static decimal CurrentLocationDegrees { get; set; }

        // default constructor

        public circle_location()

        {

            // initially set location to zero

            CurrentLocationDegrees = 0;

        }

        // parameterised constructor

        public circle_location(decimal Degrees)

        {

            // set location to value from input parameter

            CurrentLocationDegrees = Degrees;

        }

        public void MovePointer(decimal DegreesToMoveBy)

        {

            CurrentLocationDegrees = CurrentLocationDegrees + DegreesToMoveBy;

        }

        public decimal GetCurrentLocation()

        {

            return CurrentLocationDegrees;

        }

    }

2. Class Program: Actual use of above mentioned class is demonstrated here

class Program
{
static void Main(string[] args)
{
decimal moveByDegrees = 0;
// initialize
circle_location objCircleLocation = new circle_location();
Console.WriteLine("Initialize. Set Point to zero.");
// get current location
Console.WriteLine(string.Format("Current location: {0} Degrees\n" , objCircleLocation.GetCurrentLocation()));

// move point clockwise
moveByDegrees = Convert.ToDecimal(10.5);
Console.WriteLine("Move Point Clockwise by " + moveByDegrees);
objCircleLocation.MovePointer(moveByDegrees);

// get current location
Console.WriteLine(string.Format("Current location: {0} Degrees\n", objCircleLocation.GetCurrentLocation()));

// move point ani-clockwise
moveByDegrees = Convert.ToDecimal(-4);
Console.WriteLine("Move Point Anti Clockwise by " + moveByDegrees);
objCircleLocation.MovePointer(moveByDegrees);

// get current location
Console.WriteLine(string.Format("Current location: {0} Degrees\n", objCircleLocation.GetCurrentLocation()));
}
}


Related Solutions

Write a class called Animal that contains a static variable called count to keep track of...
Write a class called Animal that contains a static variable called count to keep track of the number of animals created. Your class needs a getter and setter to manage this resource. Create another variable called myCount that is assigned to each animal for each animal to keep track of its own given number. Write a getter and setter to manage the static variable count so that it can be accessed as a class resource
Using c++ Design a system to keep track of employee data. The system should keep track...
Using c++ Design a system to keep track of employee data. The system should keep track of an employee’s name, ID number and hourly pay rate in a class called Employee. You may also store any additional data you may need, (hint: you need something extra). This data is stored in a file (user selectable) with the id number, hourly pay rate, and the employee’s full name (example): 17 5.25 Daniel Katz 18 6.75 John F. Jones Start your main...
/////////////////JAVA PLEASE///////////////////////////////// Create a class called GVdate to keep track of a calendar date including month,...
/////////////////JAVA PLEASE///////////////////////////////// Create a class called GVdate to keep track of a calendar date including month, day and year.  You can do simple things like checking if it is your birthday, advancing to the next day, checking if a given date is valid and checking if it is a leap year. Class Fields/Instance Variables Provide appropriate names and data types for each of the private instance variables: the month, day and year (int) two final integers that represent YOUR birthday (month...
1) Design an implement a program that created and exception class called StringTooLongException, designed to be...
1) Design an implement a program that created and exception class called StringTooLongException, designed to be thrown when a string is discovered that has too many characters in it. Create a driver that reads in strings from the user until the user enters DONE. If a string that has more then 5 characters is entered, throw the exception. Allow the thrown exception to terminate the program 2) Create a class called TestScore that has a constructor that accepts an array...
JAVA - Design and implement a class called Flight that represents an airline flight. It should...
JAVA - Design and implement a class called Flight that represents an airline flight. It should contain instance data that represent the airline name, the flight number, and the flight’s origin and destination cities. Define the Flight constructor to accept and initialize all instance data. Include getter and setter methods for all instance data. Include a toString method that returns a one-line description of the flight. Create a driver class called FlightTest, whose main method instantiates and updates several Flight...
Write a class to keep track of a balance in a bank account with a varying...
Write a class to keep track of a balance in a bank account with a varying annual interest rate. The constructor will set both the balance and the interest rate to some initial values (with defaults of zero). The class should have member functions to change or retrieve the current balance or interest rate. There should also be functions to make a deposit (add to the balance) or withdrawal (subtract from the balance). You should not allow more money to...
Write a class to keep track of a balance in a bank account with a varying...
Write a class to keep track of a balance in a bank account with a varying annual interest rate. The constructor will set both the balance and the interest rate to some initial values (with defaults of zero). The class should have member functions to change or retrieve the current balance or interest rate. There should also be functions to make a deposit (add to the balance) or withdrawal (subtract from the balance). You should not allow more money to...
Question : Design and implement two classes called InfixToPostfix and PostFixCalculator. The InfixToPrefix class converts an...
Question : Design and implement two classes called InfixToPostfix and PostFixCalculator. The InfixToPrefix class converts an infix expression to a postfix expression. The PostFixCalculator class evaluates a postfix expression. This means that the expressions will have already been converted into correct postfix form. Write a main method that prompts the user to enter an expression in the infix form, converts it into postfix, displays the postfix expression as well as it's evaluation. For simplicity, use only these operators, + ,...
Write in drjava Problem Design and implement these 4 files: A parent class called Plant with...
Write in drjava Problem Design and implement these 4 files: A parent class called Plant with name (eg Rose, Douglas Fir) and lifespan (could be in days, weeks, months or years) attributes Tree inherits from Plant and adds a height attribute Flower inherits from Plant and adds a color attribute A driver file to test the 3 classes above. The classes described in #1, 2 and 3 above should have the usual constructors (default and parameterized), get (accessor) and set...
Design a database through the EER diagram to keep track of the teams and games of...
Design a database through the EER diagram to keep track of the teams and games of a sport league. Assume that the following requirements are collected (the English description of cardinal ration and partial/complete participate is NOT required, but you still need to provide the total/partial and cardino ration in your EER diagram) : The database has a collection of TEAM. Each Team has a unique name, players, and owner. The database also keeps the records of PLAYERS. Each player...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT