CPS 101: Computer Programming I: General Questions (40 Points)
CPS 101: Computer Programming I: General Questions (40 Points)
Mid-term Exam
Alfusainey Jallow, Lamin Saidy & Ebrima Jaw April 1st, 2016
Instructions
Please answer all questions. The questions are divided into general and problem set questions! There is
an optional bonus point question worth 10 points.
Good Luck!
p u b l i c s t a t i c f i n a l LIMIT=2;
4. (5 pts ). What is a static variable in Java? How will the static age variable be called?
1 p u b l i c c l a s s Person {
2 p u b l i c s t a t i c age ;
3 }
5. Is it true that all Java programs must have a main method? Motivate your answer. (5 pts )
6. (5 pts ) What are the rules for declaring a constructor and state it's main function in a Java
program.
7. (10 pts ) Consider the code snippet below. How can you get the string Algebra from the course
variable?
S t r i n g c o u r s e = "Modern Algebra 1 " ;
S t r i n g a l g e b r a = . . . ; // c o m p l e t e t h i s p a r t .
Hint: Use the method structure provided below. Feel free to declare additional local variables if
you want.
1 p u b l i c d o u b l e compute ( ) {
2
3 d o u b l e x = u s e t h e Math l i b r a r y h e r e ;
4 ...
5
6 return x ;
7 }
1
2. (15 pts ) Write a predicate method isPositive(int value) that returns true if its explicit param-
eter is postive and false otherwise.
1 public c l a s s PersonTester {
2 p u b l i c s t a t i c v o i d main ( S t r i n g a r g s [ ] ) {
3 // HINT : c a l l t h e setName ( S t r i n g ) and s e t A g e ( i n t ) methods
4 // o f t h e p e r s o n c l a s s h e r e . . .
5 }
6 }
How can you call the setName(String) and setAge(int) methods inside of the main method of the
PersonTester class?