ComputerScienceExpert

(11)

$18/per page/

About ComputerScienceExpert

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Applied Sciences,Calculus See all
Applied Sciences,Calculus,Chemistry,Computer Science,Environmental science,Information Systems,Science Hide all
Teaching Since: Apr 2017
Last Sign in: 8 Weeks Ago, 4 Days Ago
Questions Answered: 4870
Tutorials Posted: 4863

Education

  • MBA IT, Mater in Science and Technology
    Devry
    Jul-1996 - Jul-2000

Experience

  • Professor
    Devry University
    Mar-2010 - Oct-2016

Category > Programming Posted 26 Apr 2017 My Price 8.00

Loan Main Method

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);
}
}

Attachments:

Answers

(11)
Status NEW Posted 26 Apr 2017 01:04 AM My Price 8.00

-----------

Attachments

file 1493168914-Solutions file 2.docx preview (51 words )
H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly -----------onl-----------ine----------- an-----------d g-----------ive----------- yo-----------u e-----------xac-----------t f-----------ile----------- an-----------d t-----------he -----------sam-----------e f-----------ile----------- is----------- al-----------so -----------sen-----------t t-----------o y-----------our----------- em-----------ail----------- th-----------at -----------is -----------reg-----------ist-----------ere-----------d o-----------n -----------THI-----------S W-----------EBS-----------ITE-----------. ----------- Th-----------ank----------- yo-----------u -----------
Not Rated(0)