CS 103

Outline of Material for Test 2


The following is a brief outline of the material which will be covered on the first test. All of this information can be found in the lecture notes and/or on this web page.
  1. Mathematical Calculations in Java
    1. Identify each of the math operators in Java, i.e. +, -, *, /, %
    2. What does precedence refer to in math formulas in Java?
    3. Why do you use parentheses in math formulas in Java?
    4. Given a mathematical formula, such as the common formulas shown below, show how you would write the formula in Java. Pay careful attention to where you would need to use parentheses to ensure the calculations are done in the correct order.













  2. Object Oriented Programming with Classes
    You should know:
    1. What is a class?
    2. What is an object in Object Oriented Programming?
    3. What do the terms instantiate and instance mean in Object Oriented Programming with Java?
    4. When you define a class where do the member variables go?
    5. What is the new operator used for in a program. Give an example of its' use.
  3. Strings and Character Variables in Java
    You should know:
    1. Show how you would define a char variable called ch and store the character A in it.
    2. What does the acronym ASCII stand for?
    3. Show how you would create a String reference variable and initialize it to "This is a test string.".
    4. Given a String variable called str show how you would set it to hold the phrase "Java is fun!".
    5. Given each of the following functions which are part of the String class and the string str containing "Java is Fun!" explain what each does or what it will return: str.charAt(1), str.compareTo("JAVA IS FUN"), str.concat(" Right?!"), indexOf('i'), indexOf("Fun"), str.length(), str.substring(0, 4), str.toLowerCase(), str.toUpperCase().
  4. Using Eclipse
    You should know:
    1. You have just typed the following into a class file after the opening {. Eclipse underlines JPanel in red. How do you fix the problem?



    2. You have just created the class MyMenuBar and want to make it a sub-class of JMenuBar. What do you add to this line?

      	
      	public class MyMenuBar
      	{
      	
      	
    3. You have just typed the following to make MyClass a sub-class of JFrame. Eclipse underlines JFrame in red. How do you fix the problem?



    4. You defined a member variable of type JTextField in your class and called it m_StatusTextField. When you type the following Eclipse indicates an error. What is the problem and how do you fix it?



    5. You have just typed the following in the class file for GUIDemoMenuBar and Eclipse has flagged errors on every line after the declaration private JMenu m_FileMenu; But, there are no syntax errors apparent. What is the problem and how do you fix it?
      public class GUIDemoMenuBar extends JMenuBar
      {
      	/** The File menu */
      	private JMenu	m_FileMenu;
      	m_FileMenu = new JMenu("File");  
      	m_FileMenu.setMnemonic(KeyEvent.VK_F); // "F" for File
      	m_FileMenu.getAccessibleContext().setAccessibleDescription("Load and save files, etc.");
      	m_FileMenu.setBackground(Color.lightGray);
      	this.add(m_FileMenu);
      	public GUIDemoMenuBar()
      	{
      	}
      }
      
    6. In each of the following lines taken from a Java program, Eclipse has flagged a syntax error. Identify and fix the error.

      	if(x == 3) && (y == 4)                           // x and y are both integers
      	m_MainPanel.setSize(640, 480)                    // m_MainPanel is a JPanel
      	m_Label1.setLocation(32);                        // m_Label1 is a JLabel
      	while(count <= 3                                 // count is an integer
      	m_StatusTF = New JTextField();                   // m_StatusTF is a JTextField
      	m_MainPanel.add(JSlider);                        // m_MainPanel is a JPanel
      	m_TextButton1.setBackgroundColor(Color.WHITE);   // m_TextButton1 is a JButton
      	listData.add(new String("List item 01);          // listData is a Vector
      	public static void main(String args)             // start of the main() function
      	if(val = 2.5)                                    // val is a double
      	for(int i=0, i<10, i++)                          // start of a for loop
      	System.out.println("Num = ", num);               // num is an integer