Download exam1

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
2/11/2015
CS 110G Exam 1
Page 1
Computer Science I G
Spring 2015, Wednesday, 2/11/15
100 points
Name _____________________________
1. Fill in the remaining 4 boxes that identify the primary components of a computer system. Use general terms
for the components.
[12 pts]
Data flow
Primary Memory
The smallest addressable unit in primary memory is a ___________ and each is composed of _____ bits,
and bits can hold the values _______ and ________ .
2. True/False on Java compiling and debugging.
[10 pts]
______ The class name of the program and the source file name with a .java extension must be the same.
______ The Java compiler creates the .class bytecodes from the .java file.
______ The Java Virtual Machine executes the program only from the .java source file.
______ Java software is compile once, run anywhere.
______ A Java application must have a main method in it.
______ A missing semicolon is an example of a runtime error.
______ Typing “hello” interactively when executing a nextInt() method is an example of a syntax error.
______ Resolving all syntax errors guarantees a correctly working program.
______ A statement expressing a calculation at the beginning of the program is executed every time a
variable in the calculation changes just like in a spreadsheet.
______ The compiler uses comments to help generate correct code.
2/11/2015
CS 110G Exam 1
Page 2
3. True/false on variables and types.
[10 pts]
_____A variable can tracks all values it takes on during the execution of the program.
_____ The variable total is the same as the variable Total; capitalization is immaterial.
_____ A variable must be declared with its type before it can be used.
_____ “95”, 95, and 95.0 are understood by Java to be the same value and can be used interchangeably.
_____ A variable’s type remains fixed throughout the program, but its value can change.
_____ A double value can be assigned to an int variable type without loss of information.
_____ When a double is typecast as an int, it automatically rounds up or down.
_____ A char is encoded inside Java and computer as a number.
_____ The String type is treated as a primitive just like int or double.
_____ Every variable’s value can be automatically converted to a String for concatenation or printing
purposes in Java.
4. Evaluate the following expressions. Be sure to use the correct syntactic notation for each of the results. E.g.,
appropriate inclusion of decimal points, single quotes or double quotes to represent the type of the result.
The correct value is worth a point and the expressing the answer in the correct type notation is also worth
one point.
[20 pts]
Assume the following variables and initial values:
int a = 12;
int b = 8;
double c = 6.0;
double d = 1.5;
String s = “The answer is:”;
_________ = a - b / 2
_________ = s.length( )
_________ = c / d – 1.0
_________ = s.charAt(b)
_________ = a – b – c
_________ = s + a + b
_________ = a % b * 3
_________ = a < c * d
_________ = 6 / c + 0.5
_________ = b<=a && d>=2.0
5. Show the output for the following code segments.
[5 pts]
System.out.print(“abcd“);
System.out.println(“efgh“);
System.out.print (“ijkl\nmop\n“);
System.out.println(“rstu“ +
“wxyz“);
CS 110G Exam 1
2/11/2015
Page 3
6. Fill in the blanks to complete a Java program to input two double type numbers and prints which one is the
largest of the two values input. Comments contain hints (nice, huh?).
[13 pts]
import java.util.Scanner;
public class largest
{
public static void __________ (String [] args) //start, main, Main, Start
{
double __________; // input variables
________ __________;
Scanner keyboard = new __________ (System.in);
System.out.println(“Enter two numbers: “);
first
= keyboard.________________ ();
// constructor is same as class
//important Scanner methods next
second = keyboard.________________ ();
______ (_________ > __________) // test, if, check, throw, catch
{// choices above here drive answers in printlns
System.out.println (“The ____________ number is the largest”);
} _______ {//then otherwise default else return
System.out.println (“The ____________ number is the largest”);
}
}
}
7. Explain or give the UNIX or vi commands/keystrokes to do the following tasks. A single command should
suffice.
[12 pts]
a. Display all filenames that are in your current working directory. _______________
b. Display the contents of dnaGen.java file found _______________________________
c. Delete the temp file in your current directory ____________________
d. Create a subdirectory in your current directory called projects. ___________________________
e. Move all java type files in your current directory to this subdirectory projects ______________________
(You can use a * for a wildcard for general root file names in this case.)
f.
Change your current working directory to its parent directory (up one level) ________________________
g. Compile the source file exam.java _______________________________
h. Run the Java program exam __________________________________________
i.
True/false on Unix
_______The ctrl-D key combination designates end of input in Unix.
_______The ctrl-C key combination stops and cancels a program in Unix.
_______All directories, disk drives, file storage structures are unified into one directory tree.
_______Text files’ end-of-line coding is consistent between Windows/DOS and Unix.
2/11/2015
CS 110G Exam 1
Page 4
8. Write a complete Java program (use #7 as a guide for structure) to input a DNA sequence. Search if the
sequence has a start codon “ATG” using the indexOf() method. If so, reset the sequence with substring() so
that you can output the sequence starting with ATG discarding the letters preceding ATG. Then search this
new string for “TAA” as a stop codon. Print a message whether you found it and if its position is divisible
by 3. That’s all. (If it is divisible by 3 it’s really a stop codon.) Be sure the output is well labeled so a casual
user understands the results.
Example:
 Input: CGATGAGGTAGDTAGTAAATAAA
 Output:
Start found, sequence is ATGAGGTAGDTAGTAAATAAA
Stop found at position 11
It is not aligned.
[18 pts]