zeroliken 79 Nearly a Posting Virtuoso

Good for you

zeroliken 79 Nearly a Posting Virtuoso

Third mistake in a row tsktsk I must be losing it

payement+=payement

that should do it

zeroliken 79 Nearly a Posting Virtuoso

sorry just change the pay to payement in the println

Never had so many mistakes in my posts like this :(

zeroliken 79 Nearly a Posting Virtuoso

ehem..anyway just store the value in a separate variable

int payement = pay;    
System.out.println ("Month: "+ month + " Balance: " + nbalance + " Total Payments: " + pay);
    while(nbalance>1.00){
    double value = nbalance * .015;
    payement+=100;
    nbalance = (value+nbalance) - pay;
    System.out.println ("Month: "+ month + " Balance: " + nbalance + " Total Payments: " + pay);
    month++;
    }
zeroliken 79 Nearly a Posting Virtuoso

Haha, if you scroll down a bit, in the inital post, it says:

"Say that you owe the credit card company $1000.00. The company charges you 1.5% per month on the unpaid balance. You have decided to stop using the card and to pay off the debt by making a monthly payment of N dollars a month. Write a program that asks for the monthy payment, then writes out the balance and total payments so far for every succeeding month until the balance is zero or less.

For each month, calculate the interest due on the unpaid balance. Then calculate the new balance by adding the interest and subtracting the payment."

Then the fool here is me I should have initially and repeatedly told you to have a working solution before coding

I got too obsessed answering your every problem.. sorry

zeroliken 79 Nearly a Posting Virtuoso

you only posted the output you want
not the real program description

zeroliken 79 Nearly a Posting Virtuoso

My final advice my friend is to know the algorithm before coding

zeroliken 79 Nearly a Posting Virtuoso

Oh, okay, but we still had to move month++ before the second println for it to work. Thanks! One more thing, if I were to change the user input to 500, instead of 100, then it wouldn't work. I believe this is because we put 100 everywhere...

Hahaha:D:D:D:D:D:D:D:D:D
you make me laugh!!!
of course it will not give the same result like 100 that's why I'm telling you to have a solution by hand before trying to code it... It's like you just want to have the same output as stated but you did not mention how your program really works like when the user wants to have another input...

Most of the given in the code is predefined

Now all our coding could be just a waste

zeroliken 79 Nearly a Posting Virtuoso

Did you just made the code so that you can make an exact replica of the output?
Cause I was thinking you were trying to make a bank or investment like program :-O

zeroliken 79 Nearly a Posting Virtuoso

Ok, this gets the -8.37, but skips the first output line. The output resides to:


Month: 1 Balance: 828.725 Total Payments: 100.0
Month: 2 Balance: 741.155875 Total Payments: 200.0
Month: 3 Balance: 652.273213125 Total Payments: 300.0
Month: 4 Balance: 562.057311321875 Total Payments: 400.0
Month: 5 Balance: 470.4881709917031 Total Payments: 500.0
Month: 6 Balance: 377.54549355657866 Total Payments: 600.0
Month: 7 Balance: 283.20867595992735 Total Payments: 700.0
Month: 8 Balance: 187.4568060993263 Total Payments: 800.0
Month: 9 Balance: 90.26865819081618 Total Payments: 900.0
Month: 10 Balance: -8.377311936321576 Total Payments: 1000.0

already edited my previous post

zeroliken 79 Nearly a Posting Virtuoso
System.out.println ("Month: "+ month + " Balance: " + nbalance + " Total Payments: " + pay);
   while(nbalance>1.00){
    double value = nbalance * .015;
    pay+=100;
    nbalance = (value+nbalance) -100;
    System.out.println ("Month: "+ month + " Balance: " + nbalance + " Total Payments: " + pay); 
     month++;
    }
zeroliken 79 Nearly a Posting Virtuoso

you should have used your previous thread instead of creating a new one

zeroliken 79 Nearly a Posting Virtuoso

then subtract it by 100

nbalance = (nbalance * interest) + nbalance - 100;

though it defeats the purpose of using pay in your operation...
but hey as long as you get your desired output you should be happy

zeroliken 79 Nearly a Posting Virtuoso

then try to find the specific part of the code that gives the unwanted result
maybe print each array index one by one

zeroliken 79 Nearly a Posting Virtuoso

The solution, as in how the output is supposed to be?


Enter the monthly payment: 100
Month: 1 balance: 915.0 total payments: 100.0
Month: 2 balance: 828.73 total payments: 200.0
Month: 3 balance: 741.16 total payments: 300.0
Month: 4 balance: 652.27 total payments: 400.0
Month: 5 balance: 562.06 total payments: 500.0
Month: 6 balance: 470.49 total payments: 600.0
Month: 7 balance: 377.54 total payments: 700.0
Month: 8 balance: 283.21 total payments: 800.0
Month: 9 balance: 187.46 total payments: 900.0
Month: 10 balance: 90.27 total payments: 1000.0
Month: 11 balance: -8.38 total payments: 1100.0

What I meant to say is the solution on how did 915 become 828 then 741 then 652 and so on cause as you can see your current operation cannot do this

If you don't know the solution by hand then try not to code it yet

zeroliken 79 Nearly a Posting Virtuoso

can you post the operation to get the output...not the code but the solution
cause It's hard for me to guess on my side

zeroliken 79 Nearly a Posting Virtuoso

You still don't get it do you
915*.015 will be equal to....
Then add the value to nbalance

Don't just save the value to nbalance

zeroliken 79 Nearly a Posting Virtuoso

the problem is not the while loop itself but rather the operation of the doubles inside the loop

zeroliken 79 Nearly a Posting Virtuoso
nbalance = (nbalance * interest) - pay;

after this operation nbalance becomes less than 1

zeroliken 79 Nearly a Posting Virtuoso

try this

while(nbalance>1 || nbalance==1)
zeroliken 79 Nearly a Posting Virtuoso
while (nbalance>=1) {
  System.out.println ("Month: "+ month +   " Balance: " + nbalance +     " Total Payments: " + pay);
  month++;
  nbalance = (nbalance * interest) - pay;
  nbalance--;
  pay = pay+100;
  }

why should it have nbalance--?
also change the position of pay and nbalance operation

zeroliken 79 Nearly a Posting Virtuoso

Ok, changed it to that, and also back to the while loop. So now it looks like this:

import java.util.Scanner;

class CreditCardBill{
public static void main (String[] args){
  Scanner input = new Scanner(System.in);
  int month = 1;
  System.out.println ("Enter the monthly payment: ");
  double pay = input.nextInt();
  double left = 1000;
  double interest = 0.015;
  double balance = (left * interest) + left; 
  double nbalance = (balance - pay);
  while (nbalance>=1) {
  System.out.println ("Month: "+ month +   " Balance: " + nbalance +     " Total Payments: " + pay);
  month++;
  nbalance = (nbalance * interest) - pay;
  nbalance--;
  pay = pay+100;
  }
}
}

So does it still have an error?

zeroliken 79 Nearly a Posting Virtuoso

I wasn't sure how to change the while loop, and the for loop made a little more sense to me.

well suit yourself
nbalance-- subracts itself by 1 which makes the output wrong

Trust me its better to use a while loop

zeroliken 79 Nearly a Posting Virtuoso
nbalance = (nbalance * interest) - 100;

if pay is user input then subtract pay to it

zeroliken 79 Nearly a Posting Virtuoso

If you read my one of my previous post I told you that use the previous while loop in your code.. there's no need for a for loop or do want to make it complicated?

zeroliken 79 Nearly a Posting Virtuoso

in your code your multiplying it to balance and not to nbalance directly...

try to change your operations that is suited for the program

can you post your current code

zeroliken 79 Nearly a Posting Virtuoso

Try to trace your program and see the logic... your almost done

zeroliken 79 Nearly a Posting Virtuoso

pay++ only adds 1 to your previous amount e.g 100...101...102

zeroliken 79 Nearly a Posting Virtuoso

you don't need to change it to a for loop just add the previous operations on your while loop, make a few adjustments then you should be done

zeroliken 79 Nearly a Posting Virtuoso

Okay I can see the whole picture now...

Include some of your previous operations on the loop and you should be done ;)

