Shared Flashcard Set

Details

Algorithms and Problem Solving Final
Questions from past tests for the final
50
Computer Science
Undergraduate 1
12/06/2011

Additional Computer Science Flashcards

 


 

Cards

Term
A typical Computer has 5 basic parts. What are they and briefly describe each of them.
Definition

CPU- is the brain of the a computer

Ram- What the computer can work with at a given point in time

Input source- information inputted by the user

Output source- information that is outputted back to the user

Communication devices- connects the personal computer to an Internet.

Term

 


 

A java program goes through an Edit, Compile, and Run cycle. Describe this cycle.

 

Definition

Edit- is the programmer editing the program as they write it


compile - it converts the program so the computer can read/run it


run - is when the computer does what it has been told to do

Term

 

Describe the problem solving steps

 

Definition

 

  1. whats your problem/what you're trying to do
  2. what you need to know to solve the problem
  3. write the steps to solving the problem and include any formulas or utilities you will need to use
  4. solve it

 

Term
what is a java reserved words or keywords? Give some examples.
Definition

 

words that do something in java programming. Examples: new,import, if, else

 

Term
Valid Java identifiers (Not java reserved words).
Definition
Int, Main, Maximum,  Double, JOptionPane, Math.
Term
declare an int and store the value 55 in it.
Definition
int x=55;
Term
Declare a String value and store,"GO WSU WARRIORS!" in it.
Definition

String str; 

str = new string("GO WSU WARRIORS!");

Term
import statement to use SimpleDateFormat class.
Definition

import java.util;

import java.text.DateFormat;

Term
show the use of JOptionPane to output "Java programming can be very interesting."
Definition
JOPtionPane.showMessageDialog(null,"Java programming can be very interesting.");
Term
Show all the necessary declarations and write the expression needed to calculate (10)

square root of           X + 4Y^3
Definition

import java.lang;

double x = 1;

double y = 1;

double answer;

 

answer = Math.sqrt(x+(4*(yMath.pow(3))));

Term
cosine of an angle that is 75 degrees
Definition
x = math.cos(75);
Term
Describe the different parts of a Java Class Definition.
Definition
  1. Import Statements
  2. Class comment
  3. Class name
  4. Data members
  5. Methods
Term
Write a method that takes in an integer value and returns-

“Millions” if the value is in the millions
“Billions” if the values in the billions
“Cheap” if the values is below a million
“Out of Control” otherwise
Definition

int x = Integer.parseInteger(JOptionPane.input(“enter a number”));

