Levels Tought:
Elementary,Middle School,High School,College,University,PHD
Teaching Since: | Apr 2017 |
Last Sign in: | 8 Weeks Ago, 4 Days Ago |
Questions Answered: | 4870 |
Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
I'm trying to get a java program to call a file to run it with the script and i can't seem to get it to call the file. Is there a particular thing i'm suppose to do??
Â
Â
Loan Main Method
package week7assignment;
import java.io.File;
import java.io.FileNotFoundException;
import java.text.DecimalFormat;
import java.util.NoSuchElementException;
import java.util.Scanner;
/**
*
* @author
*/
public class Loan {
/**
* @param args the command line arguments
*/
public static void main(String args) {
//setting format for money
DecimalFormat money = new DecimalFormat("$#,##0.00");
//instatiating new CarLoan object
CarLoan newLoan = new CarLoan(18875.0);
System.out.println(newLoan);
try {
int numb = 0;//variable for number of payments
double totPaid = 0;//variable for total amount paid
Scanner pay = new Scanner(new File("Payments.txt"));//reading in file
while (pay.hasNext()) {
numb++;
double payment = pay.nextInt();//reading each line
totPaid += payment;
newLoan.payment(payment);//passing information to payment method
System.out.println("\n Payment " + numb + " is " + money.format(payment)
+ ". Remaining balance is: " + newLoan);
System.out.println("\t Total of payments made is : " + money.format(totPaid)); } }
pay.close();
} catch (FileNotFoundException fnfe) {
System.out.println("File not found");
} catch (NoSuchElementException nsee) {
System.out.println("File not found");
} catch (IllegalStateException ise) {
System.out.println("File not found");
} }
Bank Account Class
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package week7assignment;
import java.text.DecimalFormat;
/**
*
* @author
*/
public class BankAccount {
public final DecimalFormat money = new DecimalFormat("$#,##0.00");
protected double balance;
public BankAccount() {
balance = 0.0;
}
public BankAccount(double startBalance) {
deposit(startBalance);
}
public double getBalance() {
return balance; }
public void deposit(double amount) {
if (amount >= 0.0) {
balance += amount;
} else {
System.err.println("Loan Balance must be positive!");
}
}
public void payment(double amount) {
if (amount >= 0.0 && amount <= balance) {
balance = balance - amount;
} else {
System.err.println("Payment amount must be positive, and "
+ "cannot be grater than balace!");
}
}
@Override
public String toString() {
return ("Balance on car loan is " + money.format(balance));
}
}
Car Loan Class
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package week7assignment;
/**
*
* @author
*/
public class CarLoan extends BankAccount {
public CarLoan() {
super(); }
public CarLoan(double startBalance) {
super(startBalance);
}
}
-----------