Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2013
    Wisconsin, USA
    Rep Power

    Default Program won't let me set my setters as public void.

    I'm trying to re-learn how to use Java classes. Here's the main class code:

    Java Code:
    package pokemon;
    import java.text.NumberFormat;
    public class PokemonCard {
    	//the instance variables
    	private String name;
    	private String type;
    	private String rarity;
    	private Double value;
    	//the constructor
    	public PokemonCard(){
    		name = "";
    		type = "";
    		rarity = "";
    		value = 0.00;
    	public void setName(String name){ = name;
    	public String getName(){
    		return name;
    	public void setType(String type){
    		this.type = type;
    	public String getType(){
    		return type;
    	public void setRarity(String rarity){
    		this.rarity = rarity;
    	public String getRarity(){
    		return rarity;
    	public void setValue(Double value){
    		this.value = value;
    	public double getValue(){
    		return value;
    	public String getValueFormatted(){
    		NumberFormat currency = NumberFormat.getCurrencyInstance();
    		String valueFormatted = currency.format(value);
    		return valueFormatted;
    And the following is my attempt to make an instance of the PokemonCard class:

    Java Code:
    package pokemon;
    public class StaticPokemon {
    	public static PokemonCard getPokemon(String productCode) {
    		PokemonCard pokemon = new PokemonCard();
    		}else if(name.equalsIgnoreCase("Pikachu")){
    		}else if(name.equalsIgnoreCase("Lugia")){
    			pokemon.setName("Unknown pokemon. No available data.");
    		return pokemon;
    But lines 9, 10, 14, and 18 in the StaticPokemon class all give the error, "name cannot be resolved to a variable". What's wrong?
    Last edited by SamJava_the_Hut; 10-10-2018 at 06:52 AM. Reason: I realized that I was just missing a curly brace. Next problem.

  2. #2
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    The Netherlands
    Rep Power

    Default Re: Program won't let me set my setters as public void.

    The variable "name" you are trying to pass to the setName method does not exist. It's not the method the compiler can't find, it's the parameter.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

Similar Threads

  1. Public void issues??
    By jmcquaid1987 in forum New To Java
    Replies: 1
    Last Post: 04-11-2014, 01:23 AM
  2. why public void clear() had error pls Help mE
    By zafri in forum New To Java
    Replies: 2
    Last Post: 10-02-2012, 10:12 AM
  3. Q?> about public static void main(String args[])
    By boblingwide in forum New To Java
    Replies: 4
    Last Post: 03-23-2012, 11:17 AM
  4. What wrong with it?case : public static void main
    By bytescode in forum New To Java
    Replies: 7
    Last Post: 02-10-2011, 07:01 AM
  5. Replies: 1
    Last Post: 12-04-2010, 05:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts