0% found this document useful (0 votes)
70 views3 pages

Homework Assignment 06: Programming Assignments

The document provides instructions for 6 programming assignments: 1) Create a test class to test a MyTimer class by timing a loop and printing results. 2) Create a Sanitizer class with a static method to sanitize strings by removing special characters. Test it. 3) Write a program to get comma separated scores from the user, calculate the average, and print results. 4) Begin creating a Pong game by making a Paddle class to represent the player's paddle and draw it in the Pong class. 5) Comments and naming conventions are important. 6) Complete all assignments by the due date.

Uploaded by

Pooja Palande
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views3 pages

Homework Assignment 06: Programming Assignments

The document provides instructions for 6 programming assignments: 1) Create a test class to test a MyTimer class by timing a loop and printing results. 2) Create a Sanitizer class with a static method to sanitize strings by removing special characters. Test it. 3) Write a program to get comma separated scores from the user, calculate the average, and print results. 4) Begin creating a Pong game by making a Paddle class to represent the player's paddle and draw it in the Pong class. 5) Comments and naming conventions are important. 6) Complete all assignments by the due date.

Uploaded by

Pooja Palande
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Homework assignment 06

Complete the following programs for this week's homework.

Programming assignments
Creating a test class (10 poinsts)
Chapter 10 discusses class encapsulation and abstraction, meaning that you don't need to know how a class
works internally in order to use it. For this problem, you'll write a test class using following MyTimer class:

Write a test class


That creates a timer instance
Starts the timer
Adds up all the numbers from 0-99, printing the elapsed time in milliseconds on each iteration
Stops the timer
Note:
- Do not write the MyTimer class! This is an example showing you don't need to know everything about the
class to use it
- Don't worry about the red squiggles. You don't have a MyTimer class, so you won't actually be able to run this

program.

Static Sanitization (20 points)


Whenever you write a public-facing website or service that allows users to enter data, that data needs to be
checked to make sure weird stuff doesn't happen to your code or database. That's called sanitizing your data.
Write a class named Sanitizer that includes a static method sanitize() that takes a String as input, removes
any of the following characters and returns the sanitized String.
Characters to remove: "#!*$%&" (not the quotes. or this sentence)
Then write a test class that will call the static sanitize method with an "unsanitized" string and then print out the
returned "sanitized" string.
Note:
- The Sanitizer class should be properly created so one cannot make an instance of it (remember the modifiers
to use on the constructor to prevent this. And look at chapter 9)
- Look at the section on the String class in Chapter 10. You should be able to do this without writing a single
loop

Comma Separated Scores (30 points)


Comma Separated Value, or CSV, is a common format for table data stored as a file or transmitted. The
contents of a csv file at its simplest form could something like this:
78.0,92.5,88.8,96.4

Write a program that asks the user to enter a list of comma separated scores of double type and returns the
average of the given scores. Example input and output:
please enter the string of scores, separated by commas:
78.0,92.5,88.8,96.4
Average score is 88.92500000000001

Note: - The line of scores entered should not have any spaces

Pong Part 1 - Paddle (40 points)

We're going to make a Pong game in processing, starting with the paddle for 1 player. See animation here: gif
Create a java class named Pong.java for our game and a Paddle class for the player's paddle.
The Paddle class should have the following data fields:
- width and height of the game screen
- width and height of the paddle
- x position, y position
- Speed
It should also have the following methods:
- a constructor that passes the game screen's width and height, and sets up any default values
- a moveLeft method that moves the paddle towards the left
- a moveRight method that moves the paddle towards the right
Note: the paddle should not go off the screen!
In the Pong game class:
- create an instance of the Paddle class, passing the width and height of the game screen
- draw a rectangle for the paddle, using the instance's x position, y position, width, and height
- include a keypressed method that moves the paddle left or right if the user is holding down the left or right
key.

Remember that comments and good naming conventions factor into your grade! Don't forget.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy