1. Member
Join Date
Apr 2012
Posts
18
Rep Power
0

## Java Assignment

Hey guys, struggling with Java eclipse programming and am in need of some assitance for this question, anything would be great.

2. Consider the following skeleton of the program:

public class Calculator {
public static void main(String[] args) {
Investment i1 = new Investment(100, 7.5, 10);
Investment i2 = new Investment(200, 5);
Investment i3 = new Investment();
i1.calculateFutureValue();
i2.calculateFutueValue();
i3.calculateFutureValue();
}
}

public class Investment{
}

Investment(){
}
Investment(double mthlyInvest, double rate, double time) {
}
Investment(double mthlyInvest, double rate){
}
Public void calculateFutureValue(){
}

1. Default constructor will take the monthly investment, rate and years from user.
2. Parameterized constructors will accept these values as arguments.
3. for calculating future value,
a. The rate of interest must be changed to monthly rate of interest.
For example: 7.5% interest
Monthly interest = 0.75/12;
b. The number of years must be changed to number of months.
For example: 10 years
Number of months = 10 * 12 = 120 months
4 To calculate the future value use the following formula to given number of months (Hint: use of
loops):

futureValue = (futureValue + monthlyInvestment)*(1 + MonthlyInterest)
5. Make use of access modifiers, Accessors and mutators where required.

2. Moderator
Join Date
Apr 2009
Posts
11,302
Rep Power
18

## Re: Java Assignment

What have you done so far and where are you stuck?
Include full error messages and stack traces, indicating where in your code the problem lies.

Also, please use [code] tags [/code] when posting code.

3. Member
Join Date
Apr 2012
Posts
18
Rep Power
0

## Re: Java Assignment

import java.util.Scanner;

public void calculateFutureValue(){

Im unsure how to continue on at all, im mind blanked

4. Moderator
Join Date
Apr 2009
Posts
11,302
Rep Power
18

## Re: Java Assignment

Odd place to start.
Start at point 1, with the constructor.

And use code tags, or I'm out of here.

5. Member
Join Date
Apr 2012
Posts
18
Rep Power
0

## Re: Java Assignment

what u mean code tags or your out of here?

6. Senior Member
Join Date
Apr 2012
Location
New York State of Confusion, USA
Posts
137
Blog Entries
1
Rep Power
0

## Re: Java Assignment

I think the OP has no clue how to define a class and is overwhelmed by the list, rather than just starting with figuring out the basics and doing point 1 as you've suggested Tolls.

Perhaps the OP should start by reading the Java Classes Tutorial to understand the basics of creating a class. Hint: A constructor is just a special kind of method.

7. Member
Join Date
Apr 2012
Posts
18
Rep Power
0

## Re: Java Assignment

thanks for tryng guys ill see if anyone else knows what to do

8. Senior Member
Join Date
Apr 2012
Location
New York State of Confusion, USA
Posts
137
Blog Entries
1
Rep Power
0

## Re: Java Assignment

You don't need to go anywhere, just listen to what you're told and if you don't understand, just ask.

What Tolls means is whenever you post java code using special tags so your java code will look like this:

Java Code:
```class YourCodeGoesHere {
private int myPrivateIntAttribute;

public void myPublicMethod()  {
myPrivateIntAttribute = 42;  // The answer to the ultimate question about life, the universe and everything.
}
}```
You do this by wrapping your Java in the "code" tags that Tolls included in his original reply.

9. Member
Join Date
Apr 2012
Posts
18
Rep Power
0

## Re: Java Assignment

oh i get you now and that should come up in green on my program.

Ok so help me with part one this is what i reckon so far.

import java.util.Scanner;

// then i need to work out the monthly investment and rate of the user

im really not sure how to do the next few lines

10. Member
Join Date
Apr 2012
Posts
18
Rep Power
0

## Re: Java Assignment

i knoe how much use dislike giving out codes, i just need some help i really struggle at this subject

11. ## Re: Java Assignment

Originally Posted by MichaelF144
i knoe how much use dislike giving out codes, i just need some help i really struggle at this subject
You've been given a link to a tutorial. Did you read it? If so, what didn't you understand? You were also asked to use code tags, which you have not done (although your "code" is barely one line, it's the thought that counts). You have to put forth some effort. Read the tutorial you were linked to, and ask a specific question about what you don't understand.

You're going to have to forget about the assignment for a second and go back to the basics. Can you write a hello world program as a starter shell?

12. Senior Member
Join Date
Apr 2012
Location
New York State of Confusion, USA
Posts
137
Blog Entries
1
Rep Power
0

## Re: Java Assignment

Please understand that we are not going to do your work for you. We are going to ask a lot of questions to get you to think about how you can do your work for yourself. We will point out silly errors and link you to information that helps you learn.

1. Default constructor will take the monthly investment, rate and years from user.

Do you know which is your default constructor? Do you understand that you have to obtain the three inputs from the person that runs your program? You can use this example to read input from a user, it reads into the byte[] you pass as the parameter. You can then create a String from that byte[].

Java Code:
```try {
byte[] buffer = new byte[100];
String s = new String(buffer);
} catch (IOException e1) {
e1.printStackTrace();
}```

13. Member
Join Date
Apr 2012
Posts
18
Rep Power
0

## Re: Java Assignment

class HelloWorld {
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}

i just dont know how to continue the program at all

14. ## Re: Java Assignment

Originally Posted by MichaelF144
i just dont know how to continue the program at all
Okay, so rereading the post, you were already supplied a skeleton code. What's the very next thing you know you have to do? Don't worry about the whole list, just break it down into smaller pieces and concentrate on one small piece at a time.

15. Member
Join Date
Apr 2012
Posts
18
Rep Power
0

## Re: Java Assignment

the very next thing i need to do would be part one of the assignment.
1. Default constructor will take the monthly investment, rate and years from user.

so i need to write a code which involves the compouned interest rate, or so i think

16. Senior Member
Join Date
Apr 2012
Location
New York State of Confusion, USA
Posts
137
Blog Entries
1
Rep Power
0

## Re: Java Assignment

Correct. From reading your original post, I believe you already defined that constructor, it is empty though. Now you have to fill in the method body.

17. Member
Join Date
Apr 2012
Posts
18
Rep Power
0

## Re: Java Assignment

so see how i provided the skeleton what i basically need to do is fill in the values?

18. Senior Member
Join Date
Apr 2012
Location
New York State of Confusion, USA
Posts
137
Blog Entries
1
Rep Power
0

## Re: Java Assignment

You have to get the values from the user as I described in my previous post and you have to store them in the instance variables for your class.

19. Member
Join Date
Apr 2012
Posts
18
Rep Power
0

## Re: Java Assignment

so these values 7.5% interest
Monthly interest = 0.75/12;
10 years

20. Senior Member
Join Date
Apr 2012
Location
New York State of Confusion, USA
Posts
137
Blog Entries
1
Rep Power
0

## Re: Java Assignment

Well, I imagine that 7.5% interest will be a float. Your monthly interest is incorrect though. How do you represent 7.5% as a decimal value?

Page 1 of 2 12 Last

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•