zeroliken 79 Nearly a Posting Virtuoso

Yes, but when that break is removed, it becomes an infinite loop. The months accumulate, the nbalance and pay don't change at all, instead just keep repeating itself.

I edited my previous post and stated that you should have included your previous operation on the loop that will deduct nbalance to make it less than 1 to stop the loop

zeroliken 79 Nearly a Posting Virtuoso

whoops sorry missed that... should have noted that you are using a break ... to stop the loop
instead you should have the previous operations on the loop that will deduct the money(to make nbalance less than 1)

zeroliken 79 Nearly a Posting Virtuoso

Of course it will only print out that line...
you don't have a loop

zeroliken 79 Nearly a Posting Virtuoso

then why not convert it say 1.5 percent will become .015 then add it or do any operation with it

zeroliken 79 Nearly a Posting Virtuoso

If the output should be a double then why not declare balance and nbalance as a double?
and why not declare left as a double too?

and if you want left to be int then just convert it double then

zeroliken 79 Nearly a Posting Virtuoso

A way to convert from double to int is to use Double.intValue()

zeroliken 79 Nearly a Posting Virtuoso

I hope you understand me. Otherwise I will try to make it clearer. Thanks

What you forgot to mention is in what way should we help you

zeroliken 79 Nearly a Posting Virtuoso

