Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.95 KB | None | 0 0
  1. /*
  2.  * INFO0062 - Object-oriented programming
  3.  * Special session (16/05/2019)
  4.  *
  5.  * Example of main() to test the LineSegment class described by the first question from the
  6.  * written examination of May 2018. This question didn't asked students to write a main(), so the
  7.  * main() here is just a way of testing the code. You should only write a main() method if and
  8.  * only if the question explicitely requests it.
  9.  *
  10.  * @author: J.-F. Grailet
  11.  */
  12.  
  13. public class Main
  14. {
  15.     public static void main(String args[])
  16.     {
  17.         LineSegment l1 = new LineSegment(1, 1, 1, 2, 2, 2);
  18.         LineSegment l2 = new LineSegment(1, 2, 3, 4, 5, 6);
  19.         LineSegment l3 = (LineSegment) l1.clone();
  20.        
  21.         if(l1.equals(l2))
  22.             System.out.println(l1 + " and " + l2 + " are equal.");
  23.         else
  24.             System.out.println(l1 + " and " + l2 + " aren't equal.");
  25.        
  26.         if(l1.equals(l3))
  27.             System.out.println(l1 + " and " + l3 + " are equal.");
  28.         else
  29.             System.out.println(l1 + " and " + l3 + " aren't equal.");
  30.        
  31.         l2.translate(3, 3, 3);
  32.         l3.translate(1, 2, 3);
  33.        
  34.         System.out.println(l2);
  35.        
  36.         if(l1.equals(l3))
  37.             System.out.println(l1 + " and " + l3 + " are equal.");
  38.         else
  39.             System.out.println(l1 + " and " + l3 + " aren't equal.");
  40.        
  41.         try
  42.         {
  43.             LineSegment[] split = l1.split();
  44.             System.out.println("Split of " + l1 + ": " + split[0] + " and " + split[1]);
  45.         }
  46.         catch(Exception e)
  47.         {
  48.             System.err.println("Error: " + e.getMessage());
  49.         }
  50.        
  51.         try
  52.         {
  53.             LineSegment[] split = l2.split();
  54.             System.out.println("Split of " + l2 + ": " + split[0] + " and " + split[1]);
  55.         }
  56.         catch(Exception e)
  57.         {
  58.             System.err.println("Error: " + e.getMessage());
  59.         }
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement