3 Replies - 482 Views - Last Post: 06 October 2013 - 01:51 PM Rate Topic: -----

#1 JavaIntroMan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 06-October 13

creating a menu problem

Posted 06 October 2013 - 01:35 PM

Create a method run that includes a character menu system allowing the user to make selections by entering a char value.
The other menu options are to provide access to each of the methods listed here.
Create the method reverse. It will receive a String and return the reversed string of characters.
Create the method ourSubString. It will receive a String, and two int values. The values int values will be the starting (included) and ending (excluded) index positions of a substring with the string given. Return the substring. Do not use the method substring given in the class String.
Create the method alphabet. It will receive two characters (both will be upper case letters) and return a string composed of the range of char values given. Note, the range will be inclusive of the starting char and exclusive of the ending char. If 'H' and 'M' are passed to the method, it will return "HIJKL". Also, observe that if the starting (first) char given is greater than the ending (second) char, for example 'M' and 'H', then the method will return an empty string, "", since there are no chars in this range.

Can someone give me some pointers?

Is This A Good Question/Topic? 0
  • +

Replies To: creating a menu problem

#2 grimpirate  Icon User is offline

  • Pirate King
  • member icon

Reputation: 149
  • View blog
  • Posts: 714
  • Joined: 03-August 06

Re: creating a menu problem

Posted 06 October 2013 - 01:42 PM

I'm not sure I entirely understand what you're describing, but if I understood the first part correctly you're basically trying to employ the setMnemonic method of a JMenuItem. You could also pass the parameter during its construction.
Was This Post Helpful? 0
  • +
  • -

#3 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 822
  • View blog
  • Posts: 2,529
  • Joined: 29-July 11

Re: creating a menu problem

Posted 06 October 2013 - 01:46 PM

I doubt is has anything to do with swing. I be it's a console assignment needing input with scanner.

So, what you have you written so far?
Was This Post Helpful? 0
  • +
  • -

#4 JavaIntroMan  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 06-October 13

Re: creating a menu problem

Posted 06 October 2013 - 01:51 PM

I have alot of the methods completed, but I dont know how to create the menu that asks for input and then uses that input to implement each method. I have this example that shows what im typing to accomplish on a more basic scale.

public String remove(String toBeRemoved){
int index = sentences.indexOf(toBeRemoved);
String temp = sentences.get(index);
sentences.remove(index);
return temp;
}

public void replace(String replacement, int index){
sentences.remove(index);
sentences.add(index, replacement);
}


public void menu(){
Scanner scanner = new Scanner(System.in);
System.out.print("Which menu option do you want? remove or replace?: ");
String data = scanner.next();
if(data.equals("remove")){
System.out.print("What element do you want to remove? [of type String]: ");
data = scanner.next();
System.out.println(remove(data));
}
else if(data.equals("replace")){
System.out.print("What index value do you want to replace? [of type int]: ");
int index = scanner.nextInt();
System.out.print("What is the new value? [of type String]: ");
data = scanner.next();
replace(data, index);
}
else
System.out.println("Invalid method call");
}
}
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1