@stultuske and fakerz

he needs the name of the city with the most characters in uppercase letters and I don't think using length() alone is enough... well in the codes you presented anyway

zeroliken 79 Nearly a Posting Virtuoso

just wondering, do i still need the formula outside the print line as well. Considering its supposed to be a "encryption" i dont think it makes sense to print the converstion.

If you mean that you want to use the letters or string again then just store the converted letters in an array while in the for loop so you can use it again

If not then I don't know want you want here

zeroliken 79 Nearly a Posting Virtuoso

to show the user the conversion...
Is there a reason for it not to be in the print line?

zeroliken 79 Nearly a Posting Virtuoso

You don't have a process where you save a new value for maxlength

in your case maxlength should have a value equal to the current city name that has the most uppercase letters

Since the last city name has a length greater than 0 it will output the last city name

zeroliken 79 Nearly a Posting Virtuoso

I really hope you learned something here :idea:

zeroliken 79 Nearly a Posting Virtuoso

I gave a pseudo a while ago
if you don't know about booleans then you can learn it using google then implement it on your code

zeroliken 79 Nearly a Posting Virtuoso

a boolean is set to either true or false
Once the number of bounces have been met then change the value of the boolean to stop the loop

pseudo:

boolean value = false;

current bounce = 0;

do{

if(current bounce == number of bounce user wants) value = true;
else current bounce is added by 1;
 //you can put the iterator outside of if else statement but position will depend if your using do while loop or while loop

}while(value = false);

Do I need to post this again?

zeroliken 79 Nearly a Posting Virtuoso

I just said that you should use the number of bounces as a requirement for stopping the loop

(said that in 3 posts plus this already)

use a boolean like statement

zeroliken 79 Nearly a Posting Virtuoso

but i also want my program to print "bounce".depends on nos of time user want.

I'm not contradicting you I said the loop should stop once the required number of bounces is met, meaning you can still print "bounce" and will only not print anymore once the condition is met... you can still have the else statement I only said not to use break;

zeroliken 79 Nearly a Posting Virtuoso

Thats because you put in a break statement to stop the whole do while loop
Use a different approach in stopping the loop like a boolean

For example the loop will stop once it reaches the required amount of bounces

zeroliken 79 Nearly a Posting Virtuoso

you have no operation on calculating current and power... is that what you want to do next?

zeroliken 79 Nearly a Posting Virtuoso

So whats the problem with the bounces can you specify your desired output?

also you should have used your previous thread instead of creating a new one

zeroliken 79 Nearly a Posting Virtuoso

I already showed the right way of printing it out in my first post

System.out.println("There are " + count + " student(s) in the class");
System.out.println("The total of their scores = " + total + "points");