import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
public class AccountArrays
{
public static void main(String [] args)
{
int newId; string newName;
Customer newCust;
System.out.println("Please enter filename");
Scanner scan = new Scanner(System.in);
String fileName = scan.next();
}
Customer [] custlist = Customer[10];
try{
Scanner filescan = new Scanner (fileName);
while (filescan.hasNext())
{
newID = filescan.nextInt();
newName = filescan.nextLine();
newCust = new Customer(newID, newName);
custlist [ndx] = newCust;
ndx ++;
}
}
catch(Exception e)
{
System.out.println("File Error")
}
}
public void searchcut (String searchname, Customer[]csutlist[])
{
int i=0
boolean isfound = false;
while(i<custlist.length())&&(!isfound))
{
if (searchname.equals(custliast[i].getname()))
isfound = true;
else
i++
if (isfound)
System.out.println("Id is" + custlist[i].getID();
else
System.out.println("Not found");
}
}
5 Replies - 216 Views - Last Post: 03 April 2012 - 07:43 AM
#1
Writing Objects to An Array and a Search Method - Won't Compile
Posted 03 April 2012 - 06:42 AM
Not sure why this won't compile....an error keeps popping up at the start of the error handling 'try'
Replies To: Writing Objects to An Array and a Search Method - Won't Compile
#2
Re: Writing Objects to An Array and a Search Method - Won't Compile
Posted 03 April 2012 - 06:56 AM
I can't follow the logic of this. Your main method gets a file name and then just exits the program.
Edit - take out the bracket above your array, and see if that works. Right now it think's you're trying to make a method called try.
Edit - take out the bracket above your array, and see if that works. Right now it think's you're trying to make a method called try.
This post has been edited by nunc: 03 April 2012 - 06:58 AM
#3
Re: Writing Objects to An Array and a Search Method - Won't Compile
Posted 03 April 2012 - 07:02 AM
On line 14 you have an extra curly brace.
Edit - ninja'd
Edit - ninja'd
This post has been edited by Ryano121: 03 April 2012 - 07:02 AM
#4
Re: Writing Objects to An Array and a Search Method - Won't Compile
Posted 03 April 2012 - 07:23 AM
Thank You...it worked...
Can u say why the search method isn't working?
Can u say why the search method isn't working?
public void searchcut (String searchname, Customer[]csutlist[])
{
int i=0
boolean isfound = false;
while(i<custlist.length()&&(!isfound))
{
if (searchname.equals(custliast[i].getname()))
isfound = true;
else
i++
if (isfound)
System.out.println("Id is" + custlist[i].getID();
else
System.out.println("Not found");
}
}
#5
Re: Writing Objects to An Array and a Search Method - Won't Compile
Posted 03 April 2012 - 07:35 AM
This:
public void searchcut (String searchname, Customer[]csutlist[])
is not how you pass an array to a method. Change to:
public void searchcut (String searchname, Customer[] csutlist )
public void searchcut (String searchname, Customer[]csutlist[])
is not how you pass an array to a method. Change to:
public void searchcut (String searchname, Customer[] csutlist )
#6
Re: Writing Objects to An Array and a Search Method - Won't Compile
Posted 03 April 2012 - 07:43 AM
Thank you....it worked...
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote



|