Java: Trouble calling another class - java

I am just beginning in Java and I am having a peculiar problem that I just cant seem to get to the root of. I have 2 programs and one is taking data from a text file and then calling it into a class to do some calculations and finally putting the output into another text document.
Everything works except this part here:
public class Paycheck
{
//Constants for the private class
private final String EMPLOYEE_NAME; //Employee name
private final String SOC_SEC_NUM; //Employee Social Security Number
private final double WAGE_RATE; //Employee wage
private final double TAX_RATE; //Employee tax withheld
private final double HOURS_WORKED; //Employee's hours of work
//Variables for the private class
private double grossPay; //Employee Gross Pay
private double taxWithheld; //Employee Tax Withheld
private double netPay; //Employee Net Pay
//This is the constructor. It is called whenever an instance of the class is created
public Paycheck (String name, String ssn, double wage, double tax, double hours)
{
EMPLOYEE_NAME = name; //Instance employee name
SOC_SEC_NUM = ssn; //Instance employee SSN
WAGE_RATE = wage; //Instance employee wage rate
TAX_RATE = tax; //Instance employee tax rate
HOURS_WORKED = hours; //Instance employee hours worked
}
//This calculates the variables in the paycheck class
public void calcWages()
{
grossPay = WAGE_RATE * HOURS_WORKED; //Calculates Gross Pay
taxWithheld = grossPay * TAX_RATE; //Calculates Taxes Withheld
netPay = grossPay - taxWithheld; //Calculates net pay
}
//Returns the Paycheck objects Employee Name
public String getEmployeeName()
{
return EMPLOYEE_NAME;
}
//Returns the employee SSN of the Paycheck object
public String getSocSecNum()
{
return SOC_SEC_NUM;
}
//Reeturns a Paycheck object's employee Wage Rate
public double getWageRate()
{
return WAGE_RATE;
}
//Returns a Paycheck object's employee tax rate
public double getTaxRate()
{
return TAX_RATE;
}
//Returns an Paycheck object's employee hours worked
public double getHoursWorked()
{
return HOURS_WORKED;
}
//Returns a Paycheck object's gross pay
public double getGrossPay()
{
return grossPay;
}
//Returns a Paycheck object's Taxes Withheld
public double getTaxWithheld()
{
return taxWithheld;
}
//Returns a paycheck object't net pay
public double getNetPay()
{
return netPay;
}
The calcWages() does the necessary calculations and below this are a series of get statements to call them. However, my output does not return any values for the calcWages() arguments.
I added the getters here and my other program is grabbing them. However the final output on my other program is coming up as 0.
Where am I going wrong here?
This is the part of the main method that is calling them
public static void main(String [] args) throws IOException //Throws clause
{
//Declare constants
final String INPUT_FILE = "Employee.txt"; //Input text file containing Employee information
final String OUTPUT_FILE= "PayrollHistory.txt"; //Output text file that will receive the data
//Declare Variables
String payPeriodDate; //Ending date of the pay period
String employeeName; //Employee Name in text file
String employeeSocSecNum; //Employee SSN in text file
double employeeHours; //Employee hours worked
double employeeTax; //Employee Tax rate
double employeeWage; //Employee Wage rate
double totalGrossPay; //Total employee Gross for pay period
double totalTaxWithheld; //Total Tax Withheld for pay period
double totalNetPay; //Total Net Payroll for pay period
String input; //String input for double conversion in JoptionPane
DecimalFormat money = new DecimalFormat ("#0.00"); // Decimal Format to put money in the right format(USD)
//This ensures that the input file actually exists in the program folder
//And exits the program if it does not, along with the prompt.
File file = new File(INPUT_FILE);
if (!file.exists())
{
JOptionPane.showMessageDialog(null, "The " + INPUT_FILE + " file cannot be found." +
"Program terminated.");
System.exit(0);
}
// Create Scanner object to enable reading data from input file
Scanner inputFile = new Scanner(file);
// Create FileWriter and PrintWriter objects to enable
// writing (appending not overwriting) data to text file
FileWriter fwriter = new FileWriter(OUTPUT_FILE, true);
PrintWriter outputFile = new PrintWriter(fwriter);
//Initialize accumulator values
totalGrossPay = 0.0;
totalTaxWithheld = 0.0;
totalNetPay = 0.0;
//Get the pay period for the employee
payPeriodDate = JOptionPane.showInputDialog("Enter pay period ending date (mm/dd/yyyy):");
outputFile.println("PAY PERIOD ENDING DATE: " + payPeriodDate); //Inputs pay period date into the text file
outputFile.println(); // Blank line
outputFile.println(); // Blank line
while (inputFile.hasNext()) // This will look through the input file and get the necessary variable input
{
// Read employee Name from Input File
employeeName = inputFile.nextLine();
// Read employee SSN from input file
employeeSocSecNum = inputFile.nextLine();
// Read employee Wage Rate from input file
//Parses it into a double type
input = inputFile.nextLine();
employeeWage = Double.parseDouble(input);
//Read employee tax rate from input file
//Parses it into a double type
input = inputFile.nextLine();
employeeTax = Double.parseDouble(input);
//Get number of hours worked
input = JOptionPane.showInputDialog("Employee Name: " + employeeName +
"\nEnter number of hours worked:");
employeeHours = Double.parseDouble(input);
//This call the paycheck class to create a new Paycheck Object
Paycheck employee = new Paycheck (employeeName, employeeSocSecNum, employeeWage, employeeTax, employeeHours);
// Call Paycheck class methods into the output file
outputFile.println("Employee Name: " + employeeName); //Employee Name
outputFile.println("SSN: " + employeeSocSecNum); //Employee SSN
outputFile.println("Hours Worked: " + employeeHours); //Employee Hours Worked
outputFile.println("Wage Rate: " + money.format(employeeWage)); //Employee Wage Rate
outputFile.println("Gross Pay: " + money.format(employee.getGrossPay())); //Employee Gross Pay
outputFile.println("Tax Rate: " + money.format(employeeTax)); //Employee Tax Rate
outputFile.println("Tax Withheld: " + money.format(employee.getTaxWithheld())); //Employee Tax Withheld
outputFile.println("Net Pay: " + employee.getNetPay()); //Employee Net Pay
outputFile.println(); // Blank line

You don't appear to be actually calling calcWages() before calling your getters, so grossPay, taxWithheld, and netPay are still going to be 0, as that's Java's default value for uninitialized numbers.
You need to call employee.calcWages() before referencing those values for them to change.

It is because calcWages() is declared void (public void calcWages()), meaning it is not supposed to return any value but just complete a series of steps (calc payroll particulars in this example). After calling it, just proceed to reference the instance variables it processed.

You have declared your variables as final, meaning they can only be assigned once.

Related

Add a second class to the main class for an annual compensation calculator

I tried searching for this answer and found several answers that were similar to what I am looking for, but I can't seem to apply the suggestions provided on unrelated data to my specific program.
I need to take this working code I have created (a program to calculate an employee's annual compensation) and adjust it in a way that shows two classes (per the instructions of my homework assignment). The output given is exactly what I want, I just need help to reorganize the code so there is more than the main class. Is this something I can get help with here?
Here is my working code:
public class AnnualCompensation {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
//create salary variable and commission percentage variable
double salary = 60000;
double commissionPercentage = 0.06;
//create command output for the user to get directions to enter value
System.out.println("Enter total amount of sales for the year: ");
double value = input.nextDouble();
double totalCompensation = (value * commissionPercentage) + salary;
System.out.println("Your annual compensation is: " + "$" + totalCompensation);
}
}
Thanks in advance.
create a class Employee with salary and commissionPercentage as the fields.
In constructor take the salary and commision% of employee and initate the fields.
in this class Employee create a method which will take vavlue as input and will calculate the compensation and return it.
So from main create the instance of Employee class and call the calculateMethod.
I would structure it with these classes:
AnnualCompensationCalculator which will do the computation for you as a utility class, and
AnnualCompensation main class which would be focused on requesting for the user input (and would call the calculator).
Suppose you can move the logic inside new class.
AnnualCompensationCalculator.java
public class AnnualCompensationCalculator{
private static double commissionPercentage = 0.06;
public static double calculateCompensation(double sales ,double salary){
return((sales * commissionPercentage) + salary);
}
}
AnnualCompensation .java
public class AnnualCompensation {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
//create salary variable and commission percentage variable
double salary = 60000;
//create command output for the user to get directions to enter value
System.out.println("Enter total amount of sales for the year: ");
double value = input.nextDouble();
System.out.println("Your annual compensation is: " + "$" + AnnualCompensationCalculator.calculateCompensation(value,salary));
}
}
Following Object Oriented Programming, I suggest you create a new class Employee that holds the salary and compensation percentage of an employee, which also has a method for calculating the compensation.
Like this:
class Employee {
private double salary;
private double commPercent;
public Employee(double salary, double commPercent) {
this.salary = salary;
this.commPercent = commPercent;
}
public double calculateCompensation(double totalSales) {
return (totalSales * commPercent) + salary;
}
/* Setters & Getters */
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
public double getCommPercent() {
return commPercent;
}
public void setCommPercent(double commPercent) {
this.commPercent = commPercent;
}
}
Then have your main class use this Employee class to do all the work:
public class AnnualCompensation {
public static void main(String[] args) {
//Initialize an Employee object
Employee emp = new Employee(60000, 0.06);
//Create command output for the user to get directions to enter value
System.out.print("Enter total amount of sales for the year: ");
Scanner input = new Scanner(System.in);
double salesAmt = input.nextDouble();
//Calculate the compensation based on the user input then print it
System.out.println("Your annual compensation is: $"
+ emp.calculateCompensation(salesAmt));
}
}

Multiply all values together in string format printing in java [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I've only had a few hours practicing and learning Java so I'm still learning the basics.
I'm reading values from a text file, which contains:
Single
60
112.50
Master
70
2227.50
Penthouse
5
5000.00
(So it appears as when run)
Room Type: Single, Bookings: 60, Room Price: £112.00, Income: £6,750.00, Tax: 1350.00
And so fourth with each room.
I've printed all the values in a string format which is required. However, my problem is really simple.
I just want to add all the income together in a totalincome variable and add all the paidTax together in a totalpaidTax variable, then continue to print out it, to basically show the total tax paid and total income from all the rooms.
Although, I just don't know how to write it. I've had multiple attempts at trying but just no luck.
Here's my current code.
import java.io.FileReader;
import java.util.Scanner;
public class WagesCalculator {
public static void main(String[] args) throws Exception {
Scanner input = new Scanner(System.in);
Scanner file = new Scanner(new FileReader("task3.txt"));
Scanner sc = new Scanner(System.in);
//Current tax variable value
double tax = 20;
//User Input Y or N to change tax variable value
System.out.println("- - Hotel Tax System - -");
System.out.print("Do you want to specify a custom Tax Rate? [Y|N]: ");
//if statement to change tax variable value subject to Y or N
if (sc.next().equalsIgnoreCase("Y")) {
System.out.print("Please enter the new tax value: ");
tax = new Scanner(System.in).nextInt();
}
//Prints out current tax value
System.out.println("The current tax rate is " + tax+".");
while (file.hasNext()) {
String name = file.next();
int numberOfBookings = file.nextInt();
double price = file.nextDouble();
double income = numberOfBookings * price;
double paidTax = income*(tax/100);
//String format print out final calculations
System.out.printf("Room Type: %s, Bookings: %d, Room Price: £%.2f, Income: £%.2f, Tax: %.2f %n", name, numberOfBookings, price, income, paidTax);
}
file.close();
}
}
Objects are your friend.
Create an object for each Room in your input.
Store the Rooms in a List.
Aggregate values from the List.
Print accordingly.
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class WagesCalculator
{
public static void main(String[] args)
throws Exception
{
WagesCalculator wc = new WagesCalculator();
wc.calculate();
}
public void calculate()
throws FileNotFoundException
{
Scanner file = new Scanner(new FileReader("task3.txt"));
Scanner sc = new Scanner(System.in);
// Current tax variable value
double tax = 20;
// User Input Y or N to change tax variable value
System.out.println("- - Hotel Tax System - -");
System.out.print("Do you want to specify a custom Tax Rate? [Y|N]: ");
// if statement to change tax variable value subject to Y or N
if (sc.next().equalsIgnoreCase("Y"))
{
System.out.print("Please enter the new tax value: ");
tax = new Scanner(System.in).nextInt();
}
// Prints out current tax value
System.out.println("The current tax rate is " + tax + ".");
List<Room> rooms = new ArrayList<Room>();
while (file.hasNext())
{
String name = file.next();
int numberOfBookings = file.nextInt();
double price = file.nextDouble();
rooms.add(new Room(tax, name, numberOfBookings, price));
}
file.close();
rooms.stream().forEach(e -> System.out.println(e));
double totalIncome = rooms.stream().map(r -> r.income)
.reduce((a, b) -> a + b).orElse(0.0);
double totalTax = rooms.stream().map(r -> r.tax).reduce((a, b) -> a + b)
.orElse(0.0);
System.out.printf("Total income was: %d\nTotal tax was %d\n", totalIncome,
totalTax);
}
class Room
{
double tax;
String name;
int numberOfBookings;
double price;
double income;
double paidTax;
public Room(double tax, String name, int numberOfBookings, double price)
{
this.tax = tax;
this.name = name;
this.numberOfBookings = numberOfBookings;
this.price = price;
this.income = numberOfBookings * price;
this.paidTax = income * (tax / 100);
}
#Override
public String toString()
{
return String.format(
"Room Type: %s, Bookings: %d, Room Price: £%.2f, Income: £%.2f, Tax: %.2f %n",
name, numberOfBookings, price, income, paidTax);
}
}
}

Formatting percentages with printf

import java.util.Scanner;
public class Taxes {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.printf("Enter the employees first name: ");
Scanner input = new Scanner(System.in);
String fName = input.nextLine();
System.out.printf("Enter the employees last name: ");
String lName = input.nextLine();
System.out.printf("Enter the hours worked for the week: ");
double hours = input.nextDouble();
System.out.printf("Enter the hourly pay rate: ");
double pay = input.nextDouble();
double gross = hours * pay;
System.out.printf("Enter the federal tax withholding: ");
double fed = input.nextDouble();
double fTax = gross * fed;
System.out.printf("Enter the state tax withholding: ");
double state = input.nextDouble();
double sTax = gross * state;
double Ttax = sTax + fTax;
double net = gross - Ttax;
System.out.printf(
"Employee Name:%s %s\n\nHours Worked:%s hours\n\nPay Rate:$%.2f\n\nGross pay:$%.2f\n\nDeductions: \n\n\tFederal Withholding:(%.2f%%)$%.2f \n\n"
+ "\tState Withholding:(%.2f%%)$%.2f\n\n\tTotal Witholding:$%.2f\n\nNet Pay:$%.2f",
fName, lName, hours, pay, gross, fed, fTax, state, sTax, Ttax, net);
input.close();
}
}
I need to declare two more variables to get the Federal and State tax withholdings to show as a percent.
Example They show as (00.20%) I need them to return as a whole percent like (20.00%)
I've tried declaring new variable at the bottom such as:
statewit = sTax * 100;
fedwit = fTax * 100;
to get the percents to return as I want but it tends to add that total to the net at the end.
Any help would be appreciated greatly, thanks!
Try this.
double percent=12.34;
System.out.printf("%.2f%%", percent);
// or in different convention "percent as number *100"
System.out.printf("%.2f%%", percent*100.0);
EDIT: Your Question can be divided in two:
Convention in which numbers are used (normal or percent scaled *100)
Real formatting to String
BTW Your code is long and has very little to FORMATTING.
Java has no special type for percent values. Types: double, BigDecimal can be used with his behaviour, or integer types too, if programmer keep integer convention
EDIT: thanks Costis Aivalis , comma corrected :)

Getting a value form "get and set" in java

I have a school problem that I'm stuck on. The problem is that the gross pay keeps coming up as 0.0.
Here's the question:
Design a Payroll class with the following fields:
• name : a String containing the employee's name
• idNumber: an int representing the employee's ID number
• rate: a double containing the employee's hourly pay rate
• hours: an int representing the number of hours this employee has worked
The class should also have the following methods :
• Constructor : takes the employee's name and ID number as arguments
• Accessors: allow access to all of the fields of the Payroll class
• Mutators: let the user assign values to the fields of the Payroll class
• grossPay: returns the employee's gross pay, which is calculated as the number of
hours worked times the hourly pay rate.
Write another program that demonstrates the class by creating a Payroll object , then
asking the user to enter the data for an employee in the order: name , ID number, rate, hours.
The program should then print out a statement in the following format (for example, if
you had an employee named Chris Jacobsen with ID number 11111, who works for 5 hours at
$10/hr):
Chris Jacobsen, employee number 11111, made $50.00 in gross pay.
Using text forming so that the gross pay is rounded to two decimal places.
Here's what I have so far:
import java.util.Scanner;
public class Payroll
{
private String EmployeeName;
private int IDnumber;
private double HourlyPayRate;
private double TotalHoursWorked;
private double TotalGrossPay;
public Payroll(String Name, int ID, double HourlyRate, double HoursWorked)
{
EmployeeName = Name;
IDnumber = ID;
}
public String getEmployeeName()
{
return EmployeeName;
}
public int getIDnumber()
{
return IDnumber;
}
public void setHourlyPayRate(double HourlyRate)
{
HourlyPayRate = HourlyRate;
}
public double getHourlyPayRate()
{
return HourlyPayRate;
}
public void setTotalHoursWorked(double HoursWorked)
{
TotalHoursWorked = HoursWorked;
}
public double getTotalHoursWorked()
{
return TotalHoursWorked;
}
public void setTotalGrossPay(double GrossPay)
{
TotalGrossPay = GrossPay;
}
public double getTotalGrossPay(double HourlyRate, double HoursWorked)
{
TotalGrossPay = HourlyRate * HoursWorked;
return TotalGrossPay;
}
public static void main(String[] args)
{
String EmployeeName;
int IDnumber;
double TotalHoursWorked;
double HourlyPayRate;
double TotalGrossPay;
Scanner keyboard = new Scanner(System.in);
System.out.print("Enter employee's name:");
EmployeeName = keyboard.nextLine();
System.out.print("Enter employee's ID number:" );
IDnumber = keyboard.nextInt();
System.out.print("Enter hourly rate:");
HourlyPayRate = keyboard.nextDouble();
System.out.print("Enter number of hours worked:");
TotalHoursWorked = keyboard.nextDouble();
Payroll pay = new Payroll(EmployeeName, IDnumber, HourlyPayRate, TotalHoursWorked);
System.out.print(EmployeeName + ", " + "employee number " + IDnumber + ", made $" +
pay.TotalGrossPay + " in gross pay.");
}
}
Thanks for any help...
TotalGrossPay is a calculated value, unless you call the methods to calculate it, it will remain as its default value (0)
The fact is, you shouldn't be storing this value anyway, as it's value is actually determine by the calculation of the other fields.
Remove the TotalGrossPay field from your class and write a simple "getter" that calculates the value and returns it...
public double getTotalGrossPay()
{
return HourlyRate * HoursWorked;
}
As a general rule of thumb, you should not be accessing fields directly, but should always be accessing their values (setting/getting) via methods
Also, don't ignore values passed to your constructor...
public Payroll(String Name, int ID, double HourlyRate, double HoursWorked)
{
EmployeeName = Name;
IDnumber = ID;
// What about HourlyRate and HoursWorked??
}
Either make the user supply these vai setters or assign them within your constructor (and yes, you could use the setters to change the values after the fact...)
public Payroll(String Name, int ID, double HourlyRate, double HoursWorked)
{
EmployeeName = Name;
IDnumber = ID;
this.HourlyRate = HourlyRate;
this.HoursWorked = HoursWorked;
}
You might like to have a read through Code Conventions for the Java TM Programming Language, it will make it easier for people to read your code and for you to read others
in your constructor you are not doing anything with HourlyRate and HoursWorked
public Payroll(String Name, int ID, double HourlyRate, double HoursWorked)
Why is your getter taking parameters you need to rename it to something like calculateGrossPay(). Remove them and use the instance members HourlyRate and HoursWorked to calculate total gross pay. This is why you are getting a 0.0 as a result
Another point worth noting here is , double variable when uninitialized is set to 0.0 by Java
public double getTotalGrossPay(double HourlyRate, double HoursWorked)

Local variable can't take methods parameters

I am new To Java please help me, my local variable can't take me methods parameters.
import javax.swing.*;
import java.util.*;
import java.io.*;
import java.text.DecimalFormat; //I can not get my local variables in my
// main to accept my methods parameters.
// This is my program.
public class AccountBank
{
public static void main (String[] args) throws IOException
{
// Calling in my Class
Accountclass BankAcc = new Accountclass();
// initialize both there variables in. order to use them in a for loop.
double depDrw = 0;// this are one of the variables that is giving me problems
double withDrw = 0; // this is the other that is giving me problems
double totalW = 0;
double totalD = 0;
// declaring all my variables
String name="";
double month;
double startBal;
// This section will greet and accept input by asking the user to enter the starting alance and set it in my class
// Greetings
JOptionPane.showMessageDialog(null,"Lets Get Started");
// receiving input for my name variable
name = JOptionPane.showInputDialog(null, "Please Enter Your Name Below: ");
// ask user for starting balance
startBal = Double.parseDouble(JOptionPane.showInputDialog("What Is The Starting Balance In Your Account:"));
// This will set the value in my class
BankAcc.setBal(startBal);
// ask user how many months has the account been active
month = Double.parseDouble(JOptionPane.showInputDialog("Months That Account Has Been Active:"));
// This section will accept input by asking the user to enter each amount deposited every month from the account set it in my class.
// This will be shown in the message box
depDrw = depositTotal(deposit); << // I am having trouble here it wont take my parameters variable which I created on the buttom. please help
// This will sum up every amount the user enters in the message box.
totalD += depDrw;
// This will set the value in my class
BankAcc.setdeposit(totalD);
// This section will accept input by asking the user to enter each amount withdrawn every month from the account and set it in my class
// This will be shown in the message box
withDrw = withdrawTotal(wit); // <<< I am having problem here this variable does not take the value of my methods parameter, which i created on the bottom of this page.
// This will sum up every amount the user enters in the message box.
totalW += withDrw;
// This will set the value in my class
BankAcc.setwithdraws(totalW);
//This section will display the " monthly interest rate, monthly interest earned, total amount deposited, total amount withdrawn, and the final balance of the account."
DecimalFormat formatter = new DecimalFormat("#0.0000");
DecimalFormat formatter2 = new DecimalFormat("#0.0");
DecimalFormat formatter3 = new DecimalFormat("#0.00");
//Get the calculations from the savings account class and display them.
JOptionPane.showMessageDialog(null," Account Name: " +name+"\n \n Your Monthly Interest Rate Is ..... "
+ formatter.format(BankAcc.monthInt())+"%" + "\n \n Your Monthly Interest Earned Was ..... $"
+ formatter2.format(BankAcc.GetInt()) + "\n \n Your Overall Amount With Deposited Was ..... $" + totalD +
" \n \n Your Overall Amount WithDrawn Was ..... $" + totalW + " \n \n Your Remaining Balance Is ..... $"
+ formatter3.format(BankAcc.getFinalbal()),"Results", JOptionPane.PLAIN_MESSAGE );
}
public static double depositTotal( String deposit)
throws IOException
{
double sales;
double totalDeposit = 0;
File file = new File ("deposits.txt");
Scanner inputfile = new Scanner(file);
while (inputfile.hasNextDouble());
{
sales = inputfile.nextDouble();
totalDeposit += sales;
}
inputfile.close();
return totalDeposit;
}
public static double withdrawTotal( String wit)
throws IOException
{
double sales;
double totalwithdraws = 0;
File file = new File ("withdraws.txt");
Scanner inputfile = new Scanner(file);
while (inputfile.hasNextDouble());
{
sales = inputfile.nextDouble();
totalwithdraws += sales;
}
inputfile.close();
return totalwithdraws;
}
Your while loop is
while (inputfile.hasNextDouble());
{
sales = inputfile.nextDouble();
totalDeposit += sales;
}
There shouldn't be a ; after the while (inputfile.hasNextDouble())
while (inputfile.hasNextDouble())
{
sales = inputfile.nextDouble();
totalDeposit += sales;
}
Similarly for other while loops, remove the ;
Change your method declaration so it doesn't receive any parameter. And because it's returning a double, you may store the value it returns in a double variable:
double deposit = depositTotal();
In your depositTotal() method:
public static double depositTotal() throws IOException {
...
}

Categories