Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need to incorporat reading data from a file and writing the output to a file t

ID: 3633527 • Letter: I

Question

I need to incorporat reading data from a file and writing the output to a file to this program I've already completed. This program will use the Java capabilities of inheritance to accomplish this. Just need the code that would make it read and write with files please

import java.util.Scanner;
public class Student
{
   
    Scanner scan = new Scanner(System.in);
   
    private String firstName, lastName, address, phoneNumber;
    private int numberOfStudents, creditsEnrolled, mealChoice, inState, outOfState, stuffYourFace, iCantStandThisFood, imOnADiet;
    private String instateRate, lateFee, campusFood, healthCare;
    private double fee, incidentalFee, mealPlan, stuffYourFaceCost, iCantStandThisFoodCost, imOnADietCost, healthCareCost;
    private double tuition = 0.00, total = 0.00;

    public void readInput()
    {
        System.out.println("Please enter first name.");
        firstName = scan.nextLine();
       
        System.out.println("Please enter last name.");
        lastName = scan.nextLine();
       
        System.out.println("Please enter Address.");
        address = scan.nextLine();
       
        System.out.println("Please enter phone number");
        phoneNumber = scan.nextLine();
       
        System.out.println("Please enter credits enrolled");
        creditsEnrolled = scan.nextInt();
       
        System.out.println("Do you qualify for instate rate? (Yes/No)");
        instateRate = scan.nextLine();
        instateRate = scan.nextLine();
       
       
        System.out.println("Late fee assessed? (Yes/No)");
        lateFee = scan.nextLine();
       
        System.out.println("Do you want the on campus food plan? (Yes/NO)");
        campusFood = scan.nextLine();
        if(campusFood.toLowerCase().equals("yes"));
        {
            System.out.println("Which meal plan would you like. (Enter listed number to choose plan");
            System.out.println("1) Stuff your face for $4,999.00?");
            System.out.println("2) I can't stand this food for $3,499.00?");
            System.out.println("3) I'm on a diet for $ 2,599.00?");
           
            while(mealChoice == 1 || mealChoice == 2 || mealChoice == 3);
            {
                mealChoice = scan.nextInt();
                if(mealChoice == 1)
                {
                    mealPlan = 4999.00;
                }
                else if(mealChoice == 2)
                {
                    mealPlan = 3499.00;
                }
                else if(mealChoice == 3)
                {
                    mealPlan = 2599.00;
                }
                else
                {
                    System.out.println("Error, you did not enter a listed number. Please enter a listed number.");
                    System.out.println("Which meal plan would you like. (Enter listed number to choose plan");
                    System.out.println("1) Stuff your face for $4,999.00?");
                    System.out.println("2) I can't stand this food for $3,499.00?");
                    System.out.println("3) I'm on a diet for $ 2,599.00?");
                    mealChoice = scan.nextInt();
                }
            }
        }
               
        System.out.println("Do you want healthcare? (Yes/No)");
        healthCare = scan.nextLine();
        healthCare = scan.nextLine();
    }
   
   
   
    public void calculateData()
    {   
        if(healthCare.toLowerCase().equals("yes"))
        {
            if(creditsEnrolled <= 10)
            {
                healthCareCost = 25.00*creditsEnrolled;
            }
            else if(creditsEnrolled >= 10 && creditsEnrolled <= 15)
            {
                healthCareCost = 250;
                healthCareCost = healthCareCost + (creditsEnrolled - 10)*20;
            }
            else if(creditsEnrolled > 15)
            {
                healthCareCost = 350;
                healthCareCost = healthCareCost + (creditsEnrolled-15)*15;
            }
        }
        else if(healthCare.toLowerCase().equals("no"))
        {
            healthCareCost = 0.00;
        }
   
       
        if(instateRate.toLowerCase().equals("yes"))
        {
                if(creditsEnrolled < 12)
                {
                   
                    tuition = creditsEnrolled * 102.50;
                }
                else if(creditsEnrolled >= 12 && creditsEnrolled <= 18)
                {
                    tuition = 1127.5;
                    tuition = tuition + (creditsEnrolled-12)*75.45;
                }
                else if(creditsEnrolled > 18)
                {
                    tuition = 1655.65;
                    tuition = tuition + (creditsEnrolled - 18)*93;
                }
           
            else
               
                if(creditsEnrolled < 12)
                {
                   
                    tuition = creditsEnrolled * 351;
                }
                else if(creditsEnrolled >= 12 && creditsEnrolled <= 18)
                {
                    tuition = 1230;
                    tuition = tuition + (creditsEnrolled-12)*255;
                }
                else if(creditsEnrolled > 18)
                {
                    tuition = 2588.1;
                    tuition = tuition + (creditsEnrolled - 18)*304;
                }
            }
        if(lateFee.toLowerCase().equals("yes"))
        {
            fee = tuition * .10;
        }
       
        incidentalFee = creditsEnrolled * 20.00;
        if(incidentalFee > 250.00)
        {
            incidentalFee = 250.00;
        }       
       
        total = tuition + fee + incidentalFee + healthCareCost + mealPlan;
    }
   
    public int getNumberOfStudents()
    {
        numberOfStudents = 1;
        return numberOfStudents;
    }
   
    public int getStuffYourFace()
    {
        if(mealChoice == 1)
        {
            stuffYourFace = 1;
        }
        else
        {
            stuffYourFace = 0;
        }
        return stuffYourFace;
    }
   
