Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Exercise 1: Write a function
- public static boolean isValidDNA(String sequence)
- that returns true if the input seqience contains only As, Cs, Gs, and Ts, and false otherwise.
- Give example test cases with the expected output.
- */
- public static boolean isValidDNA(String sequence){
- for (int i = 0; i < sequence.length; i++{
- if (sequence.charAt(i) != (String "A" || String "T" || String "C" || String "G"){
- return false;
- }
- }
- return true;
- }
- /* Exercise 2: Write a function
- public static String complementDNA(String sequence)
- that returns the complement of a sequence of DNA, where A and T are complements and C and G are complements.
- */
- public static String complementDNA(String sequence){
- for (int i = 0; i < sequence.length; i++){
- if (sequence.i = "T")
- complement = complement + "A";
- if (sequence.i = "A")
- complement = complement + "T";
- if (sequence.i = "C")
- complement = complement + "G";
- if (sequence.i = "G")
- complement = complement + "C";
- }
- return complement;
- }
- /* Exercise 3: given the following class:
- public class Point{
- public int x;
- public int y;
- public Point(int x0, int y0) {
- x = x0;
- y = y0;
- }
- }
- Write a new class Circle for representing circles. You class should have a constructor
- public Circle(Point c, double r)
- that takes the center of the circle as a Point and the radius as a double.
- It should also have instance methods:
- public double getArea()
- public double getCircumference()
- public boolean inCircle(Point p)
- Where getArea and getcircumference return the area and the circumference of the circle respectively.
- The method inCircle should return true if the point p is in the circle and false otherwise.
- */
- public class Point{
- public int x;
- public int y;
- public Point(int x0, int y0) {
- x = x0;
- y = y0;
- }
- }
- public class Circle{
- public Point c;
- public double
- public Circle(Point c, double r){
- c = c0;
- r = r0;
- }
- public double getArea(){
- double Area = Math.PI*r*r;
- return Area;
- }
- public double getCircumference()
- double Circumference = 2*math.PI*r;
- return Circumference;
- }
- public boolean inCircle(Point p)
- if (((p.x-c.x)*(p.x-c.x))+((p.y-c.y)*(p.y=c.y)) <= r*r)
- return true;
- return false;
- }
- }
Add Comment
Please, Sign In to add comment