1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Constructor with a string paramater?

  1. Nov 6, 2011 #1
    I have a class for soccer players with these attributes:
    //players first name
    private firstName;
    //players lastName
    private lastName;
    //number of points scored by player
    private int pointsScored = 0;
    //number of assists the player had
    private int assists = 0;
    //the percentage kick penalty rate the player had
    private double penaltyKickRate = 0.0;

    i am assigned to have a constructor with a single formatted string parameter like this:

    public SoccerPlayerStats(String playerinfo) {
    //initialize values

    where the playerinfo string is formatted this way
    "Jane Doe: Points Scored: 3 Assists: 5 Kick Rate Percentage: 3"

    how in the world can i initialize these values in the contructor? With substrings maybe? It just seems a little wacky to me. Any tips will help : )

    - Amanda
  2. jcsd
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted

Similar Threads for Constructor string paramater
Using a custom constructor in a C++ class