Guest User

Untitled

a guest
Jan 23rd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. /* Exercise 1: Write a function
  2. public static boolean isValidDNA(String sequence)
  3. that returns true if the input seqience contains only As, Cs, Gs, and Ts, and false otherwise.
  4. Give example test cases with the expected output.
  5. */
  6. public static boolean isValidDNA(String sequence){
  7. for (int i = 0; i < sequence.length; i++{
  8. if (sequence.charAt(i) != (String "A" || String "T" || String "C" || String "G"){
  9. return false;
  10. }
  11. }
  12. return true;
  13. }
  14. /* Exercise 2: Write a function
  15. public static String complementDNA(String sequence)
  16. that returns the complement of a sequence of DNA, where A and T are complements and C and G are complements.
  17. */
  18. public static String complementDNA(String sequence){
  19. for (int i = 0; i < sequence.length; i++){
  20. if (sequence.i = "T")
  21. complement = complement + "A";
  22. if (sequence.i = "A")
  23. complement = complement + "T";
  24. if (sequence.i = "C")
  25. complement = complement + "G";
  26. if (sequence.i = "G")
  27. complement = complement + "C";
  28. }
  29. return complement;
  30. }
  31. /* Exercise 3: given the following class:
  32. public class Point{
  33. public int x;
  34. public int y;
  35.  
  36. public Point(int x0, int y0) {
  37. x = x0;
  38. y = y0;
  39. }
  40. }
  41. Write a new class Circle for representing circles. You class should have a constructor
  42. public Circle(Point c, double r)
  43. that takes the center of the circle as a Point and the radius as a double.
  44. It should also have instance methods:
  45. public double getArea()
  46. public double getCircumference()
  47. public boolean inCircle(Point p)
  48. Where getArea and getcircumference return the area and the circumference of the circle respectively.
  49. The method inCircle should return true if the point p is in the circle and false otherwise.
  50. */
  51. public class Point{
  52. public int x;
  53. public int y;
  54.  
  55. public Point(int x0, int y0) {
  56. x = x0;
  57. y = y0;
  58. }
  59. }
  60.  
  61. public class Circle{
  62. public Point c;
  63. public double
  64.  
  65. public Circle(Point c, double r){
  66. c = c0;
  67. r = r0;
  68. }
  69. public double getArea(){
  70. double Area = Math.PI*r*r;
  71. return Area;
  72. }
  73. public double getCircumference()
  74. double Circumference = 2*math.PI*r;
  75. return Circumference;
  76. }
  77. public boolean inCircle(Point p)
  78. if (((p.x-c.x)*(p.x-c.x))+((p.y-c.y)*(p.y=c.y)) <= r*r)
  79. return true;
  80. return false;
  81. }
  82. }
Add Comment
Please, Sign In to add comment