Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 months ago.
Improve this question
I'm learning java now, sorry if you didn't get it.
Here is the "money transfer" method, it works with constructor in other class.
The code does not end by itself, it constantly returns.
I need to save these parameters (username, transfer amount) and execute this later.
public static String moneyTransfer() {
System.out.println("Enter the name to whom you want to transfer funds");
String nametransfer = scanner.nextLine();
String nametransf = scanner.nextLine();
System.out.println("Enter the amount to transfer to the user " + nametransfer);
int transfermoney = scanner.nextInt();
Moneytransfer moneytr = new Moneytransfer(nametransf, transfermoney);
int resulttransfer = balance-transfermoney;
System.out.println("You transferred "+transfermoney+" to user: "+nametransf);
System.out.println("balance: "+resulttransfer);
return startPanel();
}
idk(
You can store them with a List in package java.util.
As you are new to programming, you might not understand what I am talking about. Just keep learning and you will realise.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I would like to put the following to a for loop. How do I do this since we haven't studied arrays yet. My instructor would like me to put the quarters 1-4 to a for loop.
quarter = 1;
interest = principal * quarterlyRate; // item 5
finalAmount = principal + interest;
System.out.printf("%6s%8d%16.2f%30.2f%n", year, quarter, interest, finalAmount);```
Maybe this is what you want:
# looping here
for (int i=0; i<4; i++) {
interest = principal * quarterlyRate; // item 5
finalAmount = principal + interest;
System.out.printf("%6s%8d%16.2f%30.2f%n", year, i, interest, finalAmount);```
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I am trying to convert the following Java code into swift, but I do not know about this data structure new (int start, int end)[input. length], any guidance would be appraciated.
public override void collection_entries(int[] input)
{
var ranges = new (int start, int end)[input.length];
}
In swift, you should use a Range().
let start = 0
let end = 6
var ranges = Range(start...end)[input.count]
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
I need some guidance as how can I optimize the below code. As one can see , i am creating a new object everytime to set each value. How can I do it in a better way
Balance[] balance = new Balance[3];
CurAmt curAmt = new CurAmt();
Balance bal = new Balance();
bal.setBalType("currentBalance");
curAmt.setCurCode(entry.getValue().get(0).getAs("CURRENT_BALANCE_CURRENCY_CODE"));
curAmt.setContent(entry.getValue().get(0).getAs("CURRENT_BALANCE"));
bal.setCurAmt(curAmt);
balance[0] = bal;
CurAmt curAmt1 = new CurAmt();
Balance bal1 = new Balance();
bal1.setBalType("availableBalance");
curAmt1.setCurCode(entry.getValue().get(0).getAs("AVAILABLE_BALANCE_CURRENCY_CODE"));
curAmt1.setContent(entry.getValue().get(0).getAs("AVAILABLE_BALANCE"));
bal1.setCurAmt(curAmt1);
balance[1] = bal1;
CurAmt curAmt2 = new CurAmt();
Balance bal2 = new Balance();
bal2.setBalType("interestEarnedYtd");
curAmt2.setCurCode(entry.getValue().get(0).getAs("YTD_CURRENCY_CODE"));
curAmt2.setContent(entry.getValue().get(0).getAs("TD_AMOUNT"));
bal2.setCurAmt(curAmt2);
balance[2] = bal2;
Obj.setBalance(balance);
If you are talking about code performance, I can only see one optimization. You evaluate this 6 times, and the JIT compiler probably can't optimize it:
entry.getValue().get(0)
Do it once and assign the value to a temporary variable. (It is unclear if this will make a significant difference. And you were just doing this for performance reasons, you would be advised to profile your application first. There is no point in optimizing application code that is not a performance hotspot.)
If you are talking about programmer efficiency (i.e. code readability) I can see a block of code that is repeated 3 times with different parameters. You can turn it into a method; e.g.
private Balance createBalance(Value v, String type, String currency, String balance) {
CurAmt curAmt = new CurAmt();
Balance bal = new Balance();
bal.setBalType(type);
curAmt.setCurCode(value.getAs(currency));
curAmt.setContent(value.getAs(ballance));
bal.setCurAmt(curAmt);
return bal;
}
then call it with the appropriate parameters.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need to write an if statement where I return the string "Close String" when int d is within 10% of int e. This is what I have now:
public String game(double d, double e) {
if((d>=.95*e)||(d<=e*1.05)) {
return "close string";
} else {
return "other";
}
}
TEST CASE
String game = game(100.0d, 90.0d);
System.out.println(game);
game = game(100.0d, 99.0d);
System.out.println(game);
game = game(100.0d, 100.0d);
System.out.println(game);
EXPECTED OUTPUT
other
close string
close string
CURRENT OUTPUT
close string
close string
close string
Where is the mistake?
I'm not sure exactly what you're asking, but I think you want and instead of or.
(a>=.95*b)||(a<=b*1.05)
a can then be any number, because it will be less than 5% above b, or 5% below b as long as it is a real number.
(a>=.95*b)&&(a<=b*1.05)
a can only be within + or - 5%
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
public static int secret(int value) {
int prod = 1;
for(int i =1; i <= 3; i++) {
prod = prod * value;
}
return prod;
}
What would be the output of:
System.out.println("First secret call: " + secret(5));
System.out.println("Second secret call: " + (2 * secret(6)));
and what does the method secret do
The output would be 125 and then 432. The method, "secret", cubes the number passed into it.
everything fits in a very small screenshot in two windows... try it, you will see it is fun, like playing lego but with more magic!!!