dimanche 27 novembre 2016

Inaccessible returned Strings in Java

I keep getting the error that the Strings cannot be passed from method to method and I need to do that. The goal of the program is to return two Strings and an integer to the main to access another method that will randomly generate a name based off of the given factors. NameGenerator.java:12: error: cannot find symbol String rappername = rappername(firstname, lastname, color); symbol: variable firstname location: class NameGenerator 1 error

import java.util.*; public class NameGenerator{

  public static void main(String[] args) {
  Scanner console= new Scanner(System.in);
  firstname(console);
  lastname(console);
  color(console);
  String firtname = firstname(console);
  String lastname = lastname(console);     
  int color = color(console);
  String rappername = rappername(firstname, lastname, color);
  }

  public static String firstname(Scanner console) {
  System.out.println("Welcome to my Program!");
  System.out.println("I'm going to tell you your rapper name.");
  System.out.println("What is your first name? (Type stop to quit) ");
  String firstname;
   firstname = console.nextLine();
  if (firstname.equals("stop")) {
     System.exit(0);
  }
  else {
  return firstname;
    }
 }

 public static String lastname(Scanner console) {
  String lastname;
  System.out.println("What is your last name? ");
   lastname = console.nextLine();
  return lastname;
  }

  public static int color(Scanner console) {
  int color;
  System.out.println("Pick the number to your color of choice");
  System.out.println("Blue (1)");
  System.out.println("Red (2)");
  System.out.println("Purple (3)");
  color = console.nextInt();
  return color; 
  }

public static String rappername(String firstname, String lastname, int color)  `       {    
  System.out.println(firstname+lastname+color);
  }  
  }

Aucun commentaire:

Enregistrer un commentaire