Question: need somebody that can help me with this problem !!! sorry since i don't know how to attach the file to chegg so here is
need somebody that can help me with this problem !!!
sorry since i don't know how to attach the file to chegg so here is the link for the supply file:
http://webshares.northseattle.edu/cscweb/CSC142/examples/Objects/CSC142Point.java
A GPS (Global Positioning System) is a navigation tool that knows its location and heading. This information helps a person navigate. In this assignment you are going to create an object that behaves like a simple GPS. FIX - correction added 4/20
Objectives
Programmer defined objects
Composition of objects
Specification
You will be defining two classes, creating new types. The first class is CompassHeading. One of the objectives of this assignment is composition, defining classes that have references as instance variables (similar to our LineSegment example). The second class, GPS, will be composed of a CSC142Point and a CompassHeading. NOTE - you are not writing a complete programmer. For this assignment, you are the supplier programmer, defining classes for another client to use.
class CompassHeading: A compass heading is a direction within the range [ 0 to 360) ( means degrees). 0 is North, 90 is East, 180 is South, and 270 is West. You need to implement a class to encapsulate this data and associated operations. Here is the specification for this class:
| class CompassHeading |
How to convert a compass heading to a compass bearing (or a quadrant bearing) A compass bearing, also known as a quadrant bearing, consists of 3 items:
the direction you face (North or South)
an angle to turn between 0 and 90 (inclusive)
and the direction you turn (East or West)
For example, starting with a compass heading of 110, here is how to determine the equivalent bearing: face South then turn 70 East (180 - 70 = 110). Therefore the bearing is South 70 degrees East, or S70E. The method getBearing() needs to do this conversion and return the result as one String. The String must follow a specific format:
Use only the first initial for the directions N, S, E, W
The initial should be capitalized
For the degree symbol, use ASCII code 176.
Do not include any spaces
FIX - If the heading is due North (0) or due South (180) the angle to turn is 0. It does not matter which way you turn.
FIX - If the heading is due East (90) or due West (270), you can start either N or S.
In the example above, the bearing for a heading for 110 is the String "S70E".
class GPS: A GPS object needs to know its location and its heading. To simplify things, the location is represented by a CSC142Point. You need to implement a class to encapsulate this data and associated operations. Here is the specification for our GPS class:
| class GPS |
How to move from one point to another in a given direction The method move() requires some complex math that I want to explain here.
| Given the old location of (x,y) we need to calculate a new location (x + delta x, y + delta y). Therefore, we need to calculate the change in x (delta x) and the change in y (delta y). Notice that our heading measures the angle from the vertical (0 degrees is along the y-axiz). Using right-triangle trigonometry delta x = distance to move * sin(heading angle) delta y = distance to move * cos(heading angle) You may have learned in a math class that delta x = distance * cos(angle). But that's when the angle is measured from the horizontal (the x-axis). We are measuring the angle from the vertical. |
As you look in the Math class in the Java API, you'll find a sin() and cos() method. Notice though that the units for the angle parameter is radians, not degrees. Yet the data in our object is degrees not radians. We understand how to convert from angles to radians from homework 1. Look further in the Math class and you'll find a convenient method to convert from degrees to radians.
If anyone has questions about these calculations, please don't hesitate to ask me.
Suggestions
As always, you will have success if you code and test in pieces. Start with the CompassHeading class first, then go on to the GPS class. You can test either by using the BlueJ interface of instantiating objects and calling methods on them, or writing yourself a small test method. You should definitely hand caclulate some turn() and move() operations in order to compare expected results with the program's actual results. Remember, just because something runs doesn't mean it's working properly.
Documentation, Style
Make sure you have documented your classes well. From this assignment on, we will be using JavaDoc style comments for class and method descriptions. Please see the documentation and style guidlines on the class website.
Use appropriate style that we've discussed in class. This includes (but not limited to) named constants, indenting, etc.
Grading
/7 Heading class /8 GPS class /5 documentation & style Good Luck!
delta x F -2 New location delta y heading Old location delta x F -2 New location delta y heading Old locationStep by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
