1. Write a program to compute the annual rate of return on an investment. The program will ask the user for the original purchase price, the number of days the investment was owned, and the final sale price. The program must then print out the difference between sale price and the purchase price, along with the annual rate of return. Assume that all years are 365 days; we’re going to ignore leap years.

  2. Write a program called StringPlay.java. This program will ask the user for a multi-word string and read it in from the keyboard. It will then print out in order:
    • The original string.
    • The string in all caps.
    • The string in all lowercase.
    • The length of the string (labeled as such).
    • The first, middle, and last characters of the string (labeled as such).
    • The string with all a’s replaced by @’s and all e’s replaced by 3’s. Note that there is a method in the String class that will help you handle this part. Examine the documentation for the class to find it.

• Your files must each start with beginning comment blocks as specified in the coding guidelines for this course. The code should be well commented.

I dont know where to start!!!! help!

Before we go anywhere with this, I want you to be clear about two things. First, that this is actually two different programs which you'll need to write, and second, that you will need to be the one to write them. We can give advice and help, but we cannot and will not write the program for you.

Having said that, let's start with what you do know how to do. Can you write a simple class layout, and declare the various local and instance variables you will need for the first program?

Im just not sure how to start the program like the wording and the exact // and ** to use. I'm just kind of lost

you don't need to use // and ** if you don't want to.
how 'skilled' are you in Java? you need to start by going over your course notes again. the official java tutorials, which you can find Here, can help you just as well.

This is my first time using Java. I have done aprogram called Hello World but I had help with it so im just not entirely sure how to begin it and what the program is asking for exactly.

I hear you man it sounds like it's a tough assignment for you. Ok. I will give hints but I ain't too sure how fluently you speak the language (java) or even understand it. For the first program, think about the variables that will store the values you need for the program. E.g purchase price/prices, return on investment..etc. Think about their datatype.

for the second, you'd have an array of strings(if you're asking users for a multiple of strings) or a variable for one string and to do the other things. you'll have to use a method in the string class called substr. Look it up in the documention.

Is the assignment just for fun?

This assignment is for class and since ive never used Java before i guess the problem really is like how to set up a program, what goes where what certain language to use, ive gone over the book and i just cvant find anything that would help with this project that is due this friday.

Where on the tutorial do I look at for this program, I have done Hello World before but i got help with it from the professor so never really learned hands on

I think i got it fully figured out but one problem. FIguring out the annaul rate of return equation. Any help?

it should be ((Return - Capital) / Capital) × 100% = Rate of Return

so lets say i have a return of 1200, a capital of 1000 I would have a rate of 20%
How would i write the program to display the percent value

Do you have the equation for computing the value you want to display?
Given that if should be easy to write the code to do the computation.

import java.util.Scanner;

/**
*
* @auther Scott Swingle
* .
*/

public class investment {

        /**
         * @param args
         */
        public static void main(String[] args) {
                // TODO Auto-generated method stub
                double original;  //The user's original purchase price.
                double numberofdaysowned;  //The number of days the investment is owned
                double finalprice;  //Final sales price for investment
                double investmentchange;  //Investment change in value
                double rate;  //Annual rate of return
                Scanner keyboardinput = new Scanner(System.in);

                //Get the users original price.
                                System.out.println("Please enter the intial purchase price for your investment ");
                                original = keyboardinput.nextDouble();

                //Get the users number of days owned.
                                System.out.println("Please enter the number of days you held your investment");
                                numberofdaysowned = keyboardinput.nextDouble();

                //Get the users final sales price for investment.
                                System.out.println("Please enter the final sales price for your investment");
                                finalprice = keyboardinput.nextDouble();

                //Calculate investment change in value
                                System.out.println("Investment change in value: ");
                                investmentchange = finalprice - original;

                //Calculate annual rate of return
                                System.out.println("Annual rate of return: ");
                                rate = ((investmentchange - original)/original);

I cant seem to get this program to calculate the investment change and the rate of return, why is that?

Does the program produce any results? Can you show what the results are and explain what is wrong with them.

One problem with the posted code is that is it missing the ending source lines.

well nvm about that one i got it figured out, for the string problem we are asked for
The original string.
• The string in all caps.
• The string in all lowercase.
• The length of the string (labeled as such).
• The first, middle, and last characters of the string (labeled as such).
• The string with all a’s replaced by @’s and all e’s replaced by 3’s. Note that there is a method in the String class that will help you handle this part. Examine the documentation for the class to find it.

I wanted to know what string results in giving the first,middle, and last characters of a string, how to get the original string out, and have all a's replaced by @ and all e replaces by 3's

Look at the methods of the String class. There are some that will do the replacements.

What have you tried to use? What was the results? Remember Strings are immutable, the methods return a new String with the changes made.

Edited 4 Years Ago by NormR1

I got a good result for replacing A with @ and e with 3 but i had to do it in two different lines. is that normal?

the one i can't seem to find is The first, middle, and last characters of the string all i can get is the first letter back.

This question has already been answered. Start a new discussion instead.