Question

Modify your program from Assignment # 7 part b (see below for code) by creating an...

Modify your program from Assignment # 7 part b (see below for code) by creating an interactive GUI application that displays the list of the orders read in from the file (create a data file using your CreateBankFile.java program which has a least 10 bank account records in it and include it with your submission) and the total number of bank accounts. When your program starts it will first read the records from the Bank Account file (AccountRecords.txt) and creates an array of BankAcct objects. The user of the application will then be able to have the bank accounts sorted (sorting the array of BankAcct objects) in the list by either, Customer #, Customer name, or Customer balance. Save your application as GUIBankAcctSorter.java.

Assignment # 7 part b code will be the basis of the above assignment:

Part one;

The Rochester Bank maintains customer records in a random access file. Write an application that creates 10,000 blank records and then allows the user to enter customer account information, including an account number that is 9999 or less, a last name, and a balance. Insert each new record into a data file at a location that a last name, and a balance. Insert each new record into a data file at a location that is equal to the account number. Assume that the user will not enter invalid account numbers. Force each name to eight character, padding it with spaces or truncating it if necessary. Also assume that the user will not enter a bank balance greater than 99,000.00. Save file as CreateBankFile.java

Part 2;

Create an application that uses the file created by the user located above and allows the user to enter an account- number order. Save file as ReadBankAccountsSequentially.java

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ScrollPaneConstants;

//This program will the modified program in assignment#7 a to display
//the list of the orders read in the from the file(create a data file using
// your CreateBankFile.java), which will at-least have 10 bank account records in it).
//The total number of bank account will be displayed at the bottom of the GUIBankAcctSorter
public class GUIBankAcctSorter extends JFrame implements ItemListener {

// my own code results and finalResults
String Results = null;
String FinalResults ="";
String ActualNumber;
int Accounts;
ArrayList<String[]> list=new ArrayList<String[]>();
public String StringBuilderw() {
String ProgrammerName = (" bank file");

// this is to accept input from the user
Scanner input = new Scanner(System.in);
final String ID_FORMAT = "000";
final String NAME_FORMAT = " ";
final int NAME_LENGTH = NAME_FORMAT.length();
// final String HOME_STATE = "WI";
final String BALANCE_FORMAT = "0000.00";
String delimiter = ",";
String s = ID_FORMAT + delimiter + NAME_FORMAT + delimiter
+ BALANCE_FORMAT + System.getProperty("line.separator");
final int RECSIZE = s.length();

  
byte data[] = s.getBytes();
// I thought of raping the data before reading it
ByteBuffer buffer = ByteBuffer.wrap(data);
final String EMPTY_CUST = "000";
String[] array = new String[10];
double Balance;
int total = 0;

// try and catch and declare an InputStream and BufferedReader to handle
// reading the file
try {
// I forgot to establish the path to get reading file from
Path file = Paths.get("Bank.txt");

BufferedInputStream iStream = new BufferedInputStream(
Files.newInputStream(file));
BufferedReader reader = new BufferedReader(new InputStreamReader(
iStream));


s = reader.readLine();
  
String test[]=new String[3];


while (s != null) {

array = s.split(delimiter);
if (!array[2].equals(EMPTY_CUST)) {
Balance = Double.parseDouble(array[2]);

// My own code for total of bank accounts
Accounts = Integer.parseInt(array[0]);

// My own code

if (Accounts != 0) {
String CustomerNumber = array[0];
String Names = array[1];
Balance = Double.parseDouble(array[2]);

String ActualResult = ("Cust# " + CustomerNumber
+ " Name " + Names + "Balance $" + Balance + "\n\n");
// total += Balance;
total += 1;

test[0]=array[0];
test[1]=array[1];
test[2]=array[2];
list.add(test);
//cust.add(array[0]);
StringBuilder AllTotalNumber = new StringBuilder();
AllTotalNumber.append(total);
ActualNumber = AllTotalNumber.toString();

FinalResults = FinalResults+ActualResult;
}

}

StringBuilder results = new StringBuilder();

String newline = System.getProperty("line.separator");
  
results.append(FinalResults);
  

  
     

//results.append(s);

// results.append(s1);
Results = results.toString();

s = reader.readLine();

}

// The reader close suppose to be out of while loop or else it won't
// loop
reader.close();

}

catch (Exception ex) {
System.out.println("Error was cought" + ex);
}

return Results;
}

// This code will create a label, a text field and a button to JFrame

JLabel header = new JLabel("Bank Account Sorter");
// I have to make this text field hold multiple text
JTextArea textArea = new JTextArea(StringBuilderw(), 10, 30);

JTextField TotalNumber = new JTextField(ActualNumber);
JLabel sortBy = new JLabel("Sort By");
JLabel totalNumberOfBankAcct = new JLabel("Total # of Bank Accounts");

// JCheckBoxes
JCheckBox boxCustomer = new JCheckBox("Cust#", false);
JCheckBox boxBalance = new JCheckBox("Balance", false);
JCheckBox boxName = new JCheckBox("Name", false);

// This is to make the textField scroll horizontally as need and not always.
// Vertical scroll is as needed as well
JScrollPane scroll = new JScrollPane(textArea);

// This is to set a font for JLabel header to be big
private Font bigFont = new Font("Arial", Font.BOLD, 20);

public GUIBankAcctSorter() {

super("Bank Account Sorter");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new FlowLayout());
// adding components to JFrame
add(header);
header.setFont(bigFont);
// I decide to show scroll not textArea
scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

add(scroll);

// textArea.add(scroll);
// add(textArea);
// textArea.setEditable(false);
// scroll.setBounds(5, 5, 300, 200);
add(sortBy);
add(boxCustomer);
add(boxBalance);
add(boxName);
add(totalNumberOfBankAcct);
add(TotalNumber);
TotalNumber.setEditable(false);
textArea.setEditable(false);

// Registering the class as listener for events
// generated by each three JCheckBoxes

boxCustomer.addItemListener(this);
boxBalance.addItemListener(this);
boxName.addItemListener(this);

}