    public double getStuffYourFaceCost()
    {
        if(mealChoice == 1)
        {
            stuffYourFaceCost = 4999.00;
        }
        else
        {
            stuffYourFaceCost = 0.00;
        }
        return stuffYourFaceCost;
    }
   
    public int getICantStandThisFood()
    {
        if(mealChoice == 2)
        {
            iCantStandThisFood = 1;
        }
        else
        {
            iCantStandThisFood = 0;
        }
        return iCantStandThisFood;
    }
   
    public double getICantStandThisFoodCost()
    {
        if(mealChoice == 2)
        {
            iCantStandThisFoodCost = 34999.00;
        }
        else
        {
            iCantStandThisFoodCost = 0.00;
        }
        return iCantStandThisFoodCost;
    }
   
    public int getImOnADiet()
    {
        if(mealChoice == 3)
        {
            imOnADiet = 1;
        }
        else
        {
            imOnADiet = 0;
        }
        return imOnADiet;
    }
   
    public double getImOnADietCost()
    {
        if(mealChoice == 3)
        {
            imOnADietCost = 2599.00;
        }
        else
        {
            imOnADietCost = 0.00;
        }
        return imOnADietCost;
    }
   
    public double getMealPlan()
    {
        return mealPlan;
    }
   
    public int getInstate()
    {
        if(instateRate.toLowerCase().equals("yes"))
        {
            inState = 1;
        }
        else
        {
            inState = 0;
        }
        return inState;
    }
   
    public int getOutOfState()
    {
        if(instateRate == "no")
        {
            outOfState = 1;
        }
        else
        {
            outOfState = 0;
        }
        return outOfState;
    }
   
    public double getTuition()
    {
        return tuition;
    }
   
    public double getFee()
    {
        return fee;
    }
   
    public double getIncidentalFee()
    {
        return incidentalFee;
    }
   
    public double getHealthCareCost()
    {
        return healthCareCost;
    }
   
    public double getTotal()
    {
        return total;
    }
   
    public void writeOutput()
    {
        System.out.println("NAME: " + firstName + " " + lastName);
        System.out.println("CREDITS: " + creditsEnrolled);
        System.out.println("ADDRESS: " + address);
        System.out.println("PHONE: " + phoneNumber);
        System.out.println("TUITION: " + tuition);
        System.out.println("LATE FEE: " + fee);
        System.out.println("INCEDENTAL: " + incidentalFee);
        System.out.println("HEALTH CARE: " + healthCareCost);
        System.out.println("MEAL PLAN: " + campusFood);
        System.out.println("TOTAL: " + total);
    }
}

public class Reporter
{
    private int numberOfStudents, inState, outOfState, stuffYourFace, iCantStandThisFood, imOnADiet;
    private double stuffYourFaceCost, iCantStandThisFoodCost, imOnADietCost, mealPlan, tuition, fee, incidentalFee, healthCareCost, total;
    public void collectDataForReport(Student otherObject)
    {
        this.numberOfStudents += otherObject.getNumberOfStudents();
        this.stuffYourFace += otherObject.getStuffYourFace();
        this.stuffYourFaceCost += otherObject.getStuffYourFaceCost();
        this.iCantStandThisFood += otherObject.getICantStandThisFood();
        this.iCantStandThisFoodCost += otherObject.getICantStandThisFoodCost();
        this.imOnADiet += otherObject.getImOnADiet();
        this.imOnADietCost += otherObject.getImOnADietCost();
        this.inState += otherObject.getInstate();
        this.outOfState += otherObject.getOutOfState();
        this.mealPlan += otherObject.getMealPlan();
        this.tuition += otherObject.getTuition();
        this.fee += otherObject.getFee();
        this.incidentalFee += otherObject.getIncidentalFee();
        this.healthCareCost += otherObject.getHealthCareCost();
        this.total += otherObject.getTotal();
       
    }
    public void printDataForSchoolReport()
    {
        System.out.println("                    UNIVERSITY OF COMPUTERS");
        System.out.println("NUMBER OF STUDENTS: " + numberOfStudents);
        System.out.println("INSTATE: " + inState);
        System.out.println("OUT OF STATE: " + outOfState);
        System.out.println("MEAL PLAN     STUFF-YOUR-FACE: " + stuffYourFace + " " + stuffYourFaceCost);
        System.out.println("              I-CAN'T-STAND-THIS-FOOD: " + iCantStandThisFood + " " + iCantStandThisFoodCost);
        System.out.println("              I'M-ON-A-DIET: " + imOnADiet + " " + imOnADietCost);
        System.out.println("                   FOOD SUB TOTAL: " + mealPlan);
        System.out.println("TUITION: " + tuition);
        System.out.println("LATE FEE: " + fee);
        System.out.println("INCEDINTAL: " + incidentalFee);
        System.out.println("HEALTH CARE: " + healthCareCost);
        System.out.println("                   TOTAL: " + total);
    }
}

Explanation / Answer

That's fairly straightforward. Scanner is fine for taking inputs, but here's what I usually use for outputting to a file: public void writeOutput() throwsIOException { FileWriter f= new FileWriter("filename.txt"); BufferedWriter b= new BufferedWriter(f); b.write("NAME: " + firstName + " " + lastName+" "); b.write("CREDITS: " + creditsEnrolled+" "); b.write("ADDRESS: " + address+" "); //etc... // the extra is for new lines. b.close(); } remember to import java.io.* as well.