Skip Top Navigation Bar

AP Computer Science A Free Response Practice - Data Analysis and ArrayList - Workout Time

Clock

This single part question is worth 5 points.

AP CSA Alignment

Unit Alignment Learning Objectives Resources Skills
Unit 1: Using Objects and Methods 1.3.C Develop code for arithmetic expressions and determine the result of these expressions. 2.A Write program code to implement an algorithm.
1.10.A Develop code to call class methods and determine the result of those calls. 2.C Write program code involving procedural abstractions.
Unit 2: Selection and Iteration 2.3.A Develop code to represent branching logical processes by using selection statements and determine the result of these processes. 2.A Write program code to implement an algorithm.
Unit 4: Data Collections 4.9.A Develop code used to traverse the elements of an ArrayList and determine the results of these traversals. 2.B Write program code involving data abstractions.
4.10.A Develop code for standard and original algorithms for a particular context or specification that involve ArrayList objects and determine the result of these algorithms.

Directions

The Workout class is used to record information for a fitness app about a workout. A Workout object has a type of exercise (e.g."Running", "Cycling", "Swimming"), the duration in minutes, and the calories burned. A declaraion of the Workout class is shown.

The WorkoutLog class maintains an ArrayList named workouts that contains all the workouts a person logs for a week. A partial declaration of the WorkoutLog class is shown.

Assume that typeA and typeB workouts exist in workouts and that the duration of each entry is not 0. Further assume that workouts of the same type are uniformly recorded.

Write the moreEfficientType method in the WorkoutLog class. This method should return the type of workout that has the higher average calories burned per minute across all workouts in workouts. It the two workout types have the same average calories burned per minute, either type can be returned.

Example 1

Suppose workouts contains the following Workout objects for the following workouts:

  • Running for 30 minutes burning 300 calories
  • Running for 15 minutes burning 150 calories
  • Cycling for 40 minutes burning 320 calories
  • Cycling for 20 minutes burning 180 calories

Based on these entries, Running burned an average of 10 calories per minute and Cycling burned an average of 8.33 calories per minute. Running burns more aveage calories. Running should be returned.

Example 2

Suppose workouts contains the following Workout objects for the following workouts:

  • Swimming for 30 minutes burning 300 calories
  • Swimming for 10 minutes burning 100 calories
  • Yoga for 40 minutes burning 400 calories

Based on these entries, both Swimming and Yoga burn 10 calories per minute. Either type can be returned.

Write Your Response

  • In order to test your program, we have provided some test cases for calls to moreEfficientType.
  • Write the code for the method moreEfficientType in the Java Playground as indicated by the comment add your code here.
  • All tests should return true if your code is correct.