有人可以帮我编写我的java程序吗? [英] Can someone help me code my java program?

查看:54
本文介绍了有人可以帮我编写我的java程序吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的任务:从程序#1开始使用SavingsAccount类。首先,按如下方式更新类本身。构造函数需要接受三个参数:帐号,起始余额和利率。使用这三个值初始化三个实例变量。



现在,其余的更新将在main方法中进行(在MainClass中)。当然,您需要以不同方式实例化对象,传递构造函数所需的三个值。传递您想要的任何帐号。对于余额,传递4000.00美元,并且费率通过0.4%(百分之四十,代表每月利率。)



当程序启动时,假设客户刚进入机构做生意。像以前一样问候客户,询问他们的名字,并在对话的其余部分使用它。接下来,向客户显示帐户的当前状态,即初始化的所有内容。然后,允许客户进行一次存款和/或一次提款。您需要允许他们进行存款或取款,或两者兼而有之,但两者都不需要。换句话说,询问他们是否想要存款,如果他们这样做,那么接受这笔钱。然后,询问他们是否想要退出,如果是,请完成。在这次访问期间,只允许其中一种交易,但它们需要完全相互独立。



注意:这些交易需要编程作为应用程序的一部分,即main方法内部,以及MainClass中可能的静态方法,未包含在SavingsAccount类中。换句话说,与客户的接口不是您通常写入管理帐户的类的内容,因为它可能会在添加或修改功能时经常更改。接口最终可能成为单独的接口类的一部分,但不包含在维护帐户本身的类中。该类代表储蓄账户,储蓄账户对象通常无法与客户进行对话



在这两笔潜在交易之后,存款和取款,显示帐户的最终状态。然后,显示一个12个月的帐户摘要,显示当前利率对余额增长的影响。假设利息每月一次作为简单利息应用。 (每月汇总算法可以设计到main方法本身,或者MainClass中的静态方法,甚至可以设置在SavingsAccount类中的新方法中。您可以自行决定。)



例如,假设在客户的存款/取款操作后,起始余额为$ 4350.00。桌子开始看起来像这样:



月份开始兴趣结束

#平衡收入余额

1 43​​50.00 17.40 4367.40

2 4367.40 17.47 4384.87

3 ...... ......



只需按月数1 - 12.第一个月的起始余额应该是客户添加或撤回资金(或两者)后的最终值。尽可能多地使用对象的方法。 (提示:不要在实际账户中存储期末余额,除非您希望银行破产!在您的MainClass中使用数学计算它。)注意:它应该不言而喻,但只是为了确保,这里go:这个12个月的表必须使用循环结构来生成结果。将不接受一系列12个独立的作业/输出!



确保所有美元数字都以标准商业格式显示,即带有两位小数。从现在开始这将是必要的!



我尝试过:



这是我的计划1,计划2是它的延续。



主类:

