FAQ: Learn Java: Manipulating Variables - Review

This community-built FAQ covers the “Review” exercise from the lesson “Learn Java: Manipulating Variables”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn Java

FAQs on the exercise Review

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

For the love of God, fix question 4.

6 Likes

I had the same problem. It says “expected to see A” printed and it actually did but I didn’t pass that question. Why?

did you remember to add the “…” on the end of the line?

1 Like

I tried that too and it doesn’t work.

Alright I’m in the dark here, why is the +"…" on the end even a requirement?

1 Like

Welcome to the forums!

The instructions state that the output should be as follows.

I gave each friend <amountForEachFriend>...

... is at the end of this and therefore we must concatenate ... to our string.

I was curious if the following would be a better way to write this code? Is it a better practice to always have a changeable variable that you use in calculations rather than using specific numbers?

public class BankAccount {
public static void main(String args){
/integer data/
double balance = 1000.75;
double amountToWithdraw = 250;
double priceOfTicket = 250;
double numberOfFriends = 3;
/calculations/
double updatedBalance = balance - amountToWithdraw;
double amountForEachFriend = updatedBalance / numberOfFriends;
boolean canPurchaseTicket = amountForEachFriend >= priceOfTicket;
String gaveStatement = “I gave each friend” + " " + amountForEachFriend + “…”;
/prints/
System.out.println(canPurchaseTicket);
System.out.println(gaveStatement);
}
}

I have same problem with the Q4, I tried all possible way , but still couldn’t pass this question.

I tried so many ways to fix this question 4 . Here is the correct print statement that works fine to me .

System.out.println("I gave each friend " + " " + amountForEachFriend + “…”);

Yeah, this is not working.

This input created passed output for me:

System.out.println("I gave each friend " + amountForEachFriend + “…”);

My input has

trueI gave each friend 250.25…

How do I remove the true its not in my print statement ?
please help
!

Step 3 specifies:

Then, use System.out.println() to print canPurchaseTicket.

If you wrote the statement,

System.out.println(canPurchaseTicket);

for Step 3, then that is why true is being printed because canPurchaseTicket holds a boolean value.

Step 4 has a separate print statement.

yes and it did not work

At the bottom of the exercise, there should be a “Copy to Clipboard” button. Click it to copy your code. To paste your code in the forums with proper formatting, see: [How to] Format code in posts

Perhaps it will reveal clues as to why your attempted solution isn’t working.

public class BankAccount {
public static void main(String args){
double balance = 1000.75;
double amountToWithdraw = 250;

  double updatedBalance = balance - amountToWithdraw;

  double amountForEachFriend = updatedBalance / 3;

  boolean canPurchaseTicket = amountForEachFriend >= 50;

  System.out.println(canPurchaseTicket);

  System.out.println("I gave each friend " + " " + amountForEachFriend + "...");

  

}       

}

Since you have already added a space after the word friend, there is no need for an extra space " "

// You wrote:
System.out.println("I gave each friend " + " " + amountForEachFriend + "...");

// It should be:
System.out.println("I gave each friend " + amountForEachFriend + "...");

Also,

// You wrote:
boolean canPurchaseTicket = amountForEachFriend >= 50

// It should be:
boolean canPurchaseTicket = amountForEachFriend >= 250