By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,101 Members | 1,463 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,101 IT Pros & Developers. It's quick & easy.

Java Gurus Help

P: n/a
I'm doing a uni course in the UK and one of my semesters is about
programming. This is just going to be compilied and executed with no menu
just using command promt (javac classfile.class)

I am not that good at programming but what I need to know is in java how
would i do this..................

menu appears, user selects menu option (1,2,3,4,5,6) a new menu appears
after selecting option 1 asking the user to select another option
(A.B.C.D.E.F)..... What I need to know is will this be a IF
statement........

If (Variable1 = = '1')
{
do this line
{
if (Variable = = '2)
do this line
(
if (Variable = = '3')
{
do this line E.T.C for each variable.

What i need to do is let the user choose from the first menu and then be
able to select a second menu, but i dont no how to call the second menu for
more than option 1, so if a user selects 2 how do i call it aswell. ? I hope
you can understand what I mean. If not then please ask me what you need to
know and i will try and help to help you understand what i mean.

Thanks
Mar 11 '06 #1
Share this Question
Share on Google+
13 Replies


P: n/a
Andrew Bell wrote:
I'm doing a uni course in the UK and one of my semesters is about
programming. This is just going to be compilied and executed with no menu
just using command promt (javac classfile.class)

I am not that good at programming but what I need to know is in java how
would i do this..................

menu appears, user selects menu option (1,2,3,4,5,6) a new menu appears
after selecting option 1 asking the user to select another option
(A.B.C.D.E.F)..... What I need to know is will this be a IF
statement........

If (Variable1 = = '1')
{
do this line
{
if (Variable = = '2)
do this line
(
if (Variable = = '3')
{
do this line E.T.C for each variable.

What i need to do is let the user choose from the first menu and then be
able to select a second menu, but i dont no how to call the second menu for
more than option 1, so if a user selects 2 how do i call it aswell. ? I hope
you can understand what I mean. If not then please ask me what you need to
know and i will try and help to help you understand what i mean.

Thanks

As for the selection of one menu, with (1,2,3,4,5,6) options, that
displays a another menu, with (A.B.C.D.E.F) options, does not seem to
make sense. You can not have one menu option popup another menu unless
it is a popup menu but that can not be what you mean..

Are you not sure that you have one window with a menu that you can
select options (1,2,3,4,5,6) that opens a new window that has it own
menu with the (A.B.C.D.E.F) options, the user can select?

You have to explain it better than you just did? Can not help you
because it is not clear.

As for the if statement. It can be coded three different ways depending
on the var Type:

If (stringVar.equals("1"){
}
else if (charVar == '1'){
}
else if (intVar == 1){
}

You can also use a SWITCH statement instead of a if statement.

I can point you to some docs and examples but, like I said, you have to
explain your homework in a understandable fashion. I will not give you
the exact code but can point you to what you have to do and with what API's.

http://javaalmanac.com/egs/javax.swing/Menu.html

Here is a source for information. Also another link to examples that may
help with programming menus.

http://java.sun.com/docs/books/tutor...ybigindex.html
Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Mar 11 '06 #2

P: n/a
This is what I have so far.

//Andrew Bell
public class MiniBank
{
public static void main(String args[])
{
String title[] = {"Current Account ", "ISA ", "Mortgage ", "Car Loan
"};
String ConfigMenu[] = {"A. For a specific customer, display details of
their accounts.",
"B. Get the ballance in an account for a specified customer.",
"C. Add to an account for a specific customer.",
"D. Withdraw from an account for a specified customer.",
"E. Get the total funds in all of the current accounts in the
bank.",
"F. Get the total funds in all of the ISA's in the bank."};

char Choice;
int Customer;
char Answer ='y';

int[] Customer1;
Customer1 = new int[4];
int[] Customer2;
Customer2 = new int[4];
int[] Customer3;
Customer3 = new int[4];
int[] Customer4;
Customer4 = new int[4];

System.out.println(" ");
System.out.println("Welcome To The Mini Bank");
System.out.println("------------------------");
System.out.println(" ");

for (int i=0; i<4; i++)
{
System.out.print("Please Enter Amount For Customer 1's " + title[i] +
"= ");
Customer1[i] = EasyIn.getInt();
}
System.out.println(" ");

for (int i=0; i<4; i++)
{
System.out.print("Please Enter Amount For Customer 2's " + title[i] +
"= ");
Customer2[i] = EasyIn.getInt();
}
System.out.println(" ");

for (int i=0; i<4; i++)
{
System.out.print("Please Enter Amount For Customer 3's " + title[i] +
"= ");
Customer3[i] = EasyIn.getInt();
}
System.out.println(" ");

for (int i=0; i<4; i++)
{
System.out.print("Please Enter Amount For Customer 4's " + title[i] +
"= ");
Customer4[i] = EasyIn.getInt();
}
System.out.println(" ");

//User Menu
System.out.println(" ");
System.out.println("Configuration Menu");
System.out.println("--------------------");

for (int i=0; i<6; i++)
{
System.out.println(ConfigMenu[i]);
}
System.out.println(" ");
System.out.println(" ");

System.out.print("Please select an option from the above menu
(A,B,C,D,E or F). = ");
Choice = EasyIn.getChar();

if ((Choice == 'A') || (Choice == 'a'))
{
System.out.print("Please select a customer. (1,2,3 or 4) = ");
Customer = EasyIn.getInt();

if (Customer == '1')
{
System.out.print("Customer 1");

{
System.out.print("Please select an option from the above menu
(A,B,C,D,E or F). = ");
}
}
}
}
}


Hope this helps the explination, basically what i need is if a user selects
an option for example A it then returns a message back saying please select
a customer. One the user has selected the customer it then displays the
bank ballances. That is my full program what ive done so for. Hope this
helps.
Mar 11 '06 #3

P: n/a
Andrew.Bell wrote:
This is what I have so far.

//Andrew Bell


Andrew, I tighten up some of the code. It works for your first option
now. You can see how I did because you will have to add new methods for
your other new options. I use a two dim array to hold your data for
customer and options. This cuts down on a lot of extra code. You may
want to change it to an arraylist object so that you will be able to add
new accounts or options dynamically and not worry about the size of the
array.

You did not pass along that *EasyIn* object so I just used the Scanner
class. This is close to what you were using. You can change it back but
you will have to change a few Strings to chars. You should do that.

Also, your code was very confusing because it did not follow any naming
convention. At least Java guidelines for naming your vars. You had all
upper case on the first letter of your var objects. Class names are the
only objects that have a uppercase first char of objects name. You will
see when you look at the code. You did a good job as far as I can tell.

You can see the Java coding conventions at this page:
http://java.sun.com/docs/codeconv/ht...nvTOC.doc.html

You can look at my website under my personal tab I have a section on
Java. It is not as nice as most but then I just keep it for myself and
if anybody can use it, fine. For me, its beats keeping a ton of URL's in
Bookmarks across multiple browsers.

If you have any questions just let me know.. or someone else can help
also..

For coding examples, say for an arraylist, you can goto Sun's Java
Developers Almanac, http://javaalmanac.com and search for arraylist or
any things you are trying to do.
[snip old code]

import java.util.Scanner;

public class MiniBank
{
static Scanner easyIn = new Scanner(System.in);

static String validTransactionOptions = "ABCDEFXabcdefx";
static boolean done = false;
//
// Instead using a 2 dim array to hold value Accounttype by customer
static int[][] customerArray = new int[5][4];
static String title[] = {"Current Account ", "ISA
", "Mortgage ", "Car Loan "};
static String ConfigMenu[] = {
"A. For a specific customer, display details of their
accounts.",
"B. Get the ballance in an account for a specified customer.",
"C. Add to an account for a specific customer.",
"D. Withdraw from an account for a specified customer.",
"E. Get the total funds in all of the current accounts in
the bank.",
"F. Get the total funds in all of the ISA's in the bank.",
"X. Finished."};

static char choice;
static int customer;

public static void main(String args[])
{
System.out.println(" ");
System.out.println("Welcome To The Mini Bank");
System.out.println("------------------------");
System.out.println(" ");

for (int nCustomer = 1; nCustomer < 5; nCustomer++) // outer
loop for customers
{
for (int ntransaction = 0; ntransaction < 4;
ntransaction++)// inner loop for amounts
{
System.out.print("Please Enter Amount For Customer "
+ nCustomer + "'s "
+ title[ ntransaction]
+ "= ");
// Using just one Two dim array
customerArray[nCustomer][ntransaction] = easyIn.nextInt();
}
}
//
//User Menu
System.out.println(" ");
System.out.println("Configuration Menu");
System.out.println("--------------------");

for (int i=0; i<6; i++)
{
System.out.println(ConfigMenu[i]);
}
System.out.println(" ");
System.out.println(" ");
//
// Loop and process untill done
while (!done) {
getTransactionOption();
}
}

public static void getTransactionOption()
{
System.out.print("Please select an option from the above menu
(A,B,C,D,E For X) = ");
String schoice = easyIn.next() ;
//
// Check for valid
if (validTransactionOptions.indexOf(schoice) > -1)
{
if(schoice.equals("X") || schoice.equals("x"))
done = true;
else
{
System.out.print("Please select a customer. (1,2,3 or 4) = ");
getDisplayInformation(schoice, easyIn.nextInt());
}
}
else
{
System.out.println("Error: Invalid option selected");
System.exit(9);
}
}

static void getDisplayInformation(String schoice, int customer)
{
int typeTransaction = 0;

if(schoice.equals("A") || schoice.equals("a"))
typeTransaction = 0;
else if(schoice.equals("B") || schoice.equals("b"))
typeTransaction = 1;
else if(schoice.equals("C") || schoice.equals("c"))
typeTransaction = 2;
else if(schoice.equals("D") || schoice.equals("d"))
typeTransaction = 3;
else if(schoice.equals("E") || schoice.equals("e"))
typeTransaction = 4;
else if(schoice.equals("F") || schoice.equals("f"))
typeTransaction = 5;
else
{
System.out.println("Error: Bad Transaction Type");
return;
}
System.out.println();
System.out.println("Customer "+customer+" Information for
Selected Option '"
+ schoice + "' is: "+
customerArray[customer][typeTransaction]);
System.out.println();
}
}
Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Mar 12 '06 #4

P: n/a
IchBin your good, I understand what you mean. Went to compile the code and
got this error.

C:\Java\MiniBank2.java:4: cannot find symbol
symbol : class Scanner
location: class MiniBank2
static Scanner easyIn = new Scanner(System.in);
^
C:\Java\MiniBank2.java:4: cannot find symbol
symbol : class Scanner
location: class MiniBank2
static Scanner easyIn = new Scanner(System.in);
^
2 errors

Tool completed with exit code 1

Do you no what this means ?
"IchBin" <we******@ptd.net> wrote in message
news:zN********************@ptd.net...
Andrew.Bell wrote:
This is what I have so far.

//Andrew Bell


Andrew, I tighten up some of the code. It works for your first option now.
You can see how I did because you will have to add new methods for your
other new options. I use a two dim array to hold your data for customer
and options. This cuts down on a lot of extra code. You may want to change
it to an arraylist object so that you will be able to add new accounts or
options dynamically and not worry about the size of the array.

You did not pass along that *EasyIn* object so I just used the Scanner
class. This is close to what you were using. You can change it back but
you will have to change a few Strings to chars. You should do that.

Also, your code was very confusing because it did not follow any naming
convention. At least Java guidelines for naming your vars. You had all
upper case on the first letter of your var objects. Class names are the
only objects that have a uppercase first char of objects name. You will
see when you look at the code. You did a good job as far as I can tell.

You can see the Java coding conventions at this page:
http://java.sun.com/docs/codeconv/ht...nvTOC.doc.html

You can look at my website under my personal tab I have a section on Java.
It is not as nice as most but then I just keep it for myself and if
anybody can use it, fine. For me, its beats keeping a ton of URL's in
Bookmarks across multiple browsers.

If you have any questions just let me know.. or someone else can help
also..

For coding examples, say for an arraylist, you can goto Sun's Java
Developers Almanac, http://javaalmanac.com and search for arraylist or any
things you are trying to do.
[snip old code]

import java.util.Scanner;

public class MiniBank
{
static Scanner easyIn = new Scanner(System.in);

static String validTransactionOptions = "ABCDEFXabcdefx";
static boolean done = false;
//
// Instead using a 2 dim array to hold value Accounttype by customer
static int[][] customerArray = new int[5][4];
static String title[] = {"Current Account ", "ISA ",
"Mortgage ", "Car Loan "};
static String ConfigMenu[] = {
"A. For a specific customer, display details of their
accounts.",
"B. Get the ballance in an account for a specified customer.",
"C. Add to an account for a specific customer.",
"D. Withdraw from an account for a specified customer.",
"E. Get the total funds in all of the current accounts in the
bank.",
"F. Get the total funds in all of the ISA's in the bank.",
"X. Finished."};

static char choice;
static int customer;

public static void main(String args[])
{
System.out.println(" ");
System.out.println("Welcome To The Mini Bank");
System.out.println("------------------------");
System.out.println(" ");

for (int nCustomer = 1; nCustomer < 5; nCustomer++) // outer loop
for customers
{
for (int ntransaction = 0; ntransaction < 4; ntransaction++)//
inner loop for amounts
{
System.out.print("Please Enter Amount For Customer "
+ nCustomer + "'s "
+ title[ ntransaction]
+ "= ");
// Using just one Two dim array
customerArray[nCustomer][ntransaction] = easyIn.nextInt();
}
}
//
//User Menu
System.out.println(" ");
System.out.println("Configuration Menu");
System.out.println("--------------------");

for (int i=0; i<6; i++)
{
System.out.println(ConfigMenu[i]);
}
System.out.println(" ");
System.out.println(" ");
//
// Loop and process untill done
while (!done) {
getTransactionOption();
}
}

public static void getTransactionOption()
{
System.out.print("Please select an option from the above menu
(A,B,C,D,E For X) = ");
String schoice = easyIn.next() ;
//
// Check for valid
if (validTransactionOptions.indexOf(schoice) > -1)
{
if(schoice.equals("X") || schoice.equals("x"))
done = true;
else
{
System.out.print("Please select a customer. (1,2,3 or 4) = ");
getDisplayInformation(schoice, easyIn.nextInt());
}
}
else
{
System.out.println("Error: Invalid option selected");
System.exit(9);
}
}

static void getDisplayInformation(String schoice, int customer)
{
int typeTransaction = 0;

if(schoice.equals("A") || schoice.equals("a"))
typeTransaction = 0;
else if(schoice.equals("B") || schoice.equals("b"))
typeTransaction = 1;
else if(schoice.equals("C") || schoice.equals("c"))
typeTransaction = 2;
else if(schoice.equals("D") || schoice.equals("d"))
typeTransaction = 3;
else if(schoice.equals("E") || schoice.equals("e"))
typeTransaction = 4;
else if(schoice.equals("F") || schoice.equals("f"))
typeTransaction = 5;
else
{
System.out.println("Error: Bad Transaction Type");
return;
}
System.out.println();
System.out.println("Customer "+customer+" Information for Selected
Option '"
+ schoice + "' is: "+
customerArray[customer][typeTransaction]);
System.out.println();
}
}
Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)

Mar 12 '06 #5

P: n/a
Andrew.Bell wrote:
IchBin your good, I understand what you mean. Went to compile the code and
got this error.

C:\Java\MiniBank2.java:4: cannot find symbol
symbol : class Scanner
location: class MiniBank2
static Scanner easyIn = new Scanner(System.in);
^

[snip code]

Did you leave the import statement at the top in. You will need that to
link to the Scanner class.

import java.util.Scanner;

If you did then what version of Java are you using.
Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Mar 12 '06 #6

P: n/a
Yep, I left the link to the Scanner class. Its alittle complicated as I've
only been doing this for 4 months since I started UNI. Thats why my program
was so crap. The version of Java I'm using is the latest SDK from the java
site. Still trying to get the head around different java aspects. The one
you did was nice but rather complicated for me to learn so quick.
Especially with all these loops and if statments and class files its very
hard but thank you. The way I did it I can understand and does what I
wanted it to do but was confused on the bit for the 2nd menu so a user could
select a customer AFTER selecting option A.
"IchBin" <we******@ptd.net> wrote in message
news:PM********************@ptd.net...
Andrew.Bell wrote:
IchBin your good, I understand what you mean. Went to compile the code
and got this error.

C:\Java\MiniBank2.java:4: cannot find symbol
symbol : class Scanner
location: class MiniBank2
static Scanner easyIn = new Scanner(System.in);
^

[snip code]

Did you leave the import statement at the top in. You will need that to
link to the Scanner class.

import java.util.Scanner;

If you did then what version of Java are you using.
Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)

Mar 12 '06 #7

P: n/a
I managed to get it to work, but this still leaves me with the rest of the
program to create,

I noticed that the import java.util.Scanner; had gone just like you said, my
fault.

I really wish it wasn't so hard but never mind. I'll try and get my head
around your way but its complicated and I've only known java for 4 months
without any other knowledge in programming. Ah lifes tuff
Mar 12 '06 #8

P: n/a
Below is what my assignment involves, could you basically point me in the
right direction to help me acomplish the task set but not give me the
acctual answer.

SCENARIO
This assignment is based on a banking system. This mini bank will have 4
customers. The customers each have 4 different accounts (Current Account,
ISA Savings Account, Mortgage and Car Loan).

Each customer should be represented as an array with 4 elements (Each
element of the array will represent one of their accounts).

Each customer aray should be an array of intergers. Therefore all amounts
in the accounts are interger values.

Your main program should allow the user to enter the initial amounts in each
account for each customer and then selec from a menu in order to do the
following tasks.

1.For a sepcific customer, display details of all their accounts.
2.Get the balance in an account for a specific customer.
3.Add to an account for a specific customer.
4. Withdraw from an account for a sepcified customer.
5.Get the total funds in all of the current accounts in the bank.
6.Get the total funds in all of the ISA's in the bank.

You are to plan, design and impliment and test the mini banking system.
Mar 12 '06 #9

P: n/a
Andrew.Bell wrote:
I managed to get it to work, but this still leaves me with the rest of the
program to create,

I noticed that the import java.util.Scanner; had gone just like you said, my
fault.

I really wish it wasn't so hard but never mind. I'll try and get my head
around your way but its complicated and I've only known java for 4 months
without any other knowledge in programming. Ah lifes tuff


Well you can still replace the inner and outer loop and use your old
code. That was not the problem you were having. The problem was the
other end of you program. So just replace the loops and concentrate on
the second user selection.

You threw me off before when you said a menu. Menu is a GUI object and
not command line displays.

Lot's of luck and have fun!

Hope I was able to help...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Mar 12 '06 #10

P: n/a
My apologies with throwing you off saying 'menu'. I'm still new to this
coding must learn the correct names for aspects of code. Thank you for your
time.
"IchBin" <we******@ptd.net> wrote in message
news:08********************@ptd.net...
Andrew.Bell wrote:
I managed to get it to work, but this still leaves me with the rest of
the program to create,

I noticed that the import java.util.Scanner; had gone just like you said,
my fault.

I really wish it wasn't so hard but never mind. I'll try and get my head
around your way but its complicated and I've only known java for 4 months
without any other knowledge in programming. Ah lifes tuff


Well you can still replace the inner and outer loop and use your old code.
That was not the problem you were having. The problem was the other end of
you program. So just replace the loops and concentrate on the second user
selection.

You threw me off before when you said a menu. Menu is a GUI object and not
command line displays.

Lot's of luck and have fun!

Hope I was able to help...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)

Mar 12 '06 #11

P: n/a
"IchBin" <we******@ptd.net> wrote in message
news:08********************@ptd.net...
You threw me off before when you said a menu. Menu is a GUI object and not
command line displays.


"Menu" is the name of a class in Java, and that's probably what you,
IchBin, were thinking. But the term "menu" was also used back when computers
only had text displays. They referred to exactly what Andrew is trying to
implement: A list of options which could be selected by pressing the code
(usually a single character long) associated with the desired option.

So Andrew wasn't "incorrect", but rather he was "ambiguous".

- Oliver

Mar 13 '06 #12

P: n/a

"Andrew.Bell" <ze******@zen.co.uk> wrote in message
news:44***********************@news.zen.co.uk...
Below is what my assignment involves, could you basically point me in the
right direction to help me acomplish the task set but not give me the
acctual answer.

SCENARIO
This assignment is based on a banking system. This mini bank will have 4
customers. The customers each have 4 different accounts (Current Account,
ISA Savings Account, Mortgage and Car Loan).

Each customer should be represented as an array with 4 elements (Each
element of the array will represent one of their accounts).

Each customer aray should be an array of intergers. Therefore all amounts
in the accounts are interger values.

Your main program should allow the user to enter the initial amounts in
each account for each customer and then selec from a menu in order to do
the following tasks.

1.For a sepcific customer, display details of all their accounts.
2.Get the balance in an account for a specific customer.
3.Add to an account for a specific customer.
4. Withdraw from an account for a sepcified customer.
5.Get the total funds in all of the current accounts in the bank.
6.Get the total funds in all of the ISA's in the bank.

You are to plan, design and impliment and test the mini banking system.


I'm assuming you know how to create methods.

You should create a method for each one of these six operations. For
now, just have them do something like print "This is option number 4.", and
then write the code for the menu system so that when the user selects an
item, the correct method is called (thus displaying the correct message).

From there, implement each method one by one.

This trick is known as "divide and conquer". That is, you divide the one
big problem into six smaller problems, and solve each smaller problem
individually. If the "smaller" problem is complicated, you can recursively
apply the same technqiue, and divide it again into even smaller problems
still.

- Oliver

Mar 13 '06 #13

P: n/a
Oliver Wong wrote:
"IchBin" <we******@ptd.net> wrote in message
news:08********************@ptd.net...
You threw me off before when you said a menu. Menu is a GUI object and
not command line displays.


"Menu" is the name of a class in Java, and that's probably what you,
IchBin, were thinking. But the term "menu" was also used back when
computers only had text displays. They referred to exactly what Andrew
is trying to implement: A list of options which could be selected by
pressing the code (usually a single character long) associated with the
desired option.

So Andrew wasn't "incorrect", but rather he was "ambiguous".

- Oliver

Thanks Oliver.. guess I forgot about the old days before I started
building GUI's on pc's in 1992.

--

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________ ________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Mar 13 '06 #14

This discussion thread is closed

Replies have been disabled for this discussion.