公共类MainClass {



public static void main(String [] args)

{

//设置客户输入

扫描仪输入=新扫描仪(System.in);



//设置储蓄帐户类的路径

public MainClass (双d){

SavingsAccount myAccount = new SavingsAccount(Z1234A,2000.0,.013);



//设置一些变量

字符串userName;

双重存款;

双倍取款;

字符串accountNumber;

双倍金额;





//问候并获取客户名称

System.out.println( );

System.out.println(欢迎来自loanSharks储蓄);

System.out.println(可以我们得到你的名字请);

userName = input.nextLine(); //获取客户名称

System.out.println(Hello+ userName);



System.out.println();

System.out.println();



//获取并设置帐号

System.out.println(输入您的帐号);

accountNumber = input.nextLine() ; //客户输入帐号

myAccount.setAccountNumber(accountNumber); //在SavingsAccount类中设置帐号



System.out。 println();

System.out.println();



//开立存款并设定余额

System.out.println(客户名称:+ userName);

System.out.println(帐号:+ accountNumber);

系统。 out.println(输入开始账户金额:);



金额= input.nextDouble(); //客户输入金额

deposit = amount; //定义存款金额t $ / $
myAccount.addToAccount(金额); //通过addToAccount向SavingsAccount.java发送金额



System.out.println();

System.out.println();



//处理提款和更新余额

System.out .println(客户名称:+ userName);

System.out.println(帐号:+ accountNumber);

System.out.println(输入您要提取的金额:);



金额= input.nextDouble(); //提取金额

withdraw =金额; //定义提款金额

myAccount.subtractFromAccount(金额); //适用于SavingsAccount类的余额和余额更新通过subtractFromAccount



System.out.println();

System.out.println();



//计算利息

myAccount.addInterest();





//关闭客户会话并布置帐户活动

System.ou t.println();

System.out.println(谢谢+用户名);

System.out.println(帐号:+ myAccount。 getAccountNumber());

System.out.println(存入:$+存款);

System.out.println(你撤回:$+退出);

System.out.println(感兴趣的收入:$+ myAccount.getRate()* myAccount.getBalance());

System.out.println (账户余额:$+ myAccount.getBalance()); //来自SavingsAccount类的最终余额



System.out.println();

System.out.println();



System.out.println(再见!);



input.close();

}





} // END MainClass



SavingsAccount类:



公共类SavingsAccount

{



private String accountNumber;

私人双重余额;

私人双倍汇率;





public SavingsAccount(String acctNo,double startingBalance,double startingRate)

{

balance = startingBalance;

rate = startingRate;

accountNumber = acctNo;

}



公共双getBalance()

{

返还余额;

}

< br $>




public String getAccountNumber()

{

return accountNumber;

}



public void setAccountNumber(String accountNumber)

{

this.accountNum ber = accountNumber;

}



public void addToAccount(双倍金额)

{

余额=余额+金额;

}



public void subtractFromAccount(双倍金额)

{

if(金额< =余额)

{

余额=余额 - 金额;

}

else

{

System.err.println(钱不够,杰克!);

} < br $>
}



public void addInterest()

{

余额=余额+余额* getRate();

}



public double getRate()

{

退货率;

}



public void setRate(double rate){

this.rate =率;

}







} // END类SavingsAccount

Here's my assignment: Start with the SavingsAccount class from Program #1. First, update the class itself as follows. The constructor needs to accept three arguments: the account number, the starting balance, and the interest rate. Use those three values to initialize the three instance variables.

Now, the rest of the updates will take place in the main method (in MainClass). Of course, you will need to instantiate the object differently, passing in the three values required by the constructor. Pass in any account number you want. For the balance, pass in $4000.00, and for the rate pass in 0.4% (four tenths of one percent, representing a monthly interest rate.)

When the program starts, assume that the customer has just entered the institution to do some business. Greet the customer as before, asking for their name, and use it in the rest of the dialog. Next, display to the customer the current state of the account, that is, everything that was initialized. Then, allow the customer to make one deposit and/or one withdrawal. You need to allow them to do either a deposit or a withdrawal, or both, but neither is required. In other words, ask if they want to make a deposit, and if they do, then accept the money. Then, ask if they want to make a withdrawal, and if so, accomplish that. Only one of each type of transaction will be allowed during this one visit, but they need to be completely independent of each other.

Note: these transactions need to be programmed as part of your application, that is, inside the main method, and possibly static methods in MainClass, not incorporated into the SavingsAccount class. In other words, the interface with a customer is not something that you would normally write into the class managing the account, because it may change quite often as features are added or modified. The interface may eventually become part of a separate "interface class", but not included into the class that maintains the account itself. The class represents the savings account, and a savings account object is usually not capable of carrying on a conversation with a customer

After these two potential transactions, the deposit and withdrawal, display the final state of the account. Then, display a 12-month summary of the account that shows the effect of the current interest rate on the growth of the balance. Assume that the interest is applied as simple interest once per month. (The monthly summary algorithm could be designed into the main method itself, or in a static method in MainClass, or even in a new method in the SavingsAccount class. The choice is up to you to decide.)

For example, assume that after the customer’s deposit/withdrawal actions, the starting balance was $4350.00. The table would start out looking something like this:

Month Starting Interest Ending
# Balance Earned Balance
1 4350.00 17.40 4367.40
2 4367.40 17.47 4384.87
3 … … …

Just number the months 1 – 12. The starting balance for the first month should be the final value after the customer either added or withdrew funds (or both). Make use of the object’s methods as much as possible. (Hint: don’t store the "ending balance" in the actual account, unless you want the bank to go bankrupt! Calculate it using math in your MainClass.) NOTE: it should go without saying, but just to make sure, here goes: this 12-month table must use a looping structure to generate its results. A series of 12 independent assignments/outputs will not be accepted!

Make sure that all dollar figures are displayed in standard business format, that is, with two decimals. That will be a necessity from now on!

What I have tried:

This my Program 1, Program 2 is a continuation of it.

Main Class:
public class MainClass {

public static void main(String[] args)
{
//set up customer input
Scanner input = new Scanner(System.in);

//set up path to Savings Account class
public MainClass(double d) {
SavingsAccount myAccount = new SavingsAccount("Z1234A", 2000.0, .013);

//set some variables
String userName;
double deposit;
double withdraw;
String accountNumber;
double amount;


//Greeting and get customer name
System.out.println();
System.out.println("Welcome to loanSharks Savings");
System.out.println("Can we get your name Please");
userName=input.nextLine();//get customer name
System.out.println("Hello " +userName );

System.out.println();
System.out.println();

//get and set account number
System.out.println("Enter your account number");
accountNumber=input.nextLine();//customer input account number
myAccount.setAccountNumber(accountNumber);//set account number in SavingsAccount class

System.out.println();
System.out.println();

//make opening deposit and set balance
System.out.println("Customer name: "+userName);
System.out.println("Account number: "+accountNumber);
System.out.println("Enter the amount to begin account with:");

amount = input.nextDouble();//customer input dollar amount
deposit = amount;//define deposit amount
myAccount.addToAccount(amount);//send amount to SavingsAccount.java via addToAccount

System.out.println();
System.out.println();

//process withdraw and update balance
System.out.println("Customer name: "+userName);
System.out.println("Account number: "+accountNumber);
System.out.println("Enter the amount you wish to withdraw:");

amount = input.nextDouble();//withdraw dollar amount
withdraw = amount;//define withdraw amount
myAccount.subtractFromAccount(amount);//apply to balance in SavingsAccount class and balance update via subtractFromAccount

System.out.println();
System.out.println();

//calculate interest
myAccount.addInterest();


//close customer session and lay out account activity
System.out.println();
System.out.println("Thank You " +userName);
System.out.println("Account number: " +myAccount.getAccountNumber());
System.out.println("You deposited: $"+deposit);
System.out.println("You withdrew: $"+withdraw);
System.out.println("Interested earned: $"+myAccount.getRate()*myAccount.getBalance());
System.out.println("Account balance: $"+myAccount.getBalance());//final balance from SavingsAccount class

System.out.println();
System.out.println();

System.out.println("Bye!");

input.close();
}


}//END MainClass

SavingsAccount Class:

public class SavingsAccount
{

private String accountNumber;
private double balance;
private double rate;


public SavingsAccount(String acctNo, double startingBalance, double startingRate)
{
balance = startingBalance;
rate= startingRate;
accountNumber = acctNo;
}

public double getBalance()
{
return balance;
}



public String getAccountNumber()
{
return accountNumber;
}

public void setAccountNumber(String accountNumber)
{
this.accountNumber = accountNumber;
}

public void addToAccount(double amount)
{
balance = balance + amount;
}

public void subtractFromAccount(double amount)
{
if (amount <= balance)
{
balance = balance - amount;
}
else
{
System.err.println("Not enough money, Jack!");
}
}

public void addInterest()
{
balance = balance + balance*getRate();
}

public double getRate()
{
return rate;
}

public void setRate(double rate) {
this.rate = rate;
}



}//END class SavingsAccount

推荐答案

4000.00,和费率通过率为0.4%(百分之四十,表示每月利率。)



当程序启动时,假设客户刚刚进入机构做生意。像以前一样问候客户,询问他们的名字,并在对话的其余部分使用它。接下来,向客户显示帐户的当前状态,即初始化的所有内容。然后,允许客户进行一次存款和/或一次提款。您需要允许他们进行存款或取款,或两者兼而有之,但两者都不需要。换句话说,询问他们是否想要存款,如果他们这样做,那么接受这笔钱。然后,询问他们是否想要退出,如果是,请完成。在这次访问期间,只允许其中一种交易,但它们需要完全相互独立。



注意:这些交易需要编程作为应用程序的一部分,即main方法内部,以及MainClass中可能的静态方法,未包含在SavingsAccount类中。换句话说,与客户的接口不是您通常写入管理帐户的类的内容,因为它可能会在添加或修改功能时经常更改。接口最终可能成为单独的接口类的一部分,但不包含在维护帐户本身的类中。该类代表储蓄账户,储蓄账户对象通常无法与客户进行对话



在这两笔潜在交易之后,存款和取款,显示帐户的最终状态。然后,显示一个12个月的帐户摘要,显示当前利率对余额增长的影响。假设利息每月一次作为简单利息应用。 (每月汇总算法可以设计到main方法本身,或者MainClass中的静态方法,甚至可以设置在SavingsAccount类中的新方法中。您可以自行决定。)



例如,假设在客户的存款/取款操作之后,起始余额为
4000.00, and for the rate pass in 0.4% (four tenths of one percent, representing a monthly interest rate.)

When the program starts, assume that the customer has just entered the institution to do some business. Greet the customer as before, asking for their name, and use it in the rest of the dialog. Next, display to the customer the current state of the account, that is, everything that was initialized. Then, allow the customer to make one deposit and/or one withdrawal. You need to allow them to do either a deposit or a withdrawal, or both, but neither is required. In other words, ask if they want to make a deposit, and if they do, then accept the money. Then, ask if they want to make a withdrawal, and if so, accomplish that. Only one of each type of transaction will be allowed during this one visit, but they need to be completely independent of each other.

Note: these transactions need to be programmed as part of your application, that is, inside the main method, and possibly static methods in MainClass, not incorporated into the SavingsAccount class. In other words, the interface with a customer is not something that you would normally write into the class managing the account, because it may change quite often as features are added or modified. The interface may eventually become part of a separate "interface class", but not included into the class that maintains the account itself. The class represents the savings account, and a savings account object is usually not capable of carrying on a conversation with a customer

After these two potential transactions, the deposit and withdrawal, display the final state of the account. Then, display a 12-month summary of the account that shows the effect of the current interest rate on the growth of the balance. Assume that the interest is applied as simple interest once per month. (The monthly summary algorithm could be designed into the main method itself, or in a static method in MainClass, or even in a new method in the SavingsAccount class. The choice is up to you to decide.)

For example, assume that after the customer’s deposit/withdrawal actions, the starting balance was


4350.00。桌子开始看起来像这样:



月份开始兴趣结束

#平衡收入余额

1 43​​50.00 17.40 4367.40

2 4367.40 17.47 4384.87

3 ...... ......



只需按月数1 - 12.第一个月的起始余额应该是客户添加或撤回资金(或两者)后的最终值。尽可能多地使用对象的方法。 (提示:不要在实际账户中存储期末余额,除非您希望银行破产!在您的MainClass中使用数学计算它。)注意:它应该不言而喻,但只是为了确保,这里go:这个12个月的表必须使用循环结构来生成结果。将不接受一系列12个独立的作业/输出!



确保所有美元数字都以标准商业格式显示,即带有两位小数。从现在开始这将是必要的!



我尝试过:



这是我的计划1,计划2是它的延续。



主类:

公共类MainClass {



public static void main(String [] args)

{

//设置客户输入

扫描仪输入=新扫描仪(System.in);



//设置储蓄帐户类的路径

public MainClass (双d){

SavingsAccount myAccount = new SavingsAccount(Z1234A,2000.0,.013);



//设置一些变量

字符串userName;

双重存款;

双倍取款;

字符串accountNumber;

双倍金额;





//问候并获取客户名称

System.out.println( );

System.out.println(欢迎来自loanSharks储蓄);

System.out.println(可以我们得到你的名字请);

userName = input.nextLine(); //获取客户名称

System.out.println(Hello+ userName);



System.out.println();

System.out.println();



//获取并设置帐号

System.out.println(输入您的帐号);

accountNumber = input.nextLine() ; //客户输入帐号

myAccount.setAccountNumber(accountNumber); //在SavingsAccount类中设置帐号



System.out。 println();

System.out.println();



//开立存款并设定余额

System.out.println(客户名称:+ userName);

System.out.println(帐号:+ accountNumber);

系统。 out.println(输入开始账户金额:);



金额= input.nextDouble(); //客户输入金额

deposit = amount; //定义存款金额t $ / $
myAccount.addToAccount(金额); //通过addToAccount向SavingsAccount.java发送金额



System.out.println();

System.out.println();



//处理提款和更新余额

System.out .println(客户名称:+ userName);

System.out.println(帐号:+ accountNumber);

System.out.println(输入您要提取的金额:);



金额= input.nextDouble(); //提取金额

withdraw =金额; //定义提款金额

myAccount.subtractFromAccount(金额); //适用于SavingsAccount类的余额和余额更新通过subtractFromAccount



System.out.println();

System.out.println();



//计算利息

myAccount.addInterest();





//关闭客户会话并布置帐户活动

System.ou t.println();

System.out.println(谢谢+用户名);

System.out.println(帐号:+ myAccount。 getAccountNumber());

System.out.println(你存入:
4350.00. The table would start out looking something like this:

Month Starting Interest Ending
# Balance Earned Balance
1 4350.00 17.40 4367.40
2 4367.40 17.47 4384.87
3 … … …

Just number the months 1 – 12. The starting balance for the first month should be the final value after the customer either added or withdrew funds (or both). Make use of the object’s methods as much as possible. (Hint: don’t store the "ending balance" in the actual account, unless you want the bank to go bankrupt! Calculate it using math in your MainClass.) NOTE: it should go without saying, but just to make sure, here goes: this 12-month table must use a looping structure to generate its results. A series of 12 independent assignments/outputs will not be accepted!

Make sure that all dollar figures are displayed in standard business format, that is, with two decimals. That will be a necessity from now on!

What I have tried:

This my Program 1, Program 2 is a continuation of it.

Main Class:
public class MainClass {

public static void main(String[] args)
{
//set up customer input
Scanner input = new Scanner(System.in);

//set up path to Savings Account class
public MainClass(double d) {
SavingsAccount myAccount = new SavingsAccount("Z1234A", 2000.0, .013);

//set some variables
String userName;
double deposit;
double withdraw;
String accountNumber;
double amount;


//Greeting and get customer name
System.out.println();
System.out.println("Welcome to loanSharks Savings");
System.out.println("Can we get your name Please");
userName=input.nextLine();//get customer name
System.out.println("Hello " +userName );

System.out.println();
System.out.println();

//get and set account number
System.out.println("Enter your account number");
accountNumber=input.nextLine();//customer input account number
myAccount.setAccountNumber(accountNumber);//set account number in SavingsAccount class

System.out.println();
System.out.println();

//make opening deposit and set balance
System.out.println("Customer name: "+userName);
System.out.println("Account number: "+accountNumber);
System.out.println("Enter the amount to begin account with:");

amount = input.nextDouble();//customer input dollar amount
deposit = amount;//define deposit amount
myAccount.addToAccount(amount);//send amount to SavingsAccount.java via addToAccount

System.out.println();
System.out.println();

//process withdraw and update balance
System.out.println("Customer name: "+userName);
System.out.println("Account number: "+accountNumber);
System.out.println("Enter the amount you wish to withdraw:");

amount = input.nextDouble();//withdraw dollar amount
withdraw = amount;//define withdraw amount
myAccount.subtractFromAccount(amount);//apply to balance in SavingsAccount class and balance update via subtractFromAccount

System.out.println();
System.out.println();

//calculate interest
myAccount.addInterest();


//close customer session and lay out account activity
System.out.println();
System.out.println("Thank You " +userName);
System.out.println("Account number: " +myAccount.getAccountNumber());
System.out.println("You deposited:


+存款);

System.out .println(你退出:
"+deposit);
System.out.println("You withdrew:


这篇关于有人可以帮我编写我的java程序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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