@Override
public void itemStateChanged(ItemEvent event) {
Object Source = event.getSource();
int Select = event.getStateChange();

// This is were I define what happens when
// boxCustomer CheckBox is selected
if (Source == boxCustomer) {

// this is to check if boxCustomer is selected
// then the other check boxes should not be checked
if (boxCustomer.isSelected()) {
boxName.setSelected(false);
boxBalance.setSelected(false);
}

}

// this is to see if boxCustomer is sure selected from
// event.getStateChange() method
if (Select == ItemEvent.SELECTED) {
// code here
// Sort elements in an object array(bauble sort) using customer

}

// This is were I define what happens when
// boxName CheckBox is select

if (Source == boxName) {

// this is to check if boxName is selected
// then the other check boxes should not be checked
if (boxName.isSelected()) {

boxCustomer.setSelected(false);
boxBalance.setSelected(false);
}
StringBuilder results = new StringBuilder();
String table[][]=new String[list.size()][];
table=list.toArray(table);
Arrays.sort(table[0]);
for(int j=0;j<=list.size()-1;j++){
   for(int k=j;k<1;k++){
         
       results.append("Cust# " + table[j][k] + " Name " + table[j][k+1] + "Balance $" + table[j][k+2] + "\n\n");
     
   }

}


}
// this is to see if boxCustomer is sure selected from
// event.getStateChange() method
if (Select == ItemEvent.SELECTED) {
// code here
// Sort elements in an object array(bauble sort) using Names
}

// This is were I define what happens when
// boxBalance CheckBox is select
if (Source == boxBalance) {
// this is to check if boxBalance is selected
// then the other checkboxes should not be checked
if (boxBalance.isSelected()) {

boxCustomer.setSelected(false);
boxName.setSelected(false);

}
// this is to see if boxCustomer is sure selected from
// event.getStateChange() method
if (Select == ItemEvent.SELECTED) {
// code here
// Sort elements in an object array(bauble sort) using balance
}

}
}

// Main Method
public static void main(String[] args) {
GUIBankAcctSorter gui = new GUIBankAcctSorter();
gui.setSize(450, 350);
gui.setVisible(true);
gui.setResizable(false);

}

}

