Starting from:

$30

CS 220 Lab #9 – Solved

                                    

The Jack Programming Language


                      
1.       Translate the following Java code into its equivalent Jack code.

Jack Code
 


2.       

Jack Code
 


3.         Write the Jack code that produces the following transaction with the user.
Note: the green text indicates input from the user.

Jack Code
 
 
4.         Write the Jack code that produces the following transaction with the user.
Note: the green text indicates input from the user.

Jack Code
 

 
5.         Translate the entire Main class (written in Java) into its Jack equivalent.

Jack Code
 


6.       Convert the following Java class (Fraction.java) into its Jack equivalent (two files/classes named Fraction.jack and Main.jack).

  

Jack Code
 
 
7.       Write a Jack program that will display a square (30 pixels x 30 pixels), starting in the top-left (x=0, y=0) of the screen, then moving around the edge of the screen clockwise (e.g. along the top edge, then right edge, bottom edge, left edge) until it gets back to the origin.

The square should move by itself, with a short wait between each movement 

Jack Code
Summative Questions:

8.       When we execute a Jack program, the first subroutine that starts running is:

Main.main()

9.       Can a subroutine in one Jack class access field variables of another Jack class?

No, unless you create getter methods.



10.   Which Jack classes should have a method for disposing objects?


All Jack classes should provide this.



11.   What does the keyword “this” implicitly refer to? (Select all that apply)

a)      In constructors: the current object

b)      In functions: the current object

c)      In methods: the current object

d)      In Main.main: the current object





12.   Which of the following are true about Jack classes? (Select all that apply)

a)      A Jack class must have a constructor

b)      A Jack class can contain either methods, or functions, but not both

c)      Each Jack class must be stored in a separate file

d)      Each Jack class must have a subroutine named “main”

 

1.       Translate the following Java code into its equivalent Jack code.

Jack Code
 

 
 
2.       

Jack Code

 
3.         Write the Jack code that produces the following transaction with the user.
Note: the green text indicates input from the user.

Jack Code
 
 
4.         Write the Jack code that produces the following transaction with the user.
Note: the green text indicates input from the user.

Jack Code

 
5.         Translate the entire Main class (written in Java) into its Jack equivalent.

Jack Code    6.       Convert the following Java class (Fraction.java) into its Jack equivalent (two files/classes named Fraction.jack and Main.jack).

  

Jack Code

 
7.       Write a Jack program that will display a square (30 pixels x 30 pixels), starting in the top-left (x=0, y=0) of the screen, then moving around the edge of the screen clockwise (e.g. along the top edge, then right edge, bottom edge, left edge) until it gets back to the origin.

The square should move by itself, with a short wait between each movement.

  
Jack Code
 

 

 
Summative Questions:

8.       When we execute a Jack program, the first subroutine that starts running is:

Main.main()

9.       Can a subroutine in one Jack class access field variables of another Jack class?

No, unless you create getter methods.



10.   Which Jack classes should have a method for disposing objects?


All Jack classes should provide this.



11.   What does the keyword “this” implicitly refer to? (Select all that apply)

a)      In constructors: the current object

b)      In functions: the current object

c)      In methods: the current object

d)      In Main.main: the current object

12.   Which of the following are true about Jack classes? (Select all that apply)

a)      A Jack class must have a constructor

b)      A Jack class can contain either methods, or functions, but not both

c)      Each Jack class must be stored in a separate file

d)      Each Jack class must have a subroutine named “main”

 

More products