Linked list error
Can anyone tell what's wrong with the following code?
It says arguments(int) is not supported, but I don't know what it means.
Thank you.
import java.util.*;
public class tester {
* @param args
public static void main(String[] args) {
// TODO Auto-generated method stub
LinkedList Customers = new LinkedList();
for (int k=1;k<=5;k++)
Customers.addLast(k);
System.out.println(Customers);
System.out.println(Customers.indexOf(3));
Customers.removeFirst();
System.out.println(Customers);
System.out.println(Customers.indexOf(3));
System.out.println(Math.random()*10);
}
What version of Java are you using? Collections can only hold objects, not primitives. In Java 5 (or was it 4) they introduced autoboxing which automatically "boxes" the primitive value into its wrapper class and then stores that in the Collection.
Similar Messages
-
Linked list- error problem.... HELP!!!
Just got to the point that i'm better at drinking java than programing java....
how ever... I have done person register with Linked list. There are like 4 options:
1. New post
2. search
3. search and change
4. remove post
U can enter your name, adress and personal code number while making a new post, but when I've removed it ( l.list.remove(p);)and then search for it I get the error message "Exception in thread "main"....bla bla..". Why? and how do I get around this prob? PLEASE HELP ME!! gotta hand this in tonight!
Thank U!!
//PhilPhil,
LinkedList itself works as advertised (1.3.1). For example:
LL = LinkedList()
LL.add("apple")
LL.add("battle")
LL.add("cattle")
// printing LL yields all 3
LL.remove("battle")
// printing LL yields apple, cattle
You may need to post for responders to get a better idea. If posting code please enclose in blocks so it's formatted properly.
--A -
Linked List error [SOLVED]
I have written linked lists many times, but I'm stumped by this error.
header
#include <stdio.h>
typedef struct
char *str;
struct strstack *next;
} strstack;
void connect(struct strstack *a, struct strstack *b);
source
#include <stdio.h>
#include "strstack.h"
void connect(struct strstack *a, struct strstack *b)
a->next = b;
errors
gcc -g -O2 --std=c99 -c strstack.c
strstack.c: In function 'connect':
strstack.c:7: error: dereferencing pointer to incomplete type
make: *** [strstack] Error 1
Does anybody have any idea what causes this?
Last edited by Lexion (2009-09-12 23:48:49)Yes.
Your typedef is silly.
Replace with
typedef struct stack_s
char *str;
struct stack_s *next;
} stack_t;
or similar.
You have to name the struct, and use the struct name when declaring the next pointer. You can typedef it too, if you want to, but that name can't be used in the struct declaration. -
Baffling linked list error in C program
I've been working at porting some programs over to a Mac that were built using MS C 6.0. One of the programs uses a linked list to hold some data. Just couldn't get it to work. So I decided to run a really simple test. Create a short linked list and then print out the list.
The code is below and the output is below that. It looks like all the nodes get created properly and pointers assigned correctly but when I print out the list it crashes after the second node everytime. It appears that in node 2 the link to the next node has been corrupted but I can't see anywhere that happens. Is this not the way xcode does linked lists?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
struct linklist {
int node_number;
char node_name[10];
struct linklist * next;
struct linklist * makenode();
int main(int argc, const char * argv[])
struct linklist * list_head;
struct linklist * list_item;
int i;
// insert code here...
printf("Hello, World!\n");
list_head = makenode();
list_head->node_number = 1;
strcpy(list_head->node_name, "node 1");
list_head->next = NULL;
list_item = list_head;
printf("head-> %0lx, item-> %0lx \n", (unsigned long) list_head, (unsigned long) list_item);
for (i = 1; i < 10; i++)
list_item->next = makenode();
printf("New Node %d at %lu\n", i+1, (unsigned long) list_item->next);
list_item = list_item->next;
list_item->node_number = i+1;
sprintf(list_item->node_name, "node %d", i+1);
list_item->next = NULL;
printf("list_item points at %lu\n", (unsigned long) list_item);
list_item = list_head;
for (i = 0; i < 10; i++)
printf("list_item -> %lu>\n", (unsigned long) list_item);
printf("%d - %s>\n", list_item->node_number, list_item->node_name);
list_item = list_item->next;
return 0;
struct linklist * makenode()
return (struct linklist *) (malloc( sizeof(struct linklist())));
Output>>>>>
Hello, World!
head-> 7fdf604000e0, item-> 7fdf604000e0
New Node 2 at 140597369256496
list_item points at 140597369256496
New Node 3 at 140597369256512
list_item points at 140597369256512
New Node 4 at 140597369256528
list_item points at 140597369256528
New Node 5 at 140597369256544
list_item points at 140597369256544
New Node 6 at 140597369256560
list_item points at 140597369256560
New Node 7 at 140597369256576
list_item points at 140597369256576
New Node 8 at 140597369256592
list_item points at 140597369256592
New Node 9 at 140597369256608
list_item points at 140597369256608
New Node 10 at 140597369256624
list_item points at 140597369256624
list_item -> 140597369241824>
1 - node 1>
list_item -> 140597369256496>
2 - node 2>
list_item -> 7306087013738872835>Change
return (struct linklist *) (malloc( sizeof(struct linklist())));
to
return (struct linklist *) (malloc( sizeof(struct linklist)));
Hello, World!
head-> 100103b10, item-> 100103b10
New Node 2 at 4296031024
list_item points at 4296031024
New Node 3 at 4296031056
list_item points at 4296031056
New Node 4 at 4296031088
list_item points at 4296031088
New Node 5 at 4296031120
list_item points at 4296031120
New Node 6 at 4296031152
list_item points at 4296031152
New Node 7 at 4296031184
list_item points at 4296031184
New Node 8 at 4296031216
list_item points at 4296031216
New Node 9 at 4296031248
list_item points at 4296031248
New Node 10 at 4296031280
list_item points at 4296031280
list_item -> 4296030992>
1 - node 1>
list_item -> 4296031024>
2 - node 2>
list_item -> 4296031056>
3 - node 3>
list_item -> 4296031088>
4 - node 4>
list_item -> 4296031120>
5 - node 5>
list_item -> 4296031152>
6 - node 6>
list_item -> 4296031184>
7 - node 7>
list_item -> 4296031216>
8 - node 8>
list_item -> 4296031248>
9 - node 9>
list_item -> 4296031280>
10 - node 10>
Program ended with exit code: 0 -
Errors executing bulk query when updating a Sharepoint Linked List from Access
Hi all,
I have a Sharepoint list that is a Linked List with MS Access. It has just under 5,000 items (4,864), thus meaning it avoids the reduction in functionality lists of greater than 5,000 items have.
Among the list are five calculated columns. These take the information from another column (different employee numbers), and by using a formula produce a clickable link to my company's Directory page, where that particular employee's info is displayed. I'm
not sure if these five columns are relevant to my query, but I'm mentioning them in case.
My problem is this: Frequently when I run any query on the list that updates the list, I get this error: "There were errors executing the bulk query or sending the data to the server. Reconnect the tables to resolve the
conflicts or discard the pending changes".
When I review the errors, it says they conflict with errors a previous user made (with that previous user being me). It frequently highlights several columns, despite the info in them being identical, and the calculated columns (with the original showing
the value they contained and the new showing #VALUE! (as Access can't display the formulas).
However, if I click Retry All Changes, all the update stick and everything seems fine. Why is this happening? It's proving very annoying and is really stopping the automation of my large number of queries. A list of 5000 items isn't particular big (and they've
got roughly 100 columns, although I didn't think that was too large either, given Excel's 200+ column limit).
Is this due to poor query design and SQL? Is this due to connectivity issues (which I doubt, as my line seems perfect)? Is this due to Access tripping over itself and not executing the update on each row in the table, but rather executing them concurrently
and locking itself up? I'm at wit's end about it and really need to get this sorted.
Thanks in advance for any suggestions.Hi amartin903,
According to your description, my understanding is that you got an error when you used a linked list from Access.
The table that you are updating is a linked table that does not have a primary key or a unique index. Or, the query or the form is based on a linked table that does not have a primary key or a unique index. Please add the primary key or a unique index.
Here is a similar post, please take a look at:
http://social.technet.microsoft.com/Forums/en-US/545601e9-a703-4a02-8ed9-199f1ce9dac8/updating-sharepoint-list-from-access?forum=sharepointdevelopmentlegacy
I hope this helps.
Thanks,
Wendy
Wendy Li
TechNet Community Support -
Revision: 18926
Revision: 18926
Author: [email protected]
Date: 2010-12-01 14:07:19 -0800 (Wed, 01 Dec 2010)
Log Message:
bug fix BLZ-570 Double linked list with lot of objects result in BlazeDS Error deserializing error : StackOverflowError
We put hard limit to the max object nest level to prevent StackOverFlowError. the default max object nest level is 1024 and it can be configured in the endpoint/serialziation section in service-config.xml.
This needs documentation.
Checkintests pass
Ticket Links:
http://bugs.adobe.com/jira/browse/BLZ-570
Modified Paths:
blazeds/trunk/modules/common/src/flex/messaging/errors.properties
blazeds/trunk/modules/core/src/flex/messaging/endpoints/AbstractEndpoint.java
blazeds/trunk/modules/core/src/flex/messaging/io/SerializationContext.java
blazeds/trunk/modules/core/src/flex/messaging/io/amf/Amf0Input.java
blazeds/trunk/modules/core/src/flex/messaging/io/amf/Amf3Input.java
blazeds/trunk/modules/core/src/flex/messaging/io/amf/AmfIO.java -
Revision: 20451
Revision: 20451
Author: [email protected]
Date: 2011-02-24 08:33:31 -0800 (Thu, 24 Feb 2011)
Log Message:
backporting bug fix BLZ-570/BLZ-620 Double linked list with lot of objects result in BlazeDS Error deserializing error : StackOverflowError We put hard limit to the max object nest level to prevent StackOverFlowError. the default max object nest level is 1024 and it can be configured in the endpoint/serialziation section in service-config.xml. This needs documentation. Checkintests pass
Ticket Links:
http://bugs.adobe.com/jira/browse/BLZ-570
http://bugs.adobe.com/jira/browse/BLZ-620
Modified Paths:
blazeds/branches/4.0.0_fixes/modules/common/src/flex/messaging/errors.properties
blazeds/branches/4.0.0_fixes/modules/core/src/flex/messaging/endpoints/AbstractEndpoint.j ava
blazeds/branches/4.0.0_fixes/modules/core/src/flex/messaging/io/SerializationContext.java
blazeds/branches/4.0.0_fixes/modules/core/src/flex/messaging/io/amf/Amf0Input.java
blazeds/branches/4.0.0_fixes/modules/core/src/flex/messaging/io/amf/Amf3Input.java
blazeds/branches/4.0.0_fixes/modules/core/src/flex/messaging/io/amf/AmfIO.javaDear Pallavi,
Very useful post!
I am looking for similar accelerators for
Software Inventory Accelerator
Hardware Inventory Accelerator
Interfaces Inventory
Customization Assessment Accelerator
Sizing Tool
Which helps us to come up with the relevant Bill of Matetials for every area mentioned above, and the ones which I dont know...
Request help on such accelerators... Any clues?
Any reply, help is highly appreciated.
Regards
Manish Madhav -
Revision: 20443
Revision: 20443
Author: [email protected]
Date: 2011-02-23 21:19:22 -0800 (Wed, 23 Feb 2011)
Log Message:
back porting bug fix BLZ-570/BLZ-620 Double linked list with lot of objects result in BlazeDS Error deserializing error : StackOverflowError We put hard limit to the max object nest level to prevent StackOverFlowError. the default max object nest level is 1024 and it can be configured in the endpoint/serialziation section in service-config.xml. This needs documentation. Checkintests pass
Ticket Links:
http://bugs.adobe.com/jira/browse/BLZ-570
http://bugs.adobe.com/jira/browse/BLZ-620
Modified Paths:
blazeds/branches/3.x/modules/common/src/java/flex/messaging/errors.properties
blazeds/branches/3.x/modules/core/src/java/flex/messaging/endpoints/AbstractEndpoint.java
blazeds/branches/3.x/modules/core/src/java/flex/messaging/io/SerializationContext.java
blazeds/branches/3.x/modules/core/src/java/flex/messaging/io/amf/Amf0Input.java
blazeds/branches/3.x/modules/core/src/java/flex/messaging/io/amf/Amf3Input.java
blazeds/branches/3.x/modules/core/src/java/flex/messaging/io/amf/AmfIO.java -
What can be the error in this simple Linked List Implementation
i have a linked list code that wont compile successfully. The code is
//Lets try the Linked List
import java.util.*;
class LinkedListDemo {
public static void main ( String args[]){
LinkedList l1=new LinkedList();
l1.add( "A");
l1.add(2);
l1.add(3);
l1.add(4);
l1.add(5);
l1.addFirst(6);
l1.add(7);
l1.add(8);
l1.add(9);
//Lets check what does the Linked List hold at this time
System.out.println("Prsently the linked lis is having: "+l1);
}Problem is with the add method . Compiler error is that it doesnt recognize the symbol ie add method.i m sorry , java version is 1.4In that case, read up on the link jverd posted on AutoBoxing. You can only add Objects to a List. An int is a primitive, not an Object. You can try something like this:
l1.add(new Integer(2)); -
Runtime Error displaying Linked List
Hi, I've got a main class with a linked list which I am trying to display but I seem to be getting a "Class Cast Exception" eventhough I type cast the list as a String. Can anyone help please. The code is below:
import java.util.*;
public class Library
public static void main (String[] args)
LinkedList myList = new LinkedList();
LibraryItems libraryItems = new LibraryItems("Java how to Program", 10);
myList.add(libraryItems);
ListIterator myListIterator = myList.listIterator();
while (myListIterator.hasNext())
String itemlist = (String) myListIterator.next();//this is where the runtime error occurs
libraryItems = (LibraryItems) myList.getFirst();
System.out.println(itemlist + " " + libraryItems.getItemName() + " "+
libraryItems.getItemNumber());
}and here is the supporting class:
import java.util.LinkedList;
public class LibraryItems
private String itemName;
private int itemNumber;
public LibraryItems(String itemName, int itemNumber)
this.itemName = itemName;
this.itemNumber = itemNumber;
public String getItemName()
return itemName;
public int getItemNumber()
return itemNumber;
}Any help would really be appreciated.You add LibraryItems to the LinkedList, but when you get them out, you are casting to String.
probably
LibraryItems itemlist = (LibraryItems) myListIterator.next();
System.out.println(itemlist.getItemName()... -
Strange error message - linked lists (again)
I have to keep at this linked list thing if I'm ever going to really understand it!!
I have created a method to create a linked list via user input. I'm receiving only one strange ERROR, which states:
"This method must return a result of of type ListADT.Node."
And I have just started building my class ListADT...
class ListADT{
public Node createList(int aNumber){ // THIS IS WHERE THE ERROR POINTS
* integer variable aNumber is the length of the list user wishes to create.
Scanner console = new Scanner(System.in);
int number; // declare variable number as an integer.
Node newNode = new Node(); // declare and initialize newNode.
Node first = new Node(); // declare and initialize first.
Node last = new Node(); // delcare and initizlize last.
try
for(int i = 0; i <= aNumber; i++){ // for loop to enter numbers to build list.
System.out.println("Please enter an integer: "); // prompt user.
number = console.nextInt(); // assign user input to variable number.
newNode.info = number; // assign number to newNode;
if(first == null){ // checks to see if Node first is a null value.
first = newNode; // if true, then this node is the first and last node in the list.
last = newNode;
else{ // if first is not null, then newNode is placed at the end of the list.
last.link = newNode;
last = newNode;
return first;
catch (InputMismatchException imeRef) //Catches non-integer values
System.out.println("You entered a non-Integer! " + imeRef.toString()); //Prints error messageNow why can't the error messages help
out a little more? I would have never guessed that
there was a problem with the catch block not
returning anything!!The message was pretty informative -- it told you what was wrong. If the compiler could be so smart as to be able to tell you exactly what to fix, then the compiler would be able to write code all by itself -- and then you'd be out of a job. -
After Delete in Linked list...unable to display the linked list
Hi...i know that there is an implementation of the class Linked Link but i am required to show how the linked list works in this case for my project...please help...
Yes..I tried to delete some objects in a linked list but after that i am not able to display the objects that were already in the linked list properly and instead it throws an NullPointerException.
Below shows the relevant coding for deleting and listing the linked list...
public Node remove(Comparator comparer) throws Exception {
boolean found = false;
Node prevnode = head; //the node before the nextnode
Node deletedNode = null; //node deleted...
//get next node and apply removal criteria
for(Node nextnode = head.getNextNode(); nextnode != null; nextnode = nextnode.getNextNode()) {
if(comparer.equals(nextnode)) {
found = true;
//remove the next node from the list and return it
prevnode.setNextNode(nextnode.getNextNode());
nextnode.setNextNode(null);
deletedNode = nextnode;
count = count - 1;
break;
if (found) return deletedNode;
else throw new Exception ("Not found !!!");
public Object[] list() {
//code to gather information into object array
Node node;
Object[] nodes = new Object[count];
node = head.getNextNode();
for (int i=0; i<count; i++) {
nodes[i] = node.getInformation(); // this is the line that cause runtime error after deleting...but before deleting, it works without problem.
node = node.getNextNode();
return nodes;
}Please help me in figuring out what went wrong with that line...so far i really can't see any problem with it but it still throws a NullPointerException
ThanksOK -- I've had a cup and my systems are coming back on line...
The problem looks to be the way that you are handling the pointer to the previous node in your deletion code. Essentially, that is not getting incremented along with the nextNode -- it is always pointing to head. So when you find the node to delete then the line
prevnode.setNextNode(nextnode.getNextNode());will set the nextNode for head to be null in certain situations (like if you are removing the tail, for instance).
Then when you try to print out the list, the first call you make is
node = head.getNextNode();Which has been set to null, so you get an NPE when you try to access the information.
Nothing like my favorite alkaloid to help things along on a Monday morning...
- N -
How to use methods when objects stored in a linked list?
Hi friend:
I stored a series of objects of certain class inside a linked list. When I get one of them out of the list, I want to use the instance method associated with this object. However, the complier only allow me to treat this object as general object, ( of Object Class), as a result I can't use instance methods which are associated with this object. Can someone tell me how to use the methods associated with the objects which are stored inside a linked list?
Here is my code:
import java.util.*;
public class QueueW
LinkedList qList;
public QueueW(Collection s) //Constructor of QuequW Class
qList = new LinkedList(s); //Declare an object linked list
public void addWaiting(WaitingList w)
boolean result = qList.isEmpty(); //true if list contains no elements
if (result)
qList.addFirst(w);
else
qList.add(w);
public int printCid()
Object d = qList.getFirst(); // the complier doesn't allow me to treat d as a object of waitingList class
int n = d.getCid(); // so I use "Object d"
return n; // yet object can't use getCid() method, so I got error in "int n = d.getCid()"
public void removeWaiting(WaitingList w)
qList.removeFirst();
class WaitingList
int cusmNo;
String cusmName;
int cid;
private static int id_count = 0;
/* constructor */
public WaitingList(int c, String cN)
cusmNo = c;
cusmName = cN;
cid = ++id_count;
public int getCid() //this is the method I want to use
return cid;Use casting. In other words, cat the object taken from the collection to the correct type and call your method.
HashMap map = /* ... */;
map.put(someKey, myObject);
((MyClass)(map.get(someKey)).myMethod();Chuck -
How to add SharePoint 2013 Promoted link list view web part in page programatically with Tiles view using CSOM. I found that it can be
done by using XsltListViewWebPart class but how can I use this one by using shraepoint client api.
shivNice, can you point me to the solution please ?
I'm trying to do this but I get an error :
Web Part Error: Cannot complete this action. Please try again. Correlation ID: blablabla
StackTrace: at Microsoft.SharePoint.SPViewCollection.EnsureViewSchema(Boolean fullBlownSchema, Boolean bNeedInitallViews) at Microsoft.SharePoint.SPList.GetView(Guid viewGuid)
All help really appreciated. -
Need help regarding Linked List
I'm a beginner who just spent ages working on the following code.. but need help on re-implementing the following using a linked list, i.e. no array is allowed for customer records but you still can use arrays for names, address, etc.. Hopefully I've inserted enough comments..
Help very much appreciated!! Thanks! =]
import java.util.Scanner;
import java.io.*;
public class Bank
/* Private variables declared so that the data is only accessible to its own
class, but not to any other class, thus preventing other classes from
referring to the data directly */
private static Customer[] customerList = new Customer[30];
//Array of 30 objects created for storing information of each customer
private static int noOfCustomers;
//Integer used to store number of customers in customerList
public static void main(String[] args)
Scanner sc = new Scanner(System.in);
menu();
public static void menu()
char choice;
String filename;
int custId,counter=0;
double interestRate;
Scanner sc = new Scanner(System.in);
do
//Displaying of Program Menu for user to choose
System.out.println("ABC Bank Customer Management System Menu");
System.out.println("========================================");
System.out.println("(1) Input Data from File");
System.out.println("(2) Display Data");
System.out.println("(3) Output Data to File");
System.out.println("(4) Delete Record");
System.out.println("(5) Update Record");
System.out.println("(Q) Quit");
System.out.println();
System.out.print("Enter your choice: ");
String input = sc.next();
System.out.println();
choice = input.charAt(0);
//switch statement used to assign each 'selection' to its 'operation'
switch(choice)
case '1': int noOfRecords;
System.out.print("Enter file name: ");
sc.nextLine();
filename = sc.nextLine();
System.out.println();
noOfRecords = readFile(filename);
System.out.println(+noOfRecords+" records read.");
break;
case '2': displayRecords();
break;
case '3': writeFile();
break;
case '4': System.out.print("Enter account ID to be deleted: ");
sc.nextLine();
custId = sc.nextInt();
deleteRecord(custId);
break;
case '5': if(counter==0)
System.out.print("Enter current interest rate for saving account: ");
sc.nextLine();
interestRate = sc.nextDouble();
update(interestRate);
counter++;
else
System.out.println("Error: Accounts have been updated for the month.");
break;
}System.out.println();
}while(choice!='Q' && choice!='q');
/* The method readFile() loads the customer list of a Bank from a specified
text file fileName into customerList to be stored as array of Customer
objects in customerList in ascending alphabetical order according to the
customer names */
public static int readFile(String fileName)
int custId,i=0;
String custName,custAddress,custBirthdate,custPhone,custAccType;
double custBalance,curRate;
boolean d;
/* Try block to enclose statements that might throw an exception, followed by
the catch block to handle the exception */
try
Scanner sc = new Scanner(new File(fileName));
while(sc.hasNext())
/* sc.next() gets rid of "Account", "Id" and "=" */
sc.next();sc.next();sc.next();
custId = sc.nextInt();
d=checkDuplicate(custId);
/* checkDuplicate() is a method created to locate duplicating ids in array */
if(d==true)
/* A return value of true indicates duplicating record and the sc.nextLine()
will get rid of all the following lines to read the next customer's record */
sc.nextLine();sc.nextLine();sc.nextLine();
sc.nextLine();sc.nextLine();sc.nextLine();
continue;
/* A return value of false indicates no duplicating record and the following
lines containing the information of that customer's record is being read
in */
if(d==false)
/* sc.next() gets rid of "Name" and "=" and name is changed to upper case*/
sc.next();sc.next();
custName = sc.nextLine().toUpperCase();
/* sc.nextLine get rids of the following lines to read the next customer's
record if length of name is more than 20 characters*/
if(custName.length()>21)
System.out.println("Name of custId "+custId+" is more than 20 characters");
System.out.println();
sc.nextLine();sc.nextLine();sc.nextLine();sc.nextLine();
continue;
/* sc.next() gets rid of "Address" and "=" */
sc.next();sc.next();
custAddress = sc.nextLine();
/* sc.nextLine get rids of the following lines to read the next customer's
record if length of address is more than 80 characters*/
if(custAddress.length()>81)
System.out.println("Address of custId "+custId+" is more than 80 characters");
System.out.println();
sc.nextLine();sc.nextLine();sc.nextLine();sc.nextLine();
continue;
/* sc.next() gets rid of "DOB" and "=" */
sc.next();sc.next();
custBirthdate = sc.nextLine();
/* sc.nextLine get rids of the following lines to read the next customer's
record if length of date of birth is more than 10 characters*/
if(custBirthdate.length()>11)
System.out.println("D.O.B of custId "+custId+" is more than 10 characters");
System.out.println();
sc.nextLine();sc.nextLine();sc.nextLine();sc.nextLine();
continue;
/* sc.next() gets rid of "Phone", "Number" and "=" */
sc.next();sc.next();sc.next();
custPhone = sc.nextLine();
/* sc.nextLine get rids of the following lines to read the next customer's
record if length of phone number is more than 8 characters*/
if(custPhone.length()>9)
System.out.println("Phone no. of custId "+custId+" is more than 8 characters");
System.out.println();
sc.nextLine();sc.nextLine();sc.nextLine();sc.nextLine();
continue;
/* sc.next() gets rid of "Account", "Balance" and "=" */
sc.next();sc.next();sc.next();
custBalance = sc.nextDouble();
/* sc.next() gets rid of "Account", "Type" and "=" */
sc.next();sc.next();sc.next();
custAccType = sc.next();
if(custAccType.equals("Saving"))
customerList[noOfCustomers] = new Account1(custId,custName,custAddress,custBirthdate,custPhone,custBalance,custAccType);
sc.nextLine();
noOfCustomers++;
i++;
else if(custAccType.equals("Checking"))
customerList[noOfCustomers] = new Account2(custId,custName,custAddress,custBirthdate,custPhone,custBalance,custAccType);
sc.nextLine();
noOfCustomers++;
i++;
else if(custAccType.equals("Fixed"))
sc.next();sc.next();sc.next();sc.next();
curRate = sc.nextDouble();
Account3 temp = new Account3(custId,custName,custAddress,custBirthdate,custPhone,custBalance,custAccType,curRate);
customerList[noOfCustomers]=temp;
sc.nextLine();
noOfCustomers++;
i++;
else
System.out.println("Account type not defined.");
if(noOfCustomers==30)
System.out.println("The customer list has reached its maximum limit of 30 records!");
System.out.println();
return noOfCustomers;
//Exceptions to be caught
catch (FileNotFoundException e)
System.out.println("Error opening file");
System.exit(0);
catch (IOException e)
System.out.println("IO error!");
System.exit(0);
/* Bubblesort method used to sort the array in ascending alphabetical order
according to customer's name */
bubbleSort(customerList);
return i;
/* The method displayRecords() displays the data of the customer records on
screen */
public static void displayRecords()
int k;
/* Displaying text using the printf() method */
for(k=0;k<noOfCustomers;k++)
System.out.printf("Name = %s\n", customerList[k].getName());
System.out.printf("Account Balance = %.2f\n", customerList[k].getBalance());
System.out.printf("Account Id = %d\n", customerList[k].getId());
System.out.printf("Address = %s\n", customerList[k].getAddress());
System.out.printf("DOB = %s\n", customerList[k].getBirthdate());
System.out.printf("Phone Number = %s\n", customerList[k].getPhone());
String type = customerList[k].getAccType();
System.out.println("Account Type = " +type);
if(type.equals("Fixed"))
System.out.println("Fixed daily interest = "+((Account3)customerList[k]).getFixed());
System.out.println();
/* The method writeFile() saves the content from customerList into a
specified text file. Data is printed on the screen at the same time */
public static void writeFile()
/* Try block to enclose statements that might throw an exception, followed by
the catch block to handle the exception */
try
int i;
int n=0;
//PrintWriter class used to write contents of studentList to specified file
FileWriter fwStream = new FileWriter("newCustomers.txt");
BufferedWriter bwStream = new BufferedWriter(fwStream);
PrintWriter pwStream = new PrintWriter(bwStream);
for(i=0;i<noOfCustomers;i++)
pwStream.println("Account Id = "+customerList.getId());
pwStream.println("Name = "+customerList[i].getName());
pwStream.println("Address = "+customerList[i].getAddress());
pwStream.println("DOB = "+customerList[i].getBirthdate());
pwStream.println("Phone Number = "+customerList[i].getPhone());
pwStream.printf("Account Balance = %.2f\n", customerList[i].getBalance());
pwStream.println("Account Type = "+customerList[i].getAccType());
if(customerList[i].getAccType().equals("Fixed"))
pwStream.println("Fixed Daily Interest = "+((Account3)customerList[i]).getFixed());
pwStream.println();
n++;
//Closure of stream
pwStream.close();
System.out.println(+n+" records written.");
catch(IOException e)
System.out.println("IO error!");
System.exit(0);
//Deletes specified record from list
public static void deleteRecord(int id)
int i;
i=locate(id);
if(i==200)
//checking if account to be deleted does not exist
System.out.println("Error: no account with the id of "+id+" found!");
//if account exists
else
while(i<noOfCustomers)
customerList[i] = customerList[i+1];
i++;
System.out.println("Account Id: "+id+" has been deleted");
--noOfCustomers;
//Updates the accounts
public static void update(double interest)
int i,j,k;
double custBalance,addition=0;
for(i=0;i<noOfCustomers;i++)
if(customerList[i] instanceof Account1)
for(j=0;j<30;j++)
addition=customerList[i].getBalance()*interest;
custBalance=customerList[i].getBalance()+addition;
customerList[i].setBalance(custBalance);
else if(customerList[i] instanceof Account2)
continue;
else if(customerList[i] instanceof Account3)
for(j=0;j<30;j++)
addition=customerList[i].getBalance()*((Account3)customerList[i]).getFixed();
custBalance=customerList[i].getBalance()+addition;
customerList[i].setBalance(custBalance);
else
System.out.println("Account type not defined");
System.out.println("The updated balances are: \n");
for(k=0;k<noOfCustomers;k++)
System.out.printf("Name = %s\n", customerList[k].getName());
System.out.printf("Account Balance = %.2f\n", customerList[k].getBalance());
System.out.println();
/* ================== Additional methods ==================== */
/* Bubblesort method to sort the customerList in ascending alphabetical
order according to customer's name */
public static void bubbleSort(Customer[] x)
int pass, index;
Customer tempValue;
for(pass=0; pass<noOfCustomers-1; pass++)
for(index=0; index<noOfCustomers-1; index++)
if(customerList[index].getName().compareToIgnoreCase(customerList[index+1].getName()) > 0)
tempValue = x[index];
x[index] = x[index+1];
x[index+1]= tempValue;
/* Method used to check for duplicated ids in array */
public static boolean checkDuplicate(int id)
int i;
for(i=0;i<noOfCustomers;i++)
if(id == customerList[i].getId())
System.out.println("Account Id = "+id+" already exists");
System.out.println();
return true;
}return false;
/* Method to seach for account id in array */
public static int locate(int id)
int j;
for(j=0;j<noOfCustomers;j++)
if(customerList[j].getId()==id)
return j;
j=200;
return j;
import java.util.Scanner;
public class Customer
/* The following private variables are declared so that the data is only
accessible to its own class,but not to any other class, thus preventing
other classes from referring to the data directly */
protected int id;
protected String name,address,birthdate,phone,accType;
protected double balance;
// Null constructor of Customer
public Customer()
id = 0;
name = null;
address = null;
birthdate = null;
phone = null;
balance = 0;
accType = null;
/* The following statements with the keyword this activates the Customer
(int id, String name String address, String birthdate, String phone, double
balance) constructor that has six parameters of account id, name, address,
date of birth, phone number, account balance and assign the values of the
parameters to the instance variables of the object */
public Customer(int id, String name, String address, String birthdate, String phone, double balance, String accType)
//this is the object reference that stores the receiver object
this.id = id;
this.name = name;
this.address = address;
this.birthdate = birthdate;
this.phone = phone;
this.balance = balance;
this.accType = accType;
/* The following get methods getId(), getName(), getAddress(), getBirthdate(),
getPhone(), getBalance() return the values of the corresponding instance
properties */
public int getId()
return id;
public String getName()
return name;
public String getAddress()
return address;
public String getBirthdate()
return birthdate;
public String getPhone()
return phone;
public double getBalance()
return balance;
public String getAccType()
return accType;
/* The following set methods setId(), setName(), setAddress(), setBirthdate(),
setPhone and setBalance() set the values of the corresponding instance
properties */
public void setId (int custId)
id = custId;
public void setName(String custName)
name = custName;
public void setAddress (String custAddress)
address = custAddress;
public void setBirthdate (String custBirthdate)
birthdate = custBirthdate;
public void setPhone (String custPhone)
phone = custPhone;
public void setBalance (double custBalance)
balance = custBalance;
public void setAccType (String custAccType)
accType = custAccType;
class Account1 extends Customer
public Account1(int id, String name, String address, String birthdate, String phone, double balance, String accType)
super(id,name,address,birthdate,phone,balance,accType);
this.id = id;
this.name = name;
this.address = address;
this.birthdate = birthdate;
this.phone = phone;
this.balance = balance;
this.accType = accType;
class Account2 extends Customer
public Account2(int id, String name, String address, String birthdate, String phone, double balance, String accType)
super(id,name,address,birthdate,phone,balance,accType);
this.id = id;
this.name = name;
this.address = address;
this.birthdate = birthdate;
this.phone = phone;
this.balance = balance;
this.accType = accType;
class Account3 extends Customer
protected double fixed=0;
public Account3(int id, String name, String address, String birthdate, String phone, double balance, String accType, double fixed)
super(id,name,address,birthdate,phone,balance,accType);
this.id = id;
this.name = name;
this.address = address;
this.birthdate = birthdate;
this.phone = phone;
this.balance = balance;
this.accType = accType;
this.fixed = fixed;
public double getFixed()
return fixed;
Example of a customers.txt
Account Id = 123
Name = Matt Damon
Address = 465 Ripley Boulevard, Oscar Mansion, Singapore 7666322
DOB = 10-10-1970
Phone Number = 790-3233
Account Balance = 405600.00
Account Type = Fixed
Fixed Daily Interest = 0.05
Account Id = 126
Name = Ben Affleck
Address = 200 Hunting Street, Singapore 784563
DOB = 25-10-1968
Phone Number = 432-4579
Account Balance = 530045.00
Account Type = Saving
Account Id = 65
Name = Salma Hayek
Address = 45 Mexican Boulevard, Hotel California, Singapore 467822
DOB = 06-04-73
Phone Number = 790-0000
Account Balance = 2345.00
Account Type = Checking
Account Id = 78
Name = Phua Chu Kang
Address = 50 PCK Avenue, Singapore 639798
DOB = 11-08-64
Phone Number = 345-6780
Account Balance = 0.00
Account Type = Checking
Account Id = 234
Name = Zoe Tay
Address = 100 Blue Eyed St, Singapore 456872
DOB = 15-02-68
Phone Number = 456-1234
Account Balance = 600.00
Account Type = Saving1) When you post code, please use[code] and [/code] tags as described in Formatting tips on the message entry page. It makes it much easier to read.
2) Don't just post a huge pile of code and ask, "How do I make this work?" Ask a specific question, and post just enough code to demonstrate the problem you're having.
3) Don't just write a huge pile of code and then test it. Write a tiny piece, test it. Then write the piece that will work with or use the first piece. Test that by itself--without the first piece. Then put the two together and test that. Only move on to the next step after the current step produces the correct results. Continue this process until you have a complete, working program.
Maybe you are looking for
-
Xslt transform problem on Sun AS 8PE
Hi, I have following xslt: <xsl:call-template name="CustomerFilter"> <xsl:with-param name="custFilterPath" select="CustomerFilter"/> </xsl:call-template> <xsl:template name="CustomerFilter"> <xsl:param name="custFilterPath"/> <xsl:text>Cust
-
Can Vendor Master be copied in different Co Codes
Hi All, Can Vendor Master be copied in different Co Codes. Actually we have a requirement of Vendors for cross company code....How can I go about...Please advice ............... Regards, Rounak
-
PPPoE problem - solution for review
I'm posting this to save others the search after I troubleshot a painful issue, which wiser types may be able to clarify the background. Equipment: DLink DSL 504T Gen II; MBP 2008; AEBSdual-n 2009 Problem: Set up new AEBSdual-n, set up security, PPPo
-
My IPod touch 4 and went to vertical lines. It is not responding.
My Ipod touch 4g froze while in the Facebook app. A few minutes later vertical lines were all that is on the screen (gray, aqua, green, black). Itunes and the computer do not even "see" it when I connected. The IPod is warm to the touch too. I hav
-
Hello, Scope: JVM error during initial install of SAP HANA Studio Developer Edition v1.00.80, Win86/32bit Source: installation files pulled from HANA Studio tab at https://hanadeveditionsapicl.hana.ondemand.com/hanadevedition/, which is a link from t