Results 1 to 2 of 2
Thread: Importing other programs
- 10-06-2012, 04:17 AM #1
Member
- Join Date
- Oct 2012
- Posts
- 1
- Rep Power
- 0
Importing other programs
I am a student in high school in AP Computer Science. We have to design separate programs then combine them. For example. I have multiple programs for different geometric equations. I need to make a separate program that acts as a menu. When the user selects the equation they need it pulls up the equation needed. When the equation program is finished it will request if the user wants to use it again. If not it will return back to the menu. How would I set this up.
- 10-06-2012, 06:15 AM #2
Member
- Join Date
- Oct 2012
- Location
- Tempe, Arizona
- Posts
- 77
- Blog Entries
- 12
- Rep Power
- 0
Re: Importing other programs
If you have all of your files in the same folder, it is relatively easy to set up. Here is a quick example of the main program:
Java Code:import java.util.Scanner; public class mainPgm{ public static void main(String[] args){ Scanner keyboard = new Scanner(); char again, subAgain; do{ System.out.println("This is the main menu, make a selection 1-3, /n1)blah /n2)blah /n3)blah"); selection = keyboard.nextInt(); if(selection == 1){ do{ subPgm1 pgm1 = new subPgm1(); pgm1.hello(); System.out.println("Repeat this option? y/n"); subAgain = keyboard.next().charAt(0); }while(subAgain = 'y'); }else if(selection == 2){ do{ subPgm2 pgm2 = new subPgm2(); pgm2.hello(); System.out.println("Repeat this option? y/n"); subAgain = keyboard.next().charAt(0); }while(subAgain = 'y'); }else{ do{ subPgm3 pgm3 = new subPgm3(); pgm3.hello() System.out.println("Repeat this option? y/n"); subAgain = keyboard.next().charAt(0); }while(subAgain = 'y'); } System.out.println("See main menu again? y/n"); again = keyboard.next().charAt(0); }while(again == 'y'); } }
And a quick example of your functions that you will be calling:
Java Code:public class subPgm1{ public void hello(){ System.out.println("You selected 1!"); } }Java Code:public class subPgm2{ public void hello(){ System.out.println("You selected 2!"); } }Java Code:public class subPgm3{ public void hello(){ System.out.println("You selected 3!"); } }
One thing that might differ is if you are returning something from one of your subprograms. In that case you would have to create a variable of the same type that it is returning, and make that variable equal to the function call.
Java Code:int sub1 = pgm1.hello();
Hope that helps clear things up...
Similar Threads
-
Please help fix error for two programs!
By Asvin in forum New To JavaReplies: 6Last Post: 10-13-2011, 11:59 PM -
robust programs
By dntcheatme in forum New To JavaReplies: 6Last Post: 05-03-2011, 08:54 PM -
Writing a programs
By smray7 in forum New To JavaReplies: 7Last Post: 04-28-2011, 07:49 AM -
Cant run my programs anymore
By Glenn1990 in forum New To JavaReplies: 2Last Post: 02-25-2011, 08:49 PM -
I need a simple programs
By mikau in forum New To JavaReplies: 2Last Post: 02-11-2008, 03:37 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks