Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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() previous.getPrice()) && (p.getPrice() < current.getPrice()))){ previous = current; current = current.next; } p.next = current; previous.next = p; } catch(Exception nre){ previous.next = p; } } } } count++; } public void display(){ Procedure1 item = head; System.out.println("Number of Items in List: " +count); for(;item != null;){ item.display(); item = item.next; } } public static void main(String[] args){ Procedure1 pr1 = new Procedure1(); pr1.selectDB("P122"); Procedure1 pr2 = new Procedure1(); pr1.selectDB("P321"); Procedure1 pr3 = new Procedure1(); pr1.selectDB("P114"); Procedure1 pr4 = new Procedure1(); pr1.selectDB("P119"); LinkedList list1 = new LinkedList(); list1.addItemPrice(pr1); list1.addItemPrice(pr2); list1.addItemPrice(pr3); list1.addItemPrice(pr4); list1.display(); } }

*******************************************************************

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions

Question

Explain in detail the developing and developed economy of India

Answered: 1 week ago

Question

Problem: Evaluate the integral: I = X 52+7 - 1)(x+2) dx

Answered: 1 week ago

Question

What is gravity?

Answered: 1 week ago

Question

What is the Big Bang Theory?

Answered: 1 week ago