ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 12 Weeks Ago, 3 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 23 Apr 2017 My Price 11.00

Write a Java program that uses a loop

The following questions 1 – 25 are True/False, multiple choices, or short-answer questions that can be answered in one or a few words. (2 points each)

1. What does OOP stands for in the field of Java programming? List two or more key features of OOP. 

 

2. What is a Java class? Please write a statement to create an object of a Java class named DNAseq. 

 

3. What is the default initial value of a String instance variable?

 

4. What are the commands to compile and run the Java source code file Welcome.java under command line prompt?

 

5. It is OK to have the Java source code file named differently from the public class name. (True/False) 

 

6. The following is a correct statement to create an array to hold 10 String items? (True/False) 

 

       String s[] = new String[10]; 

 

7. An import declaration can be placed inside the class declaration's body. (True/False) 

 

8. Write what will print to the screen when the following statement is executed: 

 

           System.out.println(""Java is fun"");

 

9. Please write the command to run a Java program called TestProgram with seq.fasta and 3 as the passed in command line arguments.

 

10. The following statements create an integer array values with 5 elements, and then assign each element with a value from 1 to 5. (True/false)

int values[] = new int[5];

values[] = {1, 2, 3, 4, 5};

 

11. To catch an exception, the code that might throw the exception must be enclosed in a try block. (True/False)

12.  In Java, an abstract class cannot be instantiated. (True/False)

 

13. A JTextField can be used to display a list of text. (True/False)

 

14. Every Java application is composed of at least one:

  1. local variable
  2. instance variable
  3. public class declaration
  4. imported class

 

15. Which of the following is not a syntax error?

a) System.out.println( 'Hello world!' );

b) System.out.println( "Hello

                  world!" );

c) System.out.println( "Hello world!" );

d) System.out.println( Hello world! );

 

16. Please indicate which of the following is not a valid Java identifier (variable).

  1. int
  2. $DNA 
  3. width
  4. m_x

 

 

17. What is output by the following Java code segment?

int temp;

temp = 180;

 

while ( temp != 80 )

{

  if ( temp > 90 )

  {

     System.out.print( "This porridge is too hot! " );

     // cool down

     temp = temp – ( temp > 150 ? 100 : 20 );

  } // end if

  else

  {

     if ( temp < 70 )

     {

        System.out.print(

           "This porridge is too cold! ");

      

           // warm up

           temp = temp + (temp < 50 ? 30 : 20);

     } // end if

  } // end else

} // end while

 

if ( temp == 80 )

   System.out.println( "This porridge is just right!" );

 

 

18. Programs designed for maintainability are constructed from small simple pieces or modules. Modules in Java are called:

  1. methods.
  2. classes.
  3. arguments.
  4. both methods and classes.

 

 

19. Which is a correct static method call of Math class method sqrt?

  1. sqrt( 900 );
  2. math.sqrt( 900 );
  3. Math.sqrt( 900 );
  4. Math math = new Math(); math.sqrt( 900 );

 

20. Declaring main as ________ allows the JVM to invoke main without creating an instance of the class.

  1. public
  2. void
  3. static
  4. final

 

21. Overloaded methods always have the same _________.

  1. method name.
  2. return type.
  3. number of parameters.
  4. order of the parameters.

 

22. For execution of the following three lines of Java code

String c = "Now is the time for all";

String i = c.substring( 7 );

String j = c.substring( 4, 15 );

will result in:

  1. i = "he time for all" and j = "is the time".
  2. i = "the time for all" and j = "s the time".
  3. i = "the time for all" and j = "is the time".
  4. i = "he time for all" and j = "s the time".

 

23. To find the character at a certain index position within a String, use the method:

  1. getChars, with the index as an argument.
  2. getCharAt, with the index as an argument.
  3. charAt, with the index as an argument.
  4. charAt, with the character you are searching for as an argument.

 

