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

You are to write a pseudocode for a program that will help the user manage their

ID: 3694012 • Letter: Y

Question

You are to write a pseudocode for a program that will help the user manage their checkbook.

The program will prompt the user to enter the check number, the date, the name the check is made out to, and the amount until the check number entered is 0. Make sure you use the appropriate data types.

Each entry will be saved to a file named check-ledger.dat

After the user enters a check number of 0, the program will display the check number, the date, the name the check is made to, and the amount for each record that has been saved in the file.

After displaying all the records the program will end.

The program should display a header line that identifies the data to be displayed from the file. The header will precede the data that will be listed.
(e,g., CHECK# DATE CHECK MADE TO AMOUNT)

Your program will use methods for each function it performs (e.g., housekeeping, entering data, writing data to the file, reading data from the file, finishing the program. There should be at least three methods used.

Explanation / Answer

==

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.ObjectOutputStream;

import java.io.Serializable;

import java.util.Date;

public class ChequeBook implements Serializable {

int chequeNumber;

   Date dateissued;

   String issuedTo;

double amount;

   public ChequeBook(int cn, Date di, String iT, double amt) {

       this.amount = amt;

       this.chequeNumber = cn;

       this.dateissued = di;

       this.issuedTo = iT;

   }

   public ChequeBook(int cn) {

       this.chequeNumber = cn;

   }

   public void save() throws IOException {

       FileOutputStream outStream = new FileOutputStream("check-ledger.dat",

               true);

       ObjectOutputStream objectsOutputFile = new ObjectOutputStream(outStream);

       objectsOutputFile.writeObject(this);

       objectsOutputFile.close();

   }

@Override

   public String toString() {

       return "ChequeBook [chequeNumber=" + chequeNumber + ", dateissued="

               + dateissued + ", issuedTo=" + issuedTo + ", amount=" + amount

               + "]";

   }

   public void setDateissued(Date dateissued) {

       this.dateissued = dateissued;

   }

   public void setIssuedTo(String issuedTo) {

       this.issuedTo = issuedTo;

   }

   public void setAmount(double amount) {

       this.amount = amount;

   }

}

==

import java.io.FileInputStream;

import java.io.IOException;

import java.io.ObjectInputStream;

import java.text.ParseException;

import java.text.SimpleDateFormat;

import java.util.Date;

import java.util.Scanner;

public class ChequeBookMain {

   public static void main(String[] args) throws ParseException, IOException {

       SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");

       Scanner sc = new Scanner(System.in);

       int flagChckNumberZero = 1;

       do {

           ChequeBook cb = readInput(sc);

           flagChckNumberZero = cb.chequeNumber;

           if (flagChckNumberZero != 0) {

               getOtherInputs(cb, formatter, sc);

               cb.save();

           }

       } while (flagChckNumberZero != 0);

       displayData();

   }

   private static void getOtherInputs(ChequeBook cb,

           SimpleDateFormat formatter, Scanner sc) throws ParseException {

       System.out.println(" Please Enter Date:");

       Date di = formatter.parse(sc.next());

       System.out.println(" Please Enter issued To:");

       String iT = sc.next();

       System.out.println(" Please Enter the amount:");

       double amt = sc.nextDouble();

       cb.setAmount(amt);

       cb.setDateissued(di);

       cb.setIssuedTo(iT);

   }

   public static ChequeBook readInput(Scanner sc) throws ParseException {

       System.out.println(" Please Enter cheque number:");

       int cn = sc.nextInt();

       ChequeBook cb = new ChequeBook(cn);

       return cb;

   }

   public static void displayData() throws IOException {

       ChequeBook cb;

       FileInputStream inStream = new FileInputStream("check-ledger.dat");

       ObjectInputStream objectsInFile = new ObjectInputStream(inStream);

       try {

           while((cb = (ChequeBook)objectsInFile.readObject()) != null){

           System.out.println(cb.toString());

           }

       } catch (ClassNotFoundException e1) {

           e1.printStackTrace();

       } finally {

           objectsInFile.close();

       }

   }

}

==

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote