Hi Everyone,

I have a fairly simple (atleast it seems to be one) assignment loop program to create. But, unfortuntely having trouble getting started because I took a break from Java and now that I have decided to pick up with it again I feel like I've forgot everything. So could someone please help me a little of breaking down this problem.

Program:

Financial application: computing future tuition) Suppose that the tuition for a university is $ 10,000 this year and increases 5% every year. Write a program that uses a loop to compute the tuition in ten years. Write another program that computes the total cost of four years worth of tuition starting ten years from now.

What is the basic set up?
Thank you in advance

Recommended Answers

All 21 Replies

What is the basic set up?

You design and write the code and come here when you have problems.
First figure out the algorithm for computing the total cost.
Then try to match some java code to that algorithm.

Thank you, but i'm a bit confused on whether I'm writing one program or two? like one for 10 years and then another one for 4years after that?

Yes I have figured out the computation for the algorithm:

(tuition * .05) + tuition

($10,000 * .05) + $10,000

and the loop would go on until the year is not 10, right?

But, I dont see how I would do the 4yrs after that? in the same program or a different one? Do you see where I'm confused?

The assignment says 2 programs.

how I would do the 4yrs after that

Start at the 11th year sum up the amounts for 4 years

Ok so for the first program this is what I have started out like:

import javax.swing.JOptionPane;

public class tuition
{
	public static void main (String[] args)
	{

		double tuition = (10000.00);
		int year = 1;

		for (int i = 1; i <= 10; i++)
		{
			tuition = ((tuition * .05) + tuition);

		}

		System.out.println (tuition);


	}
}

The problem I see with this is that it outputs with a trail of decimal places.
Do you see any other? Is this even right, because it looks too simple to be right.
What do I need to do after this?

it outputs with a trail of decimal places

I don't see where you posted the output.

To format the output, see the DecimalFormat class.

I've never used that format before, so not aware of how to do so, and I just googled for examples and applied it to my program..it didnt work -- giving syntax errors.


This is what the output is:
16288.946267774414

giving syntax errors

Please post full text of the error messages here.

Actually I think I fixed the decimal problem by making the output statement like this:

System.out.printf ("%.2f",tuition);

so now it outputs:
16288.95

is that right?

is that right?

Beats me. Not sure what you are asking.

Hi

so now it outputs:
16288.95

I suppose that this value is for 11 year

Yet I suppose that your poste need some explanation before starting the discution:

Suppose that the tuition for a university is $ 10,000 this year and increases 5% every year

Is the 5% based on 10 000 $ or it is based on the fee of the precedent year?

1- First case: The Adjutant is base 10 000.00 $
every year the charge is incremented by the constant 10000*5/100 = 500$

Year 1 ...................... feeYearOne= 10 000
Year 2 ...................... feeYearTwo=feaYearOne+feaYearOne*5/100=feaYearOne*(1+5/100)
Year 3 ...................... feeYearTree=feeYearTwo+feaYearOne*5/100=feeYearOne*(1+ 5/100) + feeYearOne*5/100
=feeYearOne*((1+5/100)+5/100)=feeYearOne*(1+2*5/100)
.
.
.
.
Year 10.................... feeYearTen=feeYearOne*(1+9*5/100)
Note that 9=10 -1
You can recognize that for year N the fee will be:
feeYearN = feeYearOne*(1+(N-1)*5/100)


2- second case: The Adjutant is based in the fee of precedent year:
Year 1 ...................... feeYearOne= 10 000
Year 2 ...................... feeYearTwo=feaYearOne+feeYearOne*5/100=feeYearOne*(1+5/100)
Year 3 ...................... feeYearTree=feeYearTwo+feeYearTwo*5/100=feeYearTwo*(1+5/100)
=feeYearOne*[(1+5/100)*(1+5/100)]
Year 4....................... feeYearFour=feeYearTree+feeYearTree*5/100
= feeYearOne*[(1+5/100)*[(1+5/100)*(1+5/100)]]
Note that (1+5/100) is multiplided 3 times for the year 4
Note also that 4 = 3-1
.
.
.
.
Year 10.................... feeYearTen=feeYearOne*[(1+5/100)*(1+5/100)*(1+5/100)*......*(1+5/100)] (9 times)

You can recognize that for year N the fee will be:
feeYearN =feeYearOne*(1+5/100)power(N-1)


if you chose the seconde case the loop need to be

for(int i=1; i<10)

Instead

And I suppose that you have to write two programms as the assignement suggest.

Important:
1-the code you wrote calculate the fee for 11 years
2-please make the first letter of the name of your class upcase "Tuition" because it is recommended
3-do not give a variable the name of the class it is confusing rename it

double fee;

instead of

double tuition

Hope it helps

Hi,

Ok yes I understand where I went wrong in the computation but can't i just correct that by this:

import javax.swing.JOptionPane;

public class Tuition
{
	public static void main (String[] args)
	{

		double fee = (10000.00);
		int year = 1;

		for (int i = 1; i <= 9; i++)
		{
			fee = ((fee * .05) + fee);

		}

		System.out.printf("The tuition for 10years is: $" + "%.2f", fee);

	}
}

What is wrong with this? And, how can I fix it? Because, for the first part we are just looking for the tutition in the 10th year, so we don't have to sum them up to 10years.

The second part is which wants the sum of 4years after the 10th year,right? Do I need an array for that, or it can be done without one?

I just realized that I think I'm suppose to incorporate "METHODS" in this program, but now I don't see how :(

Hi

What is wrong with this? And, how can I fix it? Because, for the first part we are just looking for the tutition in the 10th year, so we don't have to sum them up to 10years.

Look at this it was in my previouse post

Year 10.................... feeYearTen=feeYearOne*[(1+5/100)*(1+5/100)*(1+5/100)*......*(1+5/100)] (9 times)
Loop over the adjutant and you will get what you want
If you did not want to use the loop structure look at this
feeYearN =feeYearOne*(1+5/100)power(N-1)
you can do it with one and only one line of code

Hope it helps.

Sorry, but I'm still confused because I tried to understand your computation by plugging in the numbers and it turns out that the program I wrote is getting the same answers as yours:

Year 10.................... feeYearTen=feeYearOne*[(1+5/100)*(1+5/100)*(1+5/100)*......*(1+5/100)] (9 times)

10000 *[(1+5/100)*(1+5/100)*(1+5/100)*(1+5/100)*(1+5/100)*(1+5/100)*(1+5/100)*(1+5/100)*(1+5/100)]

10000 * [1.55132822]

15 513.2822


for (int i = 1; i <= 9; i++)
{
fee = ((fee * .05) + fee);

}

i = 1st year = 10000

i = 1 + 1 = 2
i = 2nd year
fee = ((10000 * .05) + 10000)
10500.0

i = 2 + 1 = 3
i = 3rd year
fee = ((10500.0 * .05) + 10000)
11025.0

i = 3 + 1 = 4
i = 4th year
fee = ((11025.0 * .05) + 10000)
12155.0625

i = 4 + 1 = 5
i = 5th year
fee = ((12155.065 *.05) + 10000)
12762.815625

i = 5 + 1 = 6
i = 6th year
fee = ((12762.815625 * .05) + 10000)
13400.95640625

i = 6 + 1 = 7
i = 7th year
fee = ((13400.95640625 * .05) + 10000)
14071.0042265625

i = 7 + 1 = 8
i = 8th year
fee = (14071.0042265625 * .05) + 10000)
14774.554437890625

i = 8 + 1 = 9
i = 9th year
fee = (14774.554437890625 * .05) + 10000)
15513.28159785156

Here is the code that display all of them:

import javax.swing.JOptionPane;

public class Tuition
{
	public static void main (String[] args)
	{

		double fee = (10000.00);
		int year = 1;

		for (int i = 1; i <= 9; i++)
		{
			fee = ((fee * .05) + fee);

			System.out.println(fee);
		}

	}
}

I don't know, the way I did it, I thought that's how the loop worked, I'm not sure how to embedd the code that you came up with into a loop. The end answer is the same, so that's why I'm confused.

Like, I don't think I'm right either, but I'm not seeing the difference or what's wrong, sorry. Do you get what I mean?

By the way this project is due 7pm today (US eastern time):(

SORRY I had made a mistake in the previous post, it's actually + FEE not + 10000.

Year 10.................... feeYearTen=feeYearOne*[(1+5/100)*(1+5/100)*(1+5/100)*......*(1+5/100)] (9 times)

10000 *[(1+5/100)*(1+5/100)*(1+5/100)*(1+5/100)*(1+5/100)*(1+5/100)*(1+5/100)*(1+5/100)*(1+5/100)]

10000 * [1.55132822]

15 513.2822


for (int i = 1; i <= 9; i++)
{
fee = ((fee * .05) + fee);

}
i = 1st year = 10000

i = 1 + 1 = 2
i = 2nd year
fee = ((10000 * .05) + 10000)
10500.0

i = 2 + 1 = 3
i = 3rd year
fee = ((10500.0 * .05) + 10500)
11025.0

i = 3 + 1 = 4
i = 4th year
fee = ((11025.0 * .05) + 11025)
12155.0625

i = 4 + 1 = 5
i = 5th year
fee = ((12155.065 *.05) + 12155.065)
12762.815625

i = 5 + 1 = 6
i = 6th year
fee = ((12762.815625 * .05) + 12762.815625)
13400.95640625

i = 6 + 1 = 7
i = 7th year
fee = ((13400.95640625 * .05) + 13400.95640625)
14071.0042265625

i = 7 + 1 = 8
i = 8th year
fee = (14071.0042265625 * .05) + 14071.0042265625)
14774.554437890625

i = 8 + 1 = 9
i = 9th year
fee = (14774.554437890625 * .05) + 14774.554437890625)
15513.28159785156

Here is the code that display all of them:

import javax.swing.JOptionPane;

public class Tuition
{
	public static void main (String[] args)
	{

		double fee = (10000.00);
		int year = 1;

		for (int i = 1; i <= 9; i++)
		{
			fee = ((fee * .05) + fee);

			System.out.println(fee);
		}

	}
}

It's okay, I have turned in the assignment now. Thank you for everyone's help, appreciate it!

How can i calculate the years 11 , 12 , 13 , and 14
Pleaseeee

Please start your own thread with your new problem.
This thread is over one year old.

write a program that computes and assesses the tuition fee of the students how to make program of it ?

by writing the code, compiling it and running it.
this is a dead thread, if you have an actual question, start a new thread, and do provide a bit more of information than the bit you've provided here.

Hello rereye

  1. Please do not hijack other people's posts for your question. Start your own new topic.

  2. DaniWeb Member Rules (which you agreed to when you signed up) include:
    "Do provide evidence of having done some work yourself if posting questions from school or work assignments"
    http://www.daniweb.com/community/rules

Post what you have done so far and someone will help you from there.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.