I'm trying to read data from a file and within that file if there is a certain breed of dog the program needs to add a 20 dollar fee. But I'm not sure if I'm using the if statement wrong or if I initialized the three breeds who have an additional fee properly. Can someone plesae point me in the right direction.
import java.util.Scanner;//for the Scanner Class
import java.io.*;//for file I/O classes
public class project1_Adrian_Carlo {
public static void main (String[] args)throws IOException
{
File file = new File("boarding.txt"); //open the file (filename must be spelled correctly)
Scanner inputFile = new Scanner(file); //read the file using the Scanner class
//Declare variables
String input;
double dogWeight;
double boardingDays;
double boardingFee;
final double taxRate = .06;
double totalFee;
final double fee =.70;
final double highRiskFee = 20.00;
double totalBill = 0;
double taxAmount;
double bWeight;
String customersFN;
String customersLN;
String breed;
String pB;
String dobe;
String rT;
String PitBull;
String Doberman;
String Rottweiler;
while(inputFile.hasNext())
{
customersFN = inputFile.nextLine();
customersLN = inputFile.nextLine();
breed = inputFile.nextLine();
dogWeight = inputFile.nextDouble();
boardingDays = inputFile.nextDouble();
inputFile.nextLine();
if(inputFile.hasNext())
{
inputFile.nextLine();//this handles the end of the file to avoid an exception}
}
boardingFee = fee * boardingDays;
taxAmount = boardingFee * taxRate;
totalFee = taxAmount + boardingFee;
totalBill += boardingFee;
if
( breed.equals(PitBull) ||
breed.equals(Doberman) ||
breed.equals(Rottweiler)
)
{
totalFee += highRiskFee;
}
//output individual tuititon cost
System.out.println("Customer: " + customersFN + " " + customersLN );
System.out.println("Breed: " + breed);
System.out.println("Weight: " + dogWeight + " pounds");
System.out.println("Borading Days: " + boardingDays);
System.out.printf("Subtotal for " + boardingDays + " days $%.2f \n" ,boardingFee );
System.out.printf("Tax amount: $%.2f \n" ,taxAmount);
System.out.printf("Total due: $%.2f \n" ,totalFee );
System.out.println();
}
inputFile.close();
//output the total Fees outside of the loop
System.out.printf("Total Fees for a billing cycle: $%.2f \n", totalBill);
} }
Aucun commentaire:
Enregistrer un commentaire