Question
We are going to create a LinkedList of Accounts. Create a Class called AccLinkedList, and store it in a file called AccLinkedList.java. Example Included below.
We are going to create a LinkedList of Accounts. Create a Class called AccLinkedList, and store it in a file called AccLinkedList.java. Example Included below. Remember back in Lab #1, you created an Account Class. Pull that class into this lab. Add a next property. Then build an AccLinkedList class that will store Accounts in a LinkedList in Order by Balance. That is the Highest balance should be at the head of the List and the lowest balance should be at the end of the list. Also include a display() method, that displays this linked list. In the main create and add 5 Account objects to your LinkedList, then print out this LinkedList. Make up the data for each account. The LinkedList should be in order by Balance.
*****************************
public class Account2{ //Properties private int accountNo; private int customerId; private String accountType; private double balance; //Constructors public Account2(){ accountNo = 0; customerId = 0; accountType = ""; balance = 0.0; } public Account2(int acc, int cid, String accType, double bal){ accountNo = acc; customerId = cid; accountType = accType; balance = bal; } //Behaviors public void setAccNo(int acc){ accountNo = acc; } public int getAccNo(){ return accountNo; } public void setCid(int cid){ customerId = cid; } public int getCid(){ return customerId; } public void setAccType(String accType){ accountType = accType; } public String getAccType(){ return accountType; } public void setBal(double bal){ balance = bal; } public double getBal(){ return balance; } public void display(){ System.out.println("===================== "); System.out.println("Account Number: " + getAccNo()); System.out.println("Customer ID: " + getCid()); System.out.println("Account Type: " + getAccType()); System.out.println("Balance: $" + getBal()); } public static void main(String[] args){ Account2 a2; a2 = new Account2(90000,3003,"SAV",8855.90); a2.display(); Account2 a3; a3 = new Account2(90001,3003,"CHK",786.54); a3.display(); Account2 a4; a4 = new Account2(90002,3001,"SAV",9654.13); a4.display(); Account2 a5; a5 = new Account2(90005,3006,"MMA",700356.23); a5.display(); } }
***********************************************************
class LinkedList{ public Procedure1 head = null; public int count = 0;
public LinkedList(){ } public void addItem(Procedure1 p){ p.next = head; head = p; count++; } public void addItemPrice(Procedure1 p){ //If list is empty, make p head if(count == 0){ head = p; } else{ // If list has one item if(count == 1){ // if p goes at beginning of list if (p.getPrice()
*******************************************************************
import java.util.*;
public class Procedure1{ private String pCode; private String pName; private String pDesc; private float price;
public Procedure1 next;
public Procedure1(){ pCode = ""; pName = ""; pDesc = ""; price = 0.0f; next = null; } public Procedure1(String pc, String pn, String pd, float pr){ pCode = pc; pName = pn; pDesc = pd; price = pr; next = null; } public void setPCode(String pc){pCode = pc;} public String getPCode(){ return pCode;}
public void setPName(String pn){pName = pn;} public String getPName(){ return pName;}
public void setPDesc(String pd){pDesc = pd;} public String getPDesc(){ return pDesc;}
public void setPrice(float pr){price = pr;} public float getPrice(){ return price;}
public void display(){ System.out.println("Procedure Code: " + getPCode()); System.out.println("Procedure Name: " + getPName()); System.out.println("Procedure Description: " + getPDesc()); System.out.println("Procedure Price: " +getPrice()); } // public void selectDB(String pc){ pCode = pc; String token; GetData gd = new GetData(pc, "Procedures.txt"); String data = gd.getData(); //System.out.println(data); StringTokenizer tok = new StringTokenizer(data, ":"); token = tok.nextToken(); token = tok.nextToken(); setPName(token); token = tok.nextToken(); setPDesc(token); token = tok.nextToken(); float pr = Float.parseFloat(token); setPrice(pr); } public void insertDB(String pc, String pn, String pd, float pr){ pCode = pc; pName = pn; pDesc = pd; price = pr; String sd = pc+":"+pn+":"+pd+":"+pr; SendData spd = new SendData("Procedures.txt",sd); } public static void main(String[] args){ //ArrayList Example } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started