🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: aus.computers.java
Article #1192

Re: converting integers

#1192
From: boyick
Date: Wed, 07 Jul 1999 00:00
209 lines
6037 bytes
I compiled the code and it works

just declare your variables as doubles and
A_Invest   =  Double.parseDouble(initString)

should work



import java.io.*;

 public class Investment {

   public static void main (String[] args)
       throws IOException
   {

     BufferedReader stdin   =   new BufferedReader
        (new InputStreamReader (System.in));


     String initString;
     double A_Invest;
     int N_Years;
     double Interest_Rate;
     double Value;
     int j;

     System.out.print ("Enter the amount to invest: ");
     initString      =   stdin.readLine();
     A_Invest   =  Double.parseDouble(initString) ;
     System.out.print ("Enter the amount to invest: " +  A_Invest );
     System.out.print (" ");

     System.out.print ("Enter the Interest Rate:");
     initString    =   stdin.readLine();
     Interest_Rate   = Double.parseDouble(initString) ;

     System.out.print (" ");

     System.out.print ("Enter the number of years: ");
     initString      =   stdin.readLine();
     N_Years   =   Integer.parseInt (initString);

     System.out.print (" ");

Value = A_Invest * (1 + Interest_Rate) * N_Years;

j = 1;
for (int i = 0; i < N_Years; i++) {
      System.out.print ("The value of your " + j++);
      System.out.print (" Year return will be: " + Value);
      System.out.println (" ");
    }
  }
}

----- Original Message -----
From: Knowledge <don'tsend@email.com.au>
Newsgroups: aus.computers.java
Sent: Wednesday, July 07, 1999 3:34 AM
Subject: converting integers


> Hi....I am writing this program for my course. I have been mucking around
> with doubles and floats...etc. Though I have tried to set the variables to
> double, I get compile errors. I have changed Integer.parseInt (initString)
> to Double.parseDouble(initString) but this compiles an error and too
mention
> that double A_Invest; also compiles an error.
>
> What I am asking is, Can someone show me how to change the
Integer.parseInt
> (initString) so I can accept decimal input from the command line. Here is
my
> source code:-
>
>
>
>
> import java.io.*;
>
>  public class Investment {
>
>    public static void main (String[] args)
>        throws IOException
>    {
>
>      BufferedReader stdin   =   new BufferedReader
>         (new InputStreamReader (System.in));
>
>
>      String initString;
>      int A_Invest;
>      int N_Years;
>      int Interest_Rate;
>      int Value;
>      int j;
>
>      System.out.print ("Enter the amount to invest: ");
>      initString      =   stdin.readLine();
>      A_Invest   =   Integer.parseInt (initString);
>
>      System.out.print (" ");
>
>      System.out.print ("Enter the Interest Rate:");
>      initString    =   stdin.readLine();
>      Interest_Rate   =   Integer.parseInt (initString);
>
>      System.out.print (" ");
>
>      System.out.print ("Enter the number of years: ");
>      initString      =   stdin.readLine();
>      N_Years   =   Integer.parseInt (initString);
>
>      System.out.print (" ");
>
> Value = A_Invest * (1 + Interest_Rate) * N_Years;
>
> j = 1;
> for (int i = 0; i < N_Years; i++) {
>       System.out.print ("The value of your " + j++);
>       System.out.print (" Year return will be: " + Value);
>       System.out.println (" ");
>     }
>   }
> }
>
>
>
>
>
>
>
>

Knowledge <don'tsend@email.com.au> wrote in message
news:Kerg3.109$QF3.14392@nsw.nnrp.telstra.net...
> Hi....I am writing this program for my course. I have been mucking around
> with doubles and floats...etc. Though I have tried to set the variables to
> double, I get compile errors. I have changed Integer.parseInt (initString)
> to Double.parseDouble(initString) but this compiles an error and too
mention
> that double A_Invest; also compiles an error.
>
> What I am asking is, Can someone show me how to change the
Integer.parseInt
> (initString) so I can accept decimal input from the command line. Here is
my
> source code:-
>
>
>
>
> import java.io.*;
>
>  public class Investment {
>
>    public static void main (String[] args)
>        throws IOException
>    {
>
>      BufferedReader stdin   =   new BufferedReader
>         (new InputStreamReader (System.in));
>
>
>      String initString;
>      int A_Invest;
>      int N_Years;
>      int Interest_Rate;
>      int Value;
>      int j;
>
>      System.out.print ("Enter the amount to invest: ");
>      initString      =   stdin.readLine();
>      A_Invest   =   Integer.parseInt (initString);
>
>      System.out.print (" ");
>
>      System.out.print ("Enter the Interest Rate:");
>      initString    =   stdin.readLine();
>      Interest_Rate   =   Integer.parseInt (initString);
>
>      System.out.print (" ");
>
>      System.out.print ("Enter the number of years: ");
>      initString      =   stdin.readLine();
>      N_Years   =   Integer.parseInt (initString);
>
>      System.out.print (" ");
>
> Value = A_Invest * (1 + Interest_Rate) * N_Years;
>
> j = 1;
> for (int i = 0; i < N_Years; i++) {
>       System.out.print ("The value of your " + j++);
>       System.out.print (" Year return will be: " + Value);
>       System.out.println (" ");
>     }
>   }
> }
>
>
>
>
>
>
>
>
Technical Details
Message-ID: <7lurmj$t5h$1@usenet.usq.edu.au>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <Kerg3.109$QF3.14392@nsw.nnrp.telstra.net>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10d6db,712db274a2126081
X-Google-Attributes: gid10d6db,public
From: "boyick" <boyick.mhlanga@e-edn.com>
Subject: Re: converting integers
Date: 1999/07/07
Message-ID: <7lurmj$t5h$1@usenet.usq.edu.au>
X-Deja-AN: 498043356
References: <Kerg3.109$QF3.14392@nsw.nnrp.telstra.net>
X-Priority: 3
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300
X-Complaints-To: Abuse@USQ.edu.au
X-Trace: usenet.usq.edu.au 931328531 29873 139.86.72.34 (7 Jul 1999 06:22:11 GMT)
Organization: University of Southern Queensland (Test)
X-MSMail-Priority: Normal
NNTP-Posting-Date: 7 Jul 1999 06:22:11 GMT
Newsgroups: aus.computers.java