24. Which of the following statements is true?

  1. Ranges of characters can be represented by placing a ~ between two characters.
  2. [^Z] is the same as [A~Y].
  3. Both “A*” and “A+” will match “AAA”, but only “A*” will match an empty string.
  4. All of above.

 

25. When an applet container loads an applet, the container calls three of the applet’s methods. In sequence, these three methods are:

  1. start, init, stop.
  2. start, init, paint.
  3. init, start, stop.
  4. init, start, paint.

 

 

The following questions (26-32) are short answer questions or questions with short Java code snips. No class and method declarations are required, but you may want to try in a Java program to make sure that the answers are correct.  

26. Is the following conditional statement correct? If not, please make corrections.

(4 points)

 

 

if (Acc_num = “NM_2030”)

 

   System.out.println (“This is the correct GenBank”

                        + “ accession numbern”);

 

27. Please explain how to overload a Java method (4 points)

 

28. The standard Java application has a main method with a header declaration of:

public static void main(String args[])

 

What does staticvoid mean to the method, and what type is the variable args, and where does its values come from? (4 points)

 

 

29 . Below Java statement will create an integer array that contains 5 elements. Write a few statements that will successfully swap the contents of the array at index 3 and index 4. (4 points)

int[] intArray = {2,4,6,8,10};

 

30. A piece of DNA sequence is:

String DNA = "ACGGGAGGACGGGAAAATTTACTAGC";

 

Please write one or two statements to generate a reverse complement strand of the DNA sequence and assign it to a String variable rev_com. You should use classes in the biojava package, no import declarations are needed. (4 points)

 

 

31. Write a method that could be called to concatenate any number of DNA sequences passed in as arguments, and return the concatenated DNA sequence. Two examples of calling the method are shown below: (6 points)

 

String DNA1 = dna.concat_DNAs("ATGC", "CGTA");

String DNA2 = dna.concat_DNAs("AAAA", "TTTT", "GGGG", "CCCC");

 

32. Below is the title line of a Blast sequence search hit, please use a method of the String class to extract the GenBank accession number and assign it to a variable called Acc_num. (4 points)

 

 

String title = “>ref|NM_001081660.1| Rattus norvegicus crystallin, gamma B (mapped) (Crygb), mRNA”;

 

 

The following questions (33-34) are short Java programs. They should be correct in syntax, and can be compiled and run under command prompt. Please copy the content of the Java source code file in the space below.

 

 

33. Write a Java program that uses a loop to prompt a user to input a clone ID and a DNA sequence. Include an if statement to exit the loop if the user entered the word “exit”. After the user entered an ID and the sequence, save them in a file in a FASTA format (header line starts with a > and followed by the clone id, and the sequences are in the subsequent lines). When the user entered “exit”, print out all the entered sequences to the screen in a FASTA format. (10 points)

 

 

34. Write a program to open a text file (java.txt), and count how many words are in the file. A word is considered character(s) flanked by spaces, and it is not necessary to strip off the punctuation characters. The file name should be given as an argument to the program. Print a message to the screen to indicate how many words the file contains. (10 points)

(Optional) Also, print out a sorted list of unique words followed by the number of occurrences of each word in the text. (5 bonus points)

 

 

 

 

 

 

 

 

 

The following questions 1 – 25 are True/False, multiple choices, or short-answerquestions that can be answered in one or a few words. (2 points each)1.What does OOP stands for in the field of Java programming? List two or more keyfeatures of OOP.2.What is a Java class? Please write a statement to create an object of a Java classnamed DNAseq.3.What is the default initial value of aStringinstance variable?4.What are the commands to compile and run the Java source code fileWelcome.java under command line prompt?5.It is OK to have the Java source code file named differently from the public classname. (True/False)6.The following is a correct statement to create an array to hold 10 String items?(True/False)String s[] = new String[10];7.Animportdeclaration can be placed inside the class declaration's body.(True/False)

 

Attachments:

Answers

(11)
Status NEW Posted 23 Apr 2017 04:04 PM My Price 11.00

-----------

Not Rated(0)