[an error occurred while processing this directive]

Individual Work 2 - Practice: Variables, Objects, Methods, Math

[an error occurred while processing this directive]

Description

In this assignment you will not be using Processing. Instead, you will be practicing using variables, math operators, type casting, methods, and objects. The down-side is that you will not be creating anything visual. The up-side is that as you go along, Eclipse will use something called JUnit testing to let you know if your code works.

Directions

Read all directions before beginning your work.

  1. Start by importing IW2Arithmetic.zip into Eclipse.
  2. In the Project Explorer, open the src folder then the (default package) folder. Notice three files:
    1. Arithmetic.java: you will edit this file
    2. Prizes.java: do not edit this file
    3. Tester.java: do not edit this file either
  3. The Arithmetic.java file contains five method readers and default return statements. You will remove the return statement currently in each method and replace it with the result of the computations described below.
  4. computeGrade: Takes three double parameters tests, homework, and finalExam. Each parameter represents the score on different elements of a class grade. Output the final grade, given that tests are worth 30% of the overall grade, homework 50%, and the final exam 20%.
  5. computeDistance: Takes one double parameter seconds. Output the number of meters travelled by a free-falling object over the period of time subject to the formula depicted below, in which g is the gravitational constant 9.8 meters per second per second, and t is the time in seconds.
  6. getDigit: Takes two int parameters number and place. number is an integer between 1000 and 9999. place is 1, 10, 100, or 1000. Output the digit in number represented by place. For example, if number is 1234 and place is 10, then output 3.
  7. ticketCounter: Takes one int parameter tickets, the number of tickets won playing arcade games like skee-ball. Outputs a Prizes object representing the quantities of the three different prizes you can claim with tickets: bears (cost: 10 tickets), gum balls (cost: 3 tickets), and stickers (cost: 1 ticket). Since you prefer bears to gum balls and gum balls to stickers, you always take as many bears as you can, then as many gum balls as you can, then finally as many stickers as you have tickets remaining. When you create the Prizes object, specify the number of bears, gum balls, and stickers similar to the way in PW2 you created a color by specifying r, g, and b values.
  8. scaleMAR: Takes four int parameters oldW, oldH, maxW, and maxH. In this problem, you need to scale down an image to fit in a particular space, but you also want to maintain the aspect ratio of the image. The first two parameters are the original image size (width and height). The last two parameters are the size of the space you need to scale down to (width and height). Output a Point object representing the size of the scaled-down image. For example, your original image is 400 pixels wide and 300 pixels high. Your available space is 200 pixels wide and 100 pixels high. Your result should be 133 pixels wide and 100 pixels high.

Resources

The resources below are the only resources you should use in completing this assignment. In particular, do not use the CSC 130 tutors and do not search any electronic resources such as the Web for sample code.

Grading

Recall that individual work assignments are worth 50 points each. Refer to the syllabus for more course grading information.

Each of the 5 questions are worth 10 points, divided as follows. Partial credit may be awarded.

Submission

Submit by taking two actions: create a printout and upload a file. Details are below.

  1. Ensure that your name appears as a comment at the top of the Arithmetic.java code file.
  2. Make a printout of the Arithmetic.java code file. Use duplex if possible so you submit fewer pieces of paper. Ensure that each method prints entirely on one side of a page - avoid splitting method code across pages (copy to Microsoft word if necessary). If you have multiple sheets, staple them. Print the file before class starts, not during class.
  3. Upload your Arithmetic.java file to the appropriate Moodle page. Do not export your code and do not submit a zip file. Just submit the single .java file.
[an error occurred while processing this directive]