Output Screenshot:-


Bank Account Sorter Bank Account Sorter S Smith E Mushinge Balance $76543.0 egrggushinge Balance $7543.0 gmith dravo Balance

Add a comment
Know the answer?
Add Answer to:
Modify your program from Assignment # 7 part b (see below for code) by creating an...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please make it sure your answers are meet what question needs with details I do not accept (copy ...

    Please make it sure your answers are meet what question needs with details I do not accept (copy / post) Using NetBeans IDE and write a CLI application that uses the BufferedWriter to write data to the file named "CustomerList.txt". =========================================================================== The application should follow this information A. Create a program that allows a user to input customer records (ID number, first name, last name, and balance owed) and save each record to a file. Save the program asWriteCustomerList.java.When you...

  • write a code on .C file Problem Write a C program to implement a banking application...

    write a code on .C file Problem Write a C program to implement a banking application system. The program design must use a main and the below functions only. The program should use the below three text files that contain a set of lines. Sample data of these files are provided with the assessment. Note that you cannot use the library string.h to manipulate string variables. For the file operations and manipulations, you can use only the following functions: fopen(),...

  • Instructions Using the BCException.java and the BankCustomer.java from the first part of the assignment you will...

    Instructions Using the BCException.java and the BankCustomer.java from the first part of the assignment you will implement a driver class called Bank.java to manipulate an ArrayList of BankCustomer objects. Your code should read bank customers’ information from the user. It will then create a bank customer objects and add them to an arraylist in a sorted fashion (sorted by account number). The arraylist should be sorted in ascending order at all times. The arraylist should not contain null objects at...

  • The goal of this assignment is to give you some experience building a program that uses...

    The goal of this assignment is to give you some experience building a program that uses objects. You must work in teams of 2 to complete this assignment. You will use the BankAccount class you created in Lab 3 to create a banking program. The program must display a menu to the user to allow the user to select a transaction like deposit, withdraw, transfer, create a bank account, and quit the program. The program should allow a user to...

  • PYTHON The provided code in the ATM program is incomplete. Complete the run method of the...

    PYTHON The provided code in the ATM program is incomplete. Complete the run method of the ATM class. The program should display a message that the police will be called after a user has had three successive failures. The program should also shut down the bank when this happens. [comment]: <> (The ATM program allows a user an indefinite number of attempts to log in. Fix the program so that it displays a message that the police will be called...

  • In this assignment, you will be creating a program that requires a secret code to “unlock.”...

    In this assignment, you will be creating a program that requires a secret code to “unlock.” The program should first welcome the user and ask the user to input his/her name. Then the program will greet the user using the entered name. In order to “crack the code,” the user must input three integer numbers which satisfy the following conditions: The first number must be the number 3. The second number can either be the number 1 or be between...

  • In Java Code Needed is Below the Question Using Program 3: Encapsulating Dogs, modify this program...

    In Java Code Needed is Below the Question Using Program 3: Encapsulating Dogs, modify this program to create a database of dogs of your own. You will also include File I/O with this program. You will create 3 classes for this assignment. The first class: Create a Class representing the information that is associated with one item (one dog) of your database. Name this class Dog. Using Lab 3, this will include the information in regard to one dog. The...

  • This assignment must be completed on your own with your team mates. Don't give your code...

    This assignment must be completed on your own with your team mates. Don't give your code to others or use other students' code. This is considered academic m will result 0 marks) Write a java program that mange JUC Bank accounts services. The program should have the following: The total number of accounts (n) will be specified by the user at the beginning of the program. Depending upon the entered number, create three Arrays as following o o o Array...

  • I need to update the code listed below to meet the criteria listed on the bottom....

    I need to update the code listed below to meet the criteria listed on the bottom. I worked on it a little bit but I could still use some help/corrections! import java.util.Scanner; public class BankAccount { private int accountNo; private double balance; private String lastName; private String firstName; public BankAccount(String lname, String fname, int acctNo) { lastName = lname; firstName = fname; accountNo = acctNo; balance = 0.0; } public void deposit(int acctNo, double amount) { // This method is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT