Results 1 to 15 of 15
Thread: Problem with menu-driven program
- 09-30-2010, 05:29 PM #1
Member
- Join Date
- Sep 2010
- Posts
- 12
- Rep Power
- 0
Problem with menu-driven program
I have a program that I have to write and can not figure out why the way I'm writing the menu isn't working. Here is my block of code for the menu so far, you can see I'm only working with 1 input so far, and I am getting an error compiling in ** ProcessPicture(input);** this line. Any help would be greatly appreciated.
public static void main(String[] args)
{
Scanner in = new Scanner (System.in);
int userChoice;
boolean quit = false;
//Picture q = p.oilPaint(5);
//q.explore();
do {
System.out.println("1. Choose a Picture to Process");
System.out.println("2. Display Picture");
System.out.println("3. Make Picture Black & White");
System.out.println("4. Make Picture Negative color");
System.out.println("5. Flip Picture 180 Degrees");
System.out.println("6. Save Picture to New File");
System.out.print("Pick a choice above or press 0 to Quit: ");
userChoice = in.nextInt();
switch (userChoice) {
case 1:
// process picture
ProcessPicture(input);
break;
case 2:
// display picture
break;
case 3:
// black and white
break;
case 4:
// negative
break;
case 5:
// flip 180 degrees
break;
case 6:
// save to new file
break;
case 0:
quit = true;
break;
default:
System.out.println("Invalid Selection, please select a choice above.");
break;
}
System.out.println();
}
while (!quit);
System.out.println("Have a nice day");
}
private void ProcessPicture(java.io.InputStream input){
Scanner in = new Scanner(input);
Picture p =
new Picture(FileChooser.pickAFile());
p.explore();
}
/*private void DisplayPicture(java.io.InputStream input)
private void BlackAndWhite(java.io.InputStream input)
private void Negative(java.io.InputStream input)
private void FlipUpsideDown(java.io.InputStream input)
private void Save(java.io.InputStream input)
*/
- 09-30-2010, 06:01 PM #2
please copy and paste the full text of the error message here.I am getting an error compiling
- 09-30-2010, 06:01 PM #3
Member
- Join Date
- Sep 2010
- Posts
- 12
- Rep Power
- 0
if i put....
Scanner in = new Scanner(input);
Picture p =
new Picture(FileChooser.pickAFile());
p.explore();
into my case 1:, then it works fine. I could do this to complete the assignment but i'd rather learn how to do it correctly.
- 09-30-2010, 06:02 PM #4
Member
- Join Date
- Sep 2010
- Posts
- 12
- Rep Power
- 0
the error says...
File: C:\------------\PictureMenu.java [line: 460]
Error: C:\------------\PictureMenu.java:460: cannot find symbol
symbol : variable input
location: class PictureMenu
oh and I am using DrJava if that matters
- 09-30-2010, 06:17 PM #5
please copy and paste the full text of the error message here.
Your edited version leaves stuff off.
Where is the variable input defined? Is it in scope where you are trying to use it?
- 09-30-2010, 06:25 PM #6
Member
- Join Date
- Sep 2010
- Posts
- 12
- Rep Power
- 0
It isn't, the last time I did a program similar to this, I had Scanner in = new Scanner (input); and it worked fine. However when I put that in, it also creates an error.
I think I'm missing something really basic, but I can't figure out what I'm doing wrong.Last edited by t0nydanzuh; 09-30-2010 at 06:32 PM.
- 09-30-2010, 06:39 PM #7
please copy and paste the full text of the error message here.
- 09-30-2010, 07:10 PM #8
Senior Member
- Join Date
- Jul 2008
- Posts
- 125
- Rep Power
- 0
If you use code tags, your indentations will be perserved.
I have never used case/switch statments before, except
long ago in a Pascal assignment.
All of your clues indicate to me that blocks of code within
a switch-case statement that have more than one line
of code (beyond a solitary "break;" statement), need to
have braces {} enclosing them.
Also, it is optional, but some consider it good practice to
place single lines of code, such as all of your "break;"
statements in braces {}.
EMENDED!! I'VE JUST REVEWED MANY JAVA CASE
EXAMPLES, AND I SEE I REALLY DON'T HAVE
GOOD EXPERIENCE WITH THIS TOPIC.
However, I have found an error in my indentation
of my interpretation of this code, and have corrected
it below.
Java Code:public static void main(String[] args){ Scanner in = new Scanner (System.in); int userChoice; boolean quit = false; //Picture q = p.oilPaint(5); //q.explore(); do { System.out.println("1. Choose a Picture to Process"); System.out.println("2. Display Picture"); System.out.println("3. Make Picture Black & White"); System.out.println("4. Make Picture Negative color"); System.out.println("5. Flip Picture 180 Degrees"); System.out.println("6. Save Picture to New File"); System.out.print("Pick a choice above or press 0 to Quit: "); userChoice = in.nextInt(); switch (userChoice) { case 1: // process picture ProcessPicture(input); // Probably all of this should break; // be enclosed in braces {} case 2: // display picture break; case 3: // black and white break; case 4: // negative break; case 5: // flip 180 degrees break; case 6: // save to new file break; case 0: quit = true; break; default: System.out.println("Invalid Selection, please select a choice above."); break; } System.out.println(); } while (!quit); System.out.println("Have a nice day"); } private void ProcessPicture(java.io.InputStream input){ Scanner in = new Scanner(input); Picture p = new Picture(FileChooser.pickAFile()); p.explore(); } /*private void DisplayPicture(java.io.InputStream input) private void BlackAndWhite(java.io.InputStream input) private void Negative(java.io.InputStream input) private void FlipUpsideDown(java.io.InputStream input) private void Save(java.io.InputStream input) */ }Last edited by paul pasciak; 09-30-2010 at 09:58 PM. Reason: Indentation and not experienced with this topic
- 09-30-2010, 08:54 PM #9
Member
- Join Date
- Sep 2010
- Posts
- 12
- Rep Power
- 0
1 error found:
File: C:\Users\Steve\Desktop\CS260\java-source\PictureMenu.java [line: 461]
Error: C:\Users\Steve\Desktop\CS260\java-source\PictureMenu.java:461: cannot find symbol
symbol : variable input
location: class PictureMenu
- 09-30-2010, 08:59 PM #10
What is the source code on line 461?
Did you leave off some of the error message? When I compile with an error I get:
Notice the source line and the ^ pointer.Java Code:TestCode2.java:45: cannot find symbol symbol: variable TRUE return TRUE; ^ 1 error
- 09-30-2010, 09:09 PM #11
Member
- Join Date
- Sep 2010
- Posts
- 12
- Rep Power
- 0
line 461 is:
ProcessPicture(input);
- 09-30-2010, 09:31 PM #12
Where is the variable: input defined?
I think I already have asked this question in post#5.
- 09-30-2010, 09:38 PM #13
Member
- Join Date
- Sep 2010
- Posts
- 12
- Rep Power
- 0
i figured it out. What happened is I had this in the main method, and it couldnt work that way. Here's my working code, thanks for the help.
Scanner in = new Scanner (System.in);
public static void main(String[] args)
{
PictureMenu p = new PictureMenu();
p.PictureMenus(System.in);
}
public void PictureMenus(java.io.InputStream input){
Scanner in = new Scanner (input);
int userChoice;
boolean quit = false;
//Picture q = p.oilPaint(5);
//q.explore();
do {
System.out.println("1. Choose a Picture to Process");
System.out.println("2. Display Picture");
System.out.println("3. Make Picture Black & White");
System.out.println("4. Make Picture Negative color");
System.out.println("5. Flip Picture 180 Degrees");
System.out.println("6. Save Picture to New File");
System.out.print("Pick a choice above or press 0 to Quit: ");
userChoice = in.nextInt();
switch (userChoice) {
case 1:
// process picture
ProcessPicture(input);
break;
case 2:
// display picture
break;
case 3:
// black and white
break;
case 4:
// negative
break;
case 5:
// flip 180 degrees
break;
case 6:
// save to new file
break;
case 0:
quit = true;
break;
default:
System.out.println("Invalid Selection, please select a choice above.");
break;
}
System.out.println();
}
while (!quit);
System.out.println("Have a nice day");
}
private void ProcessPicture(java.io.InputStream input){
Scanner in = new Scanner(input);
Picture p =
new Picture(FileChooser.pickAFile());
p.explore();
}
/*private void DisplayPicture(java.io.InputStream input)
private void BlackAndWhite(java.io.InputStream input)
private void Negative(java.io.InputStream input)
private void FlipUpsideDown(java.io.InputStream input)
private void Save(java.io.InputStream input)
*/
}
- 09-30-2010, 09:40 PM #14
Member
- Join Date
- Sep 2010
- Posts
- 12
- Rep Power
- 0
Since I have your attention, do you know the best way to save a picture to a new file? with extensions such as .jpg or .gif
- 09-30-2010, 09:43 PM #15
Similar Threads
-
Menu-driven console help please
By floppyspace in forum New To JavaReplies: 4Last Post: 03-12-2010, 04:12 PM -
how to create menu-driven programs?
By princess.blue in forum EclipseReplies: 0Last Post: 12-07-2009, 08:01 AM -
need menu program
By student_doesntget_java in forum New To JavaReplies: 2Last Post: 03-20-2009, 09:58 AM -
Menu driven system - atm
By thelinuxguy in forum Advanced JavaReplies: 1Last Post: 02-18-2009, 11:14 PM -
want menu driven prog. who to take user i/p in the middle of the prog.
By Shyam Singh in forum New To JavaReplies: 1Last Post: 07-13-2008, 03:16 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks