Java Gurus帮助 [英] Java Gurus Help

查看:61
本文介绍了Java Gurus帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在英国进行单一课程,我的一个学期是关于

编程。这只是编译和执行没有菜单

只是使用命令promt(javac classfile.class)


我不是很擅长编程但是我需要知道的是在java中如何使用
我会这样做..................


菜单出现,用户选择菜单选项(1,2,3,4,5,6)新菜单出现

选择选项1后要求用户选择另一个选项

(ABCDEF).....我需要知道的是这将是一个IF

声明........


如果(Variable1 = =''1'')

{

请执行此行

{

if(变量= =''2)

执行此行



if(Variable = =''3'')

{

为每个变量做这行ETC。


我需要做的是让用户从第一个菜单中选择然后是

能够选择第二个菜单,但我不知道如何拨打第二个菜单

more比选项1,所以如果用户选择2如何调用它也是如此。 ?我希望

你能明白我的意思。如果没有那么请问我你需要什么?b $ b知道,我会尽力帮助你理解我的意思。


谢谢

解决方案

Andrew Bell写道:

我正在英国做一个单一的课程,我的一个学期是关于
编程。这只是编译和执行没有菜单
只是使用命令promt(javac classfile.class)

我不是很擅长编程但我需要知道的是在java中如何
我会这样做..................

菜单出现,用户选择菜单选项(1,2,3,4 ,5,6)在选择选项1之后出现一个新菜单
要求用户选择另一个选项
(ABCDEF).....我需要知道的是这将是一个IF
声明........

如果(Variable1 = =''1'')
{
做这一行
{
如果(变量= =''2)
做这一行

if(Variable = =''3'')
{
做这行ETC for每个变量。

我需要做的是让用户从第一个菜单中选择然后能够选择第二个菜单,但我不知道如何调用第二个菜单
超过选项1,所以如果用户选择2我怎么称呼它呢?我希望你能理解这个我的意思是。如果没有,那么请问我你需要知道什么,我会尽力帮助你理解我的意思。

谢谢



至于选择一个菜单,有(1,2,3,4,5,6)个选项,

显示另一个菜单,(ABCDEF)选项,似乎没有

有意义。你不能有一个菜单选项弹出另一个菜单,除非

它是一个弹出菜单,但这不是你的意思..


你不确定吗你有一个菜单,你可以选择一个窗口

选择选项(1,2,3,4,5,6)打开一个新的窗口

菜单有(ABCDEF)选项,用户可以选择?


你必须比你刚才解释得更好吗?无法帮助你

,因为它不清楚。


至于if语句。它可以用三种不同的方式编码,取决于var上的
类型:


If(stringVar.equals(" 1"){

}

else if(charVar ==''1''){

}

else if(intVar == 1) {

}


您也可以使用SWITCH语句而不是if语句。


我可以指出你有一些文档和例子但是,就像我说的那样,你必须以一种可以理解的方式解释你的作业。我不会给你

确切的代码但可以指出你需要做什么以及使用什么API。

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


这是一个信息来源。另外一个链接示例可以帮助编程菜单。

htt p://java.sun.com/docs/books/tutor...ybigindex.html

在此先感谢...

IchBin,Pocono Lake,Pa,USA
http://weconsultants.servebeer.com/JHackerAppManager

__________________________________________________ ________________________


''如果有的话,知识就是青春之泉''

-William E. Taylor,Regular Guy(1952-)


这是我到目前为止。


//安德鲁贝尔

公共类MiniBank

{

public static void main(String args [])

{

String title [] = {" Current Account"," ISA"," Mortgage"," Car Loan

"};

String ConfigMenu [] = {" A.对于特定客户,显示其账户的详细信息。

" B.在指定客户的帐户中获得平衡。,

C。添加到特定客户的帐户。,

" D.退出指定客户的帐户。,

E。获取

银行中所有当前账户的总资金。,

F。获取银行中所有ISA的总资金。};


char选择;

int客户;

char答案=''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(欢迎来到迷你银行);

System.out.println(" ---) ---------------------");

System.out.println("");


for(int i = 0; i< 4; i ++)

{

System.out.print(" Please Enter Amount for Customer) 1''s&title; + title [i] +

" =");

Customer1 [i] = EasyIn.getInt();

}

System.out.println("");


for(int i = 0; i< 4; i ++)

{
System.out.print(请输入客户2的金额) + title [i] +

" =");

Customer2 [i] = EasyIn.getInt();

}

System.out.println("");


for(int i = 0; i< 4; i ++)

{

System.out.print(请输入客户3的金额'+ title [i] +

" =") ;

Customer3 [i] = EasyIn.getInt();

}

System.out.println("");


for(int i = 0; i< 4; i ++)

{

System.out.print(" Please输入客户4的金额'+ title [i] +

" =");

Customer4 [i] = EasyIn.getInt();

}

System.out.println("");


//用户菜单

System.out.println("");

System.out.println(" Configuration Menu");

System.out.println( " --------------------");


for(int i = 0; i< 6; i ++ )

{

System.out.print ln(ConfigMenu [i]);

}

System.out.println(" ");

System.out.println("");


System.out.print("请从中选择一个选项)菜单上面

(A,B,C,D,E或F)。=");

选择= EasyIn.getChar();


if((选择==''A'')||(选择==''''))

{

系统.out.print(" Please select a customer。(1,2,3 or 4)=");

Customer = EasyIn.getInt();


if(Customer ==''1'')

{

System.out.print(" Customer 1");
< br $>
{

System.out.print("请从上面的菜单中选择一个选项

(A,B,C,D,E)或者F)。=");

}

}

}

}

}


希望这有助于探索,基本上我需要的是如果用户选择

选项,例如A然后返回消息说请选择

a客户。一个用户选择了客户,然后显示了

银行平衡。这是我完整的计划,我为此做了什么。希望这个

有帮助。


Andrew.Bell写道:

这是我到目前为止所做的。 />
// Andrew Bell




Andrew,我收紧了部分代码。它适用于您的第一个选项
现在
。您可以看到我的表现,因为您必须为其他新选项添加​​新方法

。我使用两个昏暗的数组来保存您的数据,用于
客户和期权。这减少了许多额外的代码。您可以

想要将其更改为arraylist对象,这样您就可以动态添加

新帐户或选项,而不用担心

数组。


你没有传递* EasyIn *对象,所以我只使用了扫描仪

类。这与您使用的很接近。你可以改回来,但是你需要将几个字符串更改为字符。你应该这样做。


另外,你的代码非常混乱,因为它没有遵循任何命名

约定。至少用于命名你的vars的Java指南。你在var对象的第一个字母上有所有

大写字母。类名是

唯一具有对象名称的大写第一个char的对象。当你查看代码时,你会看到
。就我所知,你做得很好。


你可以在这个页面看到Java编码约定:
http://java.sun.com/docs/codeconv/ht...nvTOC.doc.html


您可以在我的个人标签下查看我的网站我有一个关于

Java的部分。它不像大多数那么好,但我只是为自己保留它和

如果有人可以使用它,很好。对我来说,它的节拍保留了大量的URL'

多个浏览器的书签。


如果您有任何疑问,请告诉我们。或其他人可以提供帮助

也是..


对于编码示例,比如arraylist,你可以转到Sun的Java

开发人员Almanac, http://javaalmanac.com 并搜索arraylist或

你要做的任何事情。

[剪掉旧代码]


import java.util.Scanner;


公共类MiniBank

{

静态扫描仪easyIn =新扫描仪(System.in);


static String validTransactionOptions =" ABCDEFXabcdefx";

static boolean done = false;

//

//而是使用2 dim数组来按客户持有账户类型

static int [] [] customerArray = new int [5] [4];

static String title [] = {" Current Account"," ISA

"," Mortgage"," Car Loan"};

static String ConfigMenu [] = {

" A.对于特定客户,显示其

帐户的详细信息。,

B。在指定客户的帐户中获得平衡。,

C。添加到特定客户的帐户。,

" D.退出指定客户的帐户。,

E。获取银行中所有当前账户的总资金。

" F。获得银行中所有ISA的总资金。,

X.完成。};


静态字符选择;

static int customer;


public static void main (String args [])

{

System.out.println("");

System.out.println(" ;欢迎来到迷你银行);

System.out.println(" ------------------------" ;);

System.out.println("");


for(int nCustomer = 1; nCustomer< 5; nCustomer ++)/ / outer

为客户循环

{

for(int ntransaction = 0; ntransaction< 4;

ntransaction ++)//金额的内部循环

{

System.out.print(请为客户输入金额)

+ title [ntransaction]

+" =");

//只使用一个两个昏暗的阵列

customerArray [nCustomer] [ntransaction] = easyIn.nextInt();

}

}

//

//用户菜单

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("");

//

//循环和处理直到完成

while(!done){

getTransactionOption();

}

}


public static void getTransactionOption()

{

System.out.print("请从上面的菜单中选择一个选项

(A,B ,C,D,E对于X)=");

String schoice = easyIn.next();

//

/ /检查有效

if(validTransactionOptions.indexOf(schoice)> -1)

{

if(schoice.equals(") X")|| schoice.equals(" x"))

done = true;

else

{

System.ou t.print(请选择一位客户。 (1,2,3或4)=");

getDisplayInformation(schoice,easyIn.nextInt());

}

}

else

{

System.out.println(错误:选择了无效选项);

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;

其他如果(schoi ce.equals(F)|| schoice.equals(" f"))

typeTransaction = 5;

else

{

系统。 out.println(" Error:Bad Transaction Type");

return;

}

System.out.println();

System.out.println(" Customer" + customer +"

选择的选项''"

+ schoice +的信息"''是:" +

customerArray [customer] [typeTransaction]);

System.out.println();

}

}

在此先感谢...

IchBin,Pocono Lake,Pa,USA
http://weconsultants.servebeer.com/JHackerAppManager

__________________________________________________ ________________________

''如果有的话,知识是青春之泉''

-William E. Taylor,Regular Guy(1952 - )


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

解决方案

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-)


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.


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-)


这篇关于Java Gurus帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