009-002-007
public Modifier: Point Card
Easy
Problem Description
public Modifier: Point Card
Learning Objective: Combine public methods with private fields
In this problem, you will create a program that implements a PointCard class with a private field to store points and public methods to add and retrieve points, displaying the results to standard output.
Implement a PointCard class that manages a point card. Declare the point total as a private int points field to encapsulate it, provide an addPoints(int p) method to add points, and a getPoints() method to return the current total.
Input
Line 1: Points to add (integer)
Output
Initial points: 0
Added: [points]
Current points: [total]
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