I am trying to set up a java programming scanner for my prog
I am trying to set up a java programming scanner for my program.
Hello! I cannot understand how to set up a scanner in this program. I am doing something wrong because my scanner ( I am using eclipse) has a red x next to it.
import java.math.*;
import java.util.*;
public class Project4 {
static double P;
static double r;
static int N;
public static void main(String[] args) {
PrintDirections();
GetPmt();
GetRate();
GetNumWeeks();
Report_FV(Compute_FV(P, r, N), P, r, N);
}
public static void PrintDirections() {
System.out.println(\"This program calculates the future value of the account. Program will ask for the number of deposited payments, the amount deposited, and the interest rate and then display the future amount in the account after the user enters all prompted information.\");
}
public static void GetPmt() {
Scanner console = new Scanner(System.in);
System.out.println(\"Enter the amount of payment\");
P= console.nextDouble();
}
public static void GetRate() {
Scanner console = new Scanner(System.in);
System.out.println(\"Enter the annual interest rate in %\");
r= console.nextDouble();
}
public static void GetNumWeeks() {
Scanner console = new Scanner(System.in);
System.out.println(\"Enter the number of payments\");
N= console.nextInt();
}
public static double Compute_FV(double P, double R, double N) {
return P*(Math.pow(r/5200+1,N)-1)*(r/5200+1)/(r/5200);
}
public static void Report_FV(double P, double R, double N, double FV) {
System.out.printf(\"The future value of %d weekly payments of $ %.2f at %.3f is $ %.2f \ \",N,P,r,FV);
}
}
Solution
public class Project4 {
   private double P;
    private double r;
    private int N;
   /**
    * @return the p
    */
    public double getP() {
        return P;
    }
   /**
    * @param p
    * the p to set
    */
    public void setP(double p) {
        P = p;
    }
   /**
    * @return the r
    */
    public double getR() {
        return r;
    }
   /**
    * @param r
    * the r to set
    */
    public void setR(double r) {
        this.r = r;
    }
   /**
    * @return the n
    */
    public int getN() {
        return N;
    }
   /**
    * @param n
    * the n to set
    */
    public void setN(int n) {
        N = n;
    }
   public void PrintDirections() {
        System.out
                .println(\"This program calculates the future value of the account. Program will ask for the number of deposited payments, the amount deposited, and the interest rate and then display the future amount in the account after the user enters all prompted information.\");
}
   public double Compute_FV() {
        return P * (Math.pow(r / 5200 + 1, N) - 1) * (r / 5200 + 1)
                / (r / 5200);
}
   public void Report_FV(double P, double R, double N, double FV) {
        System.out
                .printf(\"The future value of %d weekly payments of $ %.2f at %.3f is $ %.2f \ \",
                        (int) N, P, r, FV);
}
public static void main(String[] args) {
       double P;
        double r;
        int N;
        Project4 project4 = new Project4();
        project4.PrintDirections();
        Scanner console = new Scanner(System.in);
        System.out.println(\"Enter the amount of payment\");
        P = console.nextDouble();
        project4.setP(P);
        System.out.println(\"Enter the annual interest rate in %\");
        r = console.nextDouble();
        project4.setR(r);
        System.out.println(\"Enter the number of payments\");
        N = console.nextInt();
        project4.setN(N);
        project4.Report_FV(project4.Compute_FV(), P, r, N);
   }
 }
OUTPUT:
This program calculates the future value of the account. Program will ask for the number of deposited payments, the amount deposited, and the interest rate and then display the future amount in the account after the user enters all prompted information.
 Enter the amount of payment
 2
 Enter the annual interest rate in %
 5
 Enter the number of payments
 657
 The future value of 5 weekly payments of $ 1832.77 at 5.000 is $ 657.00




