EG1745 Lab7 - Loops(MonoDisplay)

19
  School of Engineering Course : Diploma in Multimedia & Infocomm Technology (EGDF15) Module : Programming Methodologies and Practices (EG1745) Laboratory : 7. Loops (MonoDisplay) Objectives : This lab covers the usage of loops. Software(s) : Eclipse IDE Instructions: The Java programs created for this laboratory session can be stored in C:\users\<your_userid>\EG1745-Lab on your laptop. Lab 7 – Loops (II) Page 1 of 19 Effective Date: 15 Apr 2015

description

Java

Transcript of EG1745 Lab7 - Loops(MonoDisplay)

  • School of Engineering

    Course : Diploma in Multimedia & Infocomm Technology (EGDF15)

    Module : Programming Methodologies and Practices (EG1745)

    Laboratory : 7. Loops (MonoDisplay) Objectives : This lab covers the usage of loops. Software(s) : Eclipse IDE Instructions: The Java programs created for this laboratory session can be stored in

    C:\users\\EG1745-Lab on your laptop.

    Lab 7 Loops (II) Page 1 of 19 Effective Date: 15 Apr 2015

  • SEG

    Library MonoDisplay.java Method void openDisplay() Arguments Nil What it does Pops up a Pixel window with 10 rows (0 to 9) and 20 columns (0 to 19) Usage Example public static void main(String[] args)

    { MonoDisplay.openDisplay(); }

    Library MonoDisplay.java Method void setPixelON(int r, int c) Arguments r : This represents the row number of the Pixel to turn on

    c : This represents the column number of the Pixel to turn on What it does Set the pixel represented at position (r,c) to ORANGE Usage Example public static void main(String[] args)

    { MonoDisplay.openDisplay(); MonoDisplay.setPixelON(3,8);

    }

    Library MonoDisplay.java Method void setPixelOFF(int r, int c) Arguments r : This represents the row number of the Pixel to turn off

    c : This represents the column number of the Pixel to turn off What it does Set the pixel represented at position (r,c) to gray background Usage Example public static void main(String[] args)

    { MonoDisplay.openDisplay(); MonoDisplay.setPixelOFF(3,8);

    }

    Lab 7 Loops (II) Page 2 of 19 Effective Date: 15 Apr 2015

  • SEG

    Library MonoDisplay.java Method void pause(int t) Arguments t

    This represents the time (in milliseconds) Description The screen will pause for duration of t milliseconds. This is to control

    the speed of animation on the screen. Usage Example public static void main(String[] args)

    { MonoDisplay.openDisplay(); MonoDisplay.setPixelON(3,8); MonoDisplay.pause(100); // pause the screen for 100ms MonoDisplay.setPixelOFF(3,8);

    }

    Library MonoDisplay.java Method void closeDisplay() Arguments Nil Description This will close the window. Usage Example public static void main(String[] args)

    { MonoDisplay.openDisplay(); MonoDisplay.pause(100);

    MonoDisplay.closeDisplay(); }

    Lab 7 Loops (II) Page 3 of 19 Effective Date: 15 Apr 2015

  • SEG Task 1 1.1 Requirements a) You are to light up a user-specified pixel of the MonoDisplay :

    1.2 Design

    // How to ensure that the system only allows the user to enter between 0 and 9 for row // How to ensure that the system only allows the user to enter between 0 and 19 for col

    Lab 7 Loops (II) Page 4 of 19 Effective Date: 15 Apr 2015

  • SEG 1.3 Implementation a) Create a Java Project called Lab7Task1, and a package named pkg. b) Download MonoDisplay.java from Blackboard (http://learn.nyp.edu.sg). Copy this java file

    into pkg. c) Add in App.java with the main method

    1.4 Testing Make sure you test at least the 4 corners of the screen, the center of the screen, and when the user input is not within 0-9 for row and 0-19 for column.

    Test Case

    Title Input Expected Result

    Lab 7 Loops (II) Page 5 of 19 Effective Date: 15 Apr 2015

  • SEG Task 2 (Blinking Pixel) 2.1 Requirements a) You are to blink up a user-specified pixel for 2 seconds :

    2.2 Design

    // In App.java, write a method: public static void blinkPixel(int r, int c) { _____________________________________ MonoDisplay.pause(2000); //2000ms is 2 secs _____________________________________ }

    Lab 7 Loops (II) Page 6 of 19 Effective Date: 15 Apr 2015

  • SEG 2.3 Implementation a) Copy Lab7Task1 into Lab7Task2 and continue from there. b) In the main method, call the blinkPixel method to perform the blinking. 2.4 Testing Make sure you test at least the 4 corners of the screen, the center of the screen, and when the user input is not within 0-9 for row and 0-19 for column.

    Test Case

    Title Input Expected Result

    Lab 7 Loops (II) Page 7 of 19 Effective Date: 15 Apr 2015

  • SEG Task 3 (Draw Vertical Line) 3.1 Requirements a) You are to draw a vertical column at a user-specified column number and height.

    3.2 Design

    // In App.java, write a method: public static void drawVertLine(int c, int h) // c is the user-column, h is the user-height { // Use a Loop to compress the following : // setPixelON(c,0); // setPixelON(c,1); // setPixelON(c,2); // // setPixelON(c, h-1); }

    Lab 7 Loops (II) Page 8 of 19 Effective Date: 15 Apr 2015

  • SEG 3.3 Implementation a) Copy Lab7Task2 into Lab7Task3 and continue from there. b) In the main method, call the drawVertLine method to draw the Line. 3.4 Testing Conduct at least 4 tests with various positions and heights

    Test Case

    Title Input Expected Result

    Lab 7 Loops (II) Page 9 of 19 Effective Date: 15 Apr 2015

  • SEG Task 4 (Draw Horizontal Line) 4.1 Requirements a) You are to draw a horizontal line at a user-specified row number and length.

    4.2 Design

    // In App.java, write a method: public static void drawHorLine(int r, int l) // r is the user-row, l is the user-length { // Use a Loop }

    Lab 7 Loops (II) Page 10 of 19 Effective Date: 15 Apr 2015

  • SEG 4.3 Implementation a) Copy Lab7Task3 into Lab7Task4 and continue from there. b) In the main method, call the drawHorLine method to draw the Line. 4.4 Testing Conduct at least 4 tests with various positions and lengths

    Test Case

    Title Input Expected Result

    Lab 7 Loops (II) Page 11 of 19 Effective Date: 15 Apr 2015

  • SEG Task 5 (Draw Horizontal Line at a given location) 5.1 Requirements a) You are to draw a horizontal line at a user-specified location and length. b) Do not show any portion of the line that extends beyond the right side of the Window.

    5.2 Design

    // In App.java, write a method: public static void drawHorLineAt(int r, int c, int l) // r is the user-row, c is the user-col, // l is the user-length { // Use a Loop // if (c+0 < 20) SetPixelON(r,c+0) // if (c+1 < 20) SetPixelON(r,c+1) // if (c+2 < 20) SetPixelON(r,c+2) // until // if (c+(l-1) < 20) SetPixelON(r,c+(l-1)) }

    Lab 7 Loops (II) Page 12 of 19 Effective Date: 15 Apr 2015

  • SEG 5.3 Implementation a) Copy Lab7Task4 into Lab7Task5 and continue from there. b) In the main method, call the drawHorLineAt method to draw the Line. 5.4 Testing Conduct at least 4 tests with various positions and lengths

    Test Case

    Title Input Expected Result

    Lab 7 Loops (II) Page 13 of 19 Effective Date: 15 Apr 2015

  • SEG Task 6 (Draw Dotted Horizontal Line at a given location) 6.1 Requirements a) You are to draw a dotted horizontal line at a user-specified location and length. b) Do not show any portion of the line that extends beyond the right side of the Window.

    6.2 Design

    // In App.java, write a method: public static void drawDottedHorLineAt(int r, int c, int l) // r is the user-row, c is the user-col, // l is the user-length { // Similar to drawHorLineAt, except that you only Turn Pixel ON when // the column is even ( use modulo 2 to check odd/even) }

    Lab 7 Loops (II) Page 14 of 19 Effective Date: 15 Apr 2015

  • SEG 6.3 Implementation a) Copy Lab7Task5 into Lab7Task6 and continue from there. b) In the main method, call the drawDottedHorLineAt method to draw the Line. 6.4 Testing Conduct at least 4 tests with various positions and lengths

    Test Case

    Title Input Expected Result

    Lab 7 Loops (II) Page 15 of 19 Effective Date: 15 Apr 2015

  • SEG Task 7 (Draw Rectangle Line at a given location) 7.1 Requirements a) You are to draw a Rectangle at a user-specified location, length, and height. b) Do not show any portion of the rectangle that extends beyond the right side of the Window.

    7.2 Design

    // In App.java, write a method: public static void drawRectAt(int r, int c, int l, int h) // r is the user-row, c is the user-col, // l is the user-length, h is the user-height { // Hint : this is made up of drawing h horizontal lines of length l

    //drawHorLineAt(r, c, l); //drawHorLineAt(r+1, c, l); //drawHorLineAt(r+2, c, l); // until //drawHorLineAt(r+(h-1), c, l);

    }

    Lab 7 Loops (II) Page 16 of 19 Effective Date: 15 Apr 2015

  • SEG 7.3 Implementation a) Copy Lab7Task6 into Lab7Task7 and continue from there. b) In the main method, call the drawHorLineAt method repeated to draw the Rectangle. 7.4 Testing Conduct at least 4 tests with various positions and length, and height.

    Test Case

    Title Input Expected Result

    Lab 7 Loops (II) Page 17 of 19 Effective Date: 15 Apr 2015

  • SEG Task 8 (Draw Fading Horizontal Line at a given location) 8.1 Requirements a) You are to draw a fading horizontal line at a user-specified location and length. b) Do not show any portion of the line that extends beyond the right side of the Window.

    8.2 Design

    // In App.java, write a method: public static void drawFadeHorLineAt(int r, int c, int l) // r is the user-row, c is the user-col, // l is the user-length { // Call drawHorLineAt method to draw the line // Pause for 100 ms // Copy and Modify the code from drawHorLineAt method off the Pixels. Add a small // delay of 30ms after OFF each pixel to enhance visual effect. }

    On for 800ms only

    Lab 7 Loops (II) Page 18 of 19 Effective Date: 15 Apr 2015

  • SEG 8.3 Implementation a) Copy Lab7Task6 into Lab7Task7 and continue from there. b) In the main method, call the drawFadeHorLineAt method to draw the Line. 8.4 Testing Conduct at least 4 tests with various positions and lengths

    Test Case

    Title Input Expected Result

    Lab 7 Loops (II) Page 19 of 19 Effective Date: 15 Apr 2015