Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Array Loading
- From: leo_peo@xxxxxxxxx (Leonard Fernandes)
- Subject: Array Loading
- Date: Thu, 30 Mar 2000 13:41:51 -0500
This is a multi-part message in MIME format.
------=_NextPart_000_00CE_01BF9A4D.B43B2EC0
Content-Type: multipart/alternative;
boundary="----=_NextPart_001_00CF_01BF9A4D.B43B2EC0"
------=_NextPart_001_00CF_01BF9A4D.B43B2EC0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi,=20
I was just wondering if you could help me in loading this array of =
objects. I get a NullPointerException while doing this.
=20
The code is included as an attachment.
=20
Thanks in advance,
=20
Leonard
------=_NextPart_001_00CF_01BF9A4D.B43B2EC0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">
<HTML>
<HEAD>
<META content=3Dtext/html;charset=3Diso-8859-1 =
http-equiv=3DContent-Type><!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 =
HTML//EN">
<META content=3D'"MSHTML 4.72.3612.1706"' name=3DGENERATOR>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT color=3D#000000 face=3D"Courier New" =
size=3D2>Hi,</FONT> </DIV>
<DIV><FONT color=3D#000000 face=3D"Courier New" size=3D2>I was just =
wondering if you=20
could help me in loading this array of objects. I get a =
NullPointerException=20
while doing this.</FONT></DIV>
<DIV><FONT color=3D#000000 face=3D"Courier New" =
size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2>The code is included as an=20
attachment.</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New" size=3D2>Thanks in advance,</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT> </DIV>
<DIV><FONT face=3D"Courier New" =
size=3D2>Leonard</FONT></DIV></BODY></HTML>
------=_NextPart_001_00CF_01BF9A4D.B43B2EC0--
------=_NextPart_000_00CE_01BF9A4D.B43B2EC0
Content-Type: application/octet-stream;
name="compDist.java"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="compDist.java"
import java.io.*;
public class compDist
{
buyerList buyDistArray[] = new buyerList[100];
sellerList sellDistArray[] = new sellerList[100];
String vendorplace;
String transtype;
public compDist()
{
System.out.println("Buyers and sellers added");
}
public compDist(String place,String type)
{
this.vendorplace = place;
this.transtype = type;
}
public void loadBuyArray()
{ int x = 0;
String b = "";
try
{
while(b!="q"||b!="Q" && x<100)
{
int j = x+1;
System.out.println("Enter Buyer No: "+j);
DataInputStream input = new DataInputStream(new
BufferedInputStream(System.in));
System.out.println("Enter Name:");
buyDistArray[x].name = input.readLine();
System.out.println("Enter Place of Residence:");
buyDistArray[x].place = input.readLine();
System.out.println("Enter City:");
buyDistArray[x].state = input.readLine();
System.out.println("Enter ZIP :");
buyDistArray[x].pin = input.readLine();
System.out.println("Enter Email Address:");
buyDistArray[x].email = input.readLine();
System.out.println("Enter Phone No:");
buyDistArray[x].phoneno = input.readLine();
x++;
System.out.println("Enter q to stop data entry:");
b = input.readLine();
}
}catch(IOException e)
{
e.printStackTrace();
}
}
public void loadSellArray()
{ int y = 0;
String s = "";
try
{
while(s!="q"||s!="Q" && y<100)
{
int p = y+1;
System.out.println("Enter Buyer No: "+p);
DataInputStream imput = new DataInputStream(new
BufferedInputStream(System.in));
System.out.println("Enter Name:");
sellDistArray[y].name = imput.readLine();
System.out.println("Enter Place of Residence:");
sellDistArray[y].place = imput.readLine();
System.out.println("Enter City:");
sellDistArray[y].state = imput.readLine();
System.out.println("Enter ZIP :");
sellDistArray[y].pin = imput.readLine();
System.out.println("Enter Email Address:");
sellDistArray[y].email = imput.readLine();
System.out.println("Enter Phone No:");
sellDistArray[y].phoneno = imput.readLine();
y++;
System.out.println("Enter q to stop data entry:");
s = imput.readLine();
}
}catch(IOException e)
{
e.printStackTrace();
}
}
public void listAllBuy()
{
String buyer;
String bprox;
for(int i=0;i<buyDistArray.length;i++)
{
System.out.print("Prospective Buyer");
System.out.println(buyDistArray[i].name);
System.out.print("Hailing From:");
System.out.println(buyDistArray[i].place);
System.out.print("State");
System.out.println(buyDistArray[i].state);
System.out.print("ZIP");
System.out.println(buyDistArray[i].pin);
System.out.print("E-mail");
System.out.println(buyDistArray[i].email);
System.out.print("Phone No.");
System.out.println(buyDistArray[i].phoneno);
}
}
public void listAllSell()
{
String seller;
String sprox;
for(int i=0;i<sellDistArray.length;i++)
{
System.out.print("Vandor Name");
System.out.println(buyDistArray[i].name);
System.out.print("Hailing From:");
System.out.println(buyDistArray[i].place);
System.out.print("State");
System.out.println(buyDistArray[i].state);
System.out.print("ZIP");
System.out.println(buyDistArray[i].pin);
System.out.print("E-mail");
System.out.println(buyDistArray[i].email);
System.out.print("Phone No.");
System.out.println(buyDistArray[i].phoneno);
}
}
}
class buyerList
{
final String type = "b";
String name;
String place;
String state;
String pin;
String email;
String phoneno;
int distance;
}
class sellerList
{
final String type = "s";
String name;
String place;
String state;
String pin;
String email;
String phoneno;
int distance;
}
------=_NextPart_000_00CE_01BF9A4D.B43B2EC0
Content-Type: application/octet-stream;
name="loadData.java"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="loadData.java"
import java.io.*;
public class loadData
{
public static void main(String args[])
{
compDist cD =3D new compDist();
String type;
try
{
DataInputStream in =3D new DataInputStream(new =
BufferedInputStream(System.in));
System.out.println("Enter \"b\" for buyer and \"s\" for seller");
type =3D in.readLine();
if(type.equals("b"))
{
cD.loadBuyArray();
cD.listAllBuy();
}
else
{=09
cD.loadSellArray();
cD.listAllSell();
}
}catch(IOException p)
{
p.printStackTrace();
}
}
} =09
------=_NextPart_000_00CE_01BF9A4D.B43B2EC0--
__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://im.yahoo.com
---
To unsubscribe, mail advanced-java-unsubscribe@xxxxxxxxxxxxxxxx
To get help, mail advanced-java-help@xxxxxxxxxxxxxxxx
- Follow-Ups:
- Array Loading
- From: Guy Scharf
- Array Loading
- Prev by Date: JavaRanch.com
- Next by Date: Question about "data hiding" OOP paradigm issue
- Previous by thread: JavaRanch.com
- Next by thread: Array Loading
- Index(es):