If (x>= 1000000 && <=999999999)
system.out.println(“Millions”);
If (x>= 1000000000 && <=999999999999)
system.out.println(“Billons”);
If (x < 1000000000
system.out.println(“Cheap”);
If (x> 999999999999 );
system.out.println(“Out of control ”);
Term
describe the general structure of a while loop.
Definition

code that is repeated until conditions/statements become true. 

 

while(...){

 

}

Term
Describe the general structure of a do-while loop.
Definition

same as while except while is at the end and starts out with do. 

 

do(code that repeats) {

}

while(...statement);

Term
describe the general structure of for loop.
Definition

for(i=0;i<100;i++){

}

for(;;);

 

Term
what is the difference between a counting loop and a sentinel based loop?
Definition

keeps track of the number or repetition and can also offer a way for code to stop once it reaches a certain number. 

Sentinel loop repeats until a condition is met, which may never occur. 

Term
declare an array of double size 40
Definition

double myarray[]

new double [40];

Term
declare an array of string and and store them in the following; "Monday", "Tuesday","Wednesday", "Thursday", "Friday","Saturday", and "Sunday".
Definition
String.[] Days_of_week ={“Monday”, “Tuesday”, “Wednesday”, “Thrusday”, “Friday”, “Saturday”, “Sunday”};
Term
Declare a 2-D array of size 4X5. Write the Java loop to initialize all its location to 1.


Definition

int [][]

mal= new int [4][5];

for (int i=0; i<4; i++)

for (int j=0; j<5; j++);

mal [i][j]=1;

Term

Steps to a 2D Matrix Array Program

 

Definition
  1. Declare m and n as static ints and set to values. 
  2. create load array
  3. create print array
  4. create add array
  5. create multiply array
  6. create main 
Term
Elements of a Load Matrix
Definition

public static void loadMatrix(int[][] A)

{

for (int Row = 0; Row length; Row++)

{

for (int Col = 0; Col length; Col++)

{

A[Row][Col] = (int)((Math.random()* 6 -3));

}

}

}

Term
Print Array
Definition

public static void printMatrix(int[][] A, int n)

{

System.out.println();

for (int Row = 1; Row <= n; Row++)

{

for (int Col = 1; Col <= n; Col++)

{

System.out.print(Format.rightAlign(6,A[Row][Col]));

}

System.out.println();

}

System.out.println();

}

Term
Code for Martix Add
Definition

public static void MatrixAdd (int A [][], int B [][], int C [][], int n)

{

for(int Row = 0; Row <= n; Row ++)

{

for (int Col = 0; Col <= n; Col ++)

{

C[Row][Col] = A[Row][Col] + B[Row][Col];

}

 

}

}

Term
Code for Multiply Matrix
Definition

public static void MatrixMult(int A[][], int B[][], int C[][], int m)

{

for(int i=1; i<=m;i++)

{

for(int Row=1; Row<=m;Row++)

{

for(int Col= 1; Col<=m; Col++)

{

C[Row][Col]=0;

 

C[Row][Col]= A[Row][i]*B[i][Col]+C[Row][Col];

}

}

}

}

Term
Main for 2D Array Program
Definition

public static void main(String[] args) 

{

int[][]D = new int[10][10];

int[][]E = new int[10][10];

int[][]F = new int[10][10];

 

loadMatrix(D);

loadMatrix(E);

 

printMatrix(D, n);

printMatrix(E, n);

MatrixAdd(D,E,F, n);

printMatrix(F, n);

MatrixMult(D,E,F, m);

printMatrix(F, n);

}

Term
How to tell whether binary is positive or negative
Definition
  • positive (leftmost bit is 0): as in binary to decimal
  •  negative (leftmost bit is 1): convert the number to its positive by flipping all the bits, then convert as in binary to decimal, then put a minus sign in front of it.
Term
Machine Code
Definition
Machine code is the only form of program instructions that the computer hardware can understand and execute directly. All other forms of computer language must be translated into machine code in order to be executed by the hardware. Machine code consists of many strings of binary digits that are easy for the computer to interpret.
Term
Assembler Language
Definition
Assembly language is a symbolic representation of machine code, which allows programmers to write programs in machine code without having to deal with the long binary strings. For example, the machine code for an instruction that adds two numbers might be 01101110, but in assembly language, this can be represented by the symbol ADD. A simple assembler program translates this symbolic language directly into machine code. Because machine code is specific to each type of computer hardware, assembly languages are also specific to each type of computer. 
Term
Higher Level Language
Definition
High-level language is a language that is convenient for human beings to understand. High-level programming languages must be translated into machine code for execution, and this process is called compilation. A program that carries out this translation is a compiler. High-level language may bear no resemblance at all to machine code. The compiler figures out how to generate machine language that does exactly what the high-level-language source program specifies. Languages like C++, Algol, COBOL, etc., are all compiled high-level languages. They usually work more or less the same across all computer types, which makes them much more portable than assembly language.
Term
Compiler
Definition
translates other languages into assembly level equivalents
Term
What is the difference between a class and an object?
Definition
class is basically a definition, and contains the object's code. An object is an instance of a class. For instance, there is one java.lang.String class, but you can instantiate any number of distinct java.lang.String objects (instances). While a class defines the instance variables than an object has, the instantiated object itself actually contains those variables. So to put it simply: An object is an instance of a class


Term
Difference between object declaration and object creation
Definition

Declaration of the object involves only creating the reference variable to the object.

Example:

class SampleClass{ }

Object Declaration:

SampleClass obj1;

Object Creation:

Creating an object involves use of new keyword and actually allocating memory for that object.

SampleClass obj2 = new SampleClass ();

 

Term
Design of an instantiable class
Definition
  1. What does it do? 
  2. What does it "know"?
  3. Draw a box for each method and put the input(s) (if any) and output (if any) on each box. Write the heading for each method
  4. Design the constructors. (keep in mind what a constructor does, creates the object and sets the data items to something reasonable)
  5. Write the heading for each constructer with comments. 
Term
Get a character at a specific position in a String.
Definition

charAt(position that number is in starting at 0)

or 

substring(<number>,<number>)

 

 

Term
six numerical data types
Definition
int, byte, short, long, double, float
Term
Get the position of a character
Definition
text.indexOf("<character>")
Term
Math class expressions
Definition

Math.

PI()
random()
sqrt()
abs()
max (x,y)
cos, tan and sin()
acos, atan, asin (*arc of sin, cosine and tangent)
pow(x,y)

min()

cbrt()

Term
Memory allocation of primitive data
Definition
The data is fixed pg.87 (Chapter 3.1)
Term
Decimal Format
Definition

DecimalFormat df = new DecimalFormat("0.00");

 

System.out.print("Currency is: " + df.format(currency));

Term
GregorianCalendar
Definition

GregorianCalendar today = new GregorianCalendar();

 

or specific date

 

GregorianCalender independenceDay = new GregorianCalendar(1776, 6, 4);

Term
Switch Statement
Definition

Switch Class {

Case 1: <expression>

 

Case 2: <expression>

 

<default> 

 

break;

}

 

Term

Scanner

 

Definition
  • declare scanner
  • create scanner (scanner=new Scanner(system.in);)
  • firstName = scanner.next();
Term
Program Design
Definition
  1. Import Values
  2. Data Values
  3. Define Class(es)
  4. Define Methods
  5. Pseudo Code
Term
Basic components of an object-oriented program
Definition
  • classes
  • objects
  • messages (when you tell something what to do. Ex: get obstable distance. getters/setters)
  • methods
Term
Inheritence
Definition
two sub classes that share a connection. Example: two students in the same class at WSU. 
Term
Convert Input strings to numerical data
Definition

double.parseDouble();

 

or 

 

int.parseInt();

Term
Reserved word "this"
Definition

self referencing pointer because it is used to refer the recieving object of a message from within the method. *method-only thing

 

example:

a = this.getNumerator();

 

Term
Format
Definition

 

Study 6.7 Pg.326

Term
Difference between java and othe higher level languages
Definition
Java runs on the JVM which while is platform specific does not require the language to be platform specific. 

In other words, the runtime is different depending on OS and architecture but the language you write will be same.
Supporting users have an ad free experience!