008-005-004

Reference Type Parameters: Modifying Objects

Medium

Problem Description

Reference Type Parameters: Modifying Objects

In this problem, you will create a program that receives a Counter object as a reference type parameter and modifies its count using increment() and incrementBy() methods, then displays the result to standard output.

Learning Objective: Understand how to pass reference types as method parameters and modify object state

Overview

Create methods that receive a Counter object as parameter and increase its count.

Specifications

  • Counter class: int count field
  • increment(Counter c) method: increase c.count by 1
  • incrementBy(Counter c, int amount) method: increase c.count by specified amount

Input

Initial value and increment amount are provided

Output Format

Initial: 5
After increment: 6
After incrementBy: 9

Ready to Try Running Code?

Log in to access the code editor and execute your solutions for this problem.

Don't have an account?

Sign Up