Spring08_PracticeFinalExam

Spring08_PracticeFinalExam - CS1316 Spring 2008 Practice...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
CS1316 Spring 2008 Practice Exam Final NAME: ___________________________________ PRISM ID:_______________________________ 1 Part I: Random Generators and Picture Methods Using Math.random() or the Random class, construct a method to solve the following problem. Write a new method in AdvancedPicture that will randomly change the pixels of the AdvancedPicture . There is a 40% chance that the pixel will have the red value maximized. 20% chance for the green value. 15% chance for the blue value. 25% chance that all green, blue and red values are set to 0. (Hint: Max value is 255). public void randomizePixels() public void grayscale(){ Pixel[] pixels = this.getPixels(); for (int i = 0; i < pixels.length; i++){ int intensity = (int) ((pixel[i].getRed() + pixel[i].getGreen() + pixel[i].getBlue()) / 3); pixel[i].setColor(new Color(intensity,intensity,intensity)); } }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
CS1316 Spring 2008 Practice Exam Final NAME: ___________________________________ PRISM ID:_______________________________ 2 Part II: Random Generators and LinkedList Methods Using Math.random() or the Random class, construct a method to solve the following problem. StudentList.java Part II: Random Generators and LinkedList Methods (continued) Student.java import java.util.Random; public class StudentList { private Random gen = new Random(); private StudentNode head; public StudentList(StudentNode head) {this.head = head;} public StudentNode getHead() {return head;} public void setHead(StudentNode head) {this.head = head;} public void add(StudentNode student){ if (size() == 0) head = student; else last().setNext(student);} public StudentNode last(){ if (size() == 0) return null; StudentNode current = head; while (current.getNext() != null) current = current.getNext(); return current;} public int size(){ int size = 0; StudentNode current = head; while (current != null){ size++; current = current.getNext();} return size;} public boolean insertAfter(StudentNode node, StudentNode newStudent){ StudentNode current = head; while (current != null){ if (current.equals(node)) break; current = current.getNext(); } if (current == null) return false; else{ StudentNode oldNext = node.getNext(); node.setNext(newStudent); newStudent.setNext(oldNext); return true;} } public String toString(){ String ret = ""; StudentNode current = head; while (current != null){ ret = ret + current.toString() + "\n"; current = current.getNext(); } return ret;} }
Background image of page 2
CS1316 Spring 2008 Practice Exam Final NAME: ___________________________________ PRISM ID:_______________________________ 3 Student.java StudentNode.java Write a new toString method in StudentList that contains no loops (while or for) and is recursive. (Hint: figure out what parameters the method needs to take in).
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/30/2010 for the course CS 1316 taught by Professor Staff during the Spring '08 term at Georgia Tech.

Page1 / 14

Spring08_PracticeFinalExam - CS1316 Spring 2008 Practice...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online