• Post Reply Bookmark Topic Watch Topic
  • New Topic

understanding why my code does not work  RSS feed

Mary Sibert
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello everyone,
I am new to Java and I am struggling with my latest assignment that deals with methods. I am unable to figure out what I am doing wrong. Could someone give me advice and tell me what is wrong with my code and advice on how to fix it. I think once I get a little push I can start to really understand.

Here is my program so far. I am unable to figure out the method that deals with the getStringInput(String prompt).

public class Headbands4UPhase1 {

* @param args
public static void main(String[] args) {

// declare variables
String openingMsg, nameInputMsg, customerName, nameOutputMsg,
returnInputMsg, customerReturn, returnOutputMsg,
greetingOutputMsg, outputMsg,headbandColor,colorInputMsg, colorOutputMsg, jewelInputMsg, jewelOutputMsg, jewelOption;

// display opening message
openingMsg = "*** Welcome to Headbands4U Online Ordering System ***\n"
+ " It's a great day to order a headband!";
JOptionPane.showMessageDialog(null, openingMsg);
// get required input using dialogs
private static String getStringInput(String prompt){
String customerName;
return customerName;

String customername = "Please enter your name: ";
JOptionPane.showMessageDialog(null, "Please enter your name");
if (customerName==null)
{JOptionPane.showMessageDialog(null, "Error. Please enter your name:", customerName, 3);


Thankyou for your time!


Daniel Gurianov
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You do exit at line 05 , and all code below is not used.
you should do return only after you got some input from user, i.e at the end of whole method.
fred rosenberger
lowercase baba
Posts: 12563
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generally, it works better here if you post specifics about the problem you are having. Does it compile? does it run? Does it print something you don't expect?

You may want to read our HowToAskQuestionsOnJavaRanch FAQ.

I think Daniel is right. When you say "return <something>", you are saying "i'm done in this method, so leave right now and send this value back". I would think you are getting an unreachable statement error when you compile.

However, if you are seeing some other problem, please let us know.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!