Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.05 KB | None | 0 0
  1. import java.awt.Point;
  2. import java.awt.Rectangle;
  3. // import java.util.Random;
  4.  
  5. /*
  6.  * A soldier needs our help!
  7.  * Find the methods below and implement them in order to support him.
  8.  */
  9.  
  10. public class Soldier {
  11.     private String firstName;
  12.     private String lastName;
  13.     private String tag;
  14.     private String rank;
  15.     private Point position;
  16.  
  17.     public Soldier(String firstName, String lastName, String tag, String rank, Point position) {
  18.         this.firstName = firstName;
  19.         this.lastName = lastName;
  20.         this.tag = tag;
  21.         this.rank = rank;
  22.         this.position = position;
  23.     }
  24.  
  25.     public String getFirstName() {
  26.         return firstName;
  27.     }
  28.  
  29.     public String getLastName() {
  30.         return lastName;
  31.     }
  32.  
  33.     public String getTag() {
  34.         return tag;
  35.     }
  36.  
  37.     public String getRank() {
  38.         return rank;
  39.     }
  40.  
  41.     public Point getPosition() {
  42.         return position;
  43.     }
  44.    
  45.     public void setFirstName(String firstName) {
  46.         this.firstName = firstName;
  47.     }
  48.  
  49.     public void setLastName(String lastName) {
  50.         this.lastName = lastName;
  51.     }
  52.  
  53.     public void setNumberTag(String tag) {
  54.         this.tag = tag;
  55.     }
  56.  
  57.     public void setRank(String rank) {
  58.         this.rank = rank;
  59.     }
  60.    
  61.     public void setPosition(Point position) {
  62.         this.position = position;
  63.     }
  64.  
  65.     /* You must return the distance of the target soldier to the point battle given as a parameter.
  66.      * the formula of distance of two points P1(X1,Y1) and P2(X2,Y2) is ((Y2 - Y1)^2 + (X2 - X1)^2) ^1/2
  67.      * Hint: Look for the Point class in the Java 8 API and observe the predefined methods.
  68.      */
  69.  
  70.     public double distanceToBattle(Point battle) {
  71.        
  72.         // WRITE YOUR CODE HERE
  73.        
  74. //      double differenceX, differenceY;
  75. //     
  76. //      differenceX = Math.pow(this.position.getX() - battle.getX(), 2);
  77. //      differenceY = Math.pow(this.position.getY() - battle.getY(), 2);
  78. //     
  79. //      double distance = Math.pow((differenceY + differenceX), 1/2);
  80.        
  81.         double distanceToBattle = Math.pow(((Math.pow(battle.getY() - this.position.y , 2)) + (Math.pow(battle.getX() - this.position.x, 2))), 1/2);
  82.        
  83.         return distanceToBattle;
  84.     }
  85.  
  86.     /* Using the enemyZone parameter and the soldiers position determine if the soldier is inside
  87.      * or in the edge of the danger zone.
  88.      * Hint: Look for the Rectangle class in the Java 8 API and observe the predefined methods.
  89.      */
  90.     public boolean inDanger(Rectangle enemyZone) {
  91.         // WRITE YOUR CODE HERE
  92.         return false; // Dummy return.
  93.     }
  94.  
  95.     /*
  96.      * The soldier has setup the radio to communicate with his base, but after a while the
  97.      * radio stopped working. He suspects that he needs to change the frequency in order to make
  98.      * it work again. Help him find the right frequency. Remember that the formula for sinusoidal
  99.      * functions is y(t) = A*sin(2*PI*f*t + theta).
  100.      * Hint #1: Look for the Math class in the Java 8 API and observe the predefined methods and fields.
  101.      * Hint #2: Solve for f on the previously mentioned sinusoidal function.
  102.      * Hint #3: sin(asin(t)) == t
  103.      */
  104.     public double getRadioFrequency(double yOfT, double A, double t, double theta) {
  105.         // WRITE YOUR CODE HERE
  106.         return 0.0; // Dummy return.
  107.     }
  108.  
  109.     /*
  110.      * The Soldier lost his tag in battle and he needs to get a new one.
  111.      * All tags are numbers of 6 digits. Generate a new tag changing the last
  112.      * 3 digits with random numbers.
  113.      * Hint: Look for the Random class in the Java 8 API and observe the predefined methods.
  114.      */
  115.    
  116.     public void newTag(){
  117.         // WRITE YOUR CODE HERE
  118.     }
  119.  
  120.     /*
  121.      * A newly formed squad is looking for a leader. Decide who has more experience
  122.      * on their hands between the target and parameter soldier, then return their last
  123.      * name so the new squad know who he is. The name parameter has the following format: S.Rodriguez.
  124.      * Where S is the initial of the first name and Rodriguez is the last name. Also, for the sake
  125.      * of this exercise we will assume that there are three ranks: Captain, Major and Sergeant.
  126.      * Captain is the highest rank, then Major and then Sergeant.
  127.      * Hint: Ranks are in lexicographical order.
  128.      */
  129.     public String teamLeader(String rank, String name) {
  130.         // WRITE YOUR CODE HERE
  131.         return null; // Dummy return.
  132.     }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement