Forums Register Login

understanding why my code does not work

+Pie Number of slices to send: Send
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!

Mary




+Pie Number of slices to send: Send


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.
+Pie Number of slices to send: Send
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.
So there I was, trapped in the jungle. And at the last minute, I was saved by this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 602 times.
Similar Threads
Displaying an override in inheritance.
How do I parse a String?
printing data from objects
what am i doing wrong? on this java gui
Trying to figure out what those mean
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 07:39:38.