Results 1 to 13 of 13
- 03-09-2013, 10:58 AM #1
Member
- Join Date
- Nov 2012
- Posts
- 27
- Rep Power
- 0
setting a boolean field when being read from a file
i need help when i am reading in a file one of the tokens is either "yes" or "no" , i need to set the boolean field to true if it is yes.
and false if it is no. how do i do it ?
this is my code > public void readData(Scanner scanner)
{
group = scanner.next();
vehID = scanner.next();
regNo = scanner.next();
make = scanner.next();
model = scanner.next();
if(scanner.next().equals("yes"))
{
airCon = true; // where i have to change the boolean to true if it is yes
}
engineSize = scanner.nextDouble();
fuelType = scanner.next();
gearbox = scanner.next();
transmission = scanner.next();
mileage = scanner.nextInt();
dateFirstRegistered = scanner.next();
}
- 03-09-2013, 11:09 AM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Re: setting a boolean field when being read from a file
Why not do this instead?
kind regards,Java Code:airCon= scanner.next().equals("yes");
JosLast edited by JosAH; 03-09-2013 at 12:00 PM.
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 03-09-2013, 11:16 AM #3
Member
- Join Date
- Nov 2012
- Posts
- 27
- Rep Power
- 0
Re: setting a boolean field when being read from a file
changed it , but they are still all false in the array list when im storing it nothing is being changed
- 03-09-2013, 11:49 AM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Re: setting a boolean field when being read from a file
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 03-09-2013, 11:57 AM #5
Member
- Join Date
- Nov 2012
- Posts
- 27
- Rep Power
- 0
Re: setting a boolean field when being read from a file
its reading the yes and no which is what i want , but how do i store that in the boolean field ??
- 03-09-2013, 12:00 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
- 03-09-2013, 12:06 PM #7
Member
- Join Date
- Nov 2012
- Posts
- 27
- Rep Power
- 0
Re: setting a boolean field when being read from a file
changed it and it keeps saying false . is there anything in the constuctor that i should change
- 03-09-2013, 12:47 PM #8
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Re: setting a boolean field when being read from a file
When people rob a bank they get a penalty; when banks rob people they get a bonus.
- 03-09-2013, 12:56 PM #9
Member
- Join Date
- Nov 2012
- Posts
- 27
- Rep Power
- 0
Re: setting a boolean field when being read from a file
heres the code (all)
Java Code:import java.util.*; public class Vehicle { // instance variables - replace the example below with your own private String group,vehID, regNo, make,model,fuelType,gearbox,transmission,dateFirstRegistered; private boolean airCon; private double engineSize; private int mileage; /** * Constructor for objects of class Vehicle */ public Vehicle() { // initialise instance variables group = null; vehID = null; regNo = null; make = null; } public String getGroup() { return group; } public String getVehicleID() { return vehID; } public String getRegestrationNumber() { return regNo; } public String getMakeOfVehicle() { return make; } public void displayDetails() { System.out.println(make + model + " Group: " + group + " Vehicle ID: " + vehID); System.out.println(" Air Conditioning or Climate Control : " + airCon); System.out.println(" Engine Size : " + engineSize + " Fuel : " + fuelType); System.out.println(" Gearbox : " + gearbox + " Transmission : " + transmission); System.out.println(" Mileage : " + mileage + " Date First Registered : " + dateFirstRegistered); } public void readData(Scanner scanner) { group = scanner.next(); vehID = scanner.next(); regNo = scanner.next(); make = scanner.next(); model = scanner.next(); String yes = scanner.next(); System.out.println(yes); engineSize = scanner.nextDouble(); fuelType = scanner.next(); gearbox = scanner.next(); transmission = scanner.next(); mileage = scanner.nextInt(); dateFirstRegistered = scanner.next(); } }
- 03-09-2013, 02:24 PM #10
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Re: setting a boolean field when being read from a file
In your readData( ... ) method you're not setting your airCon member variable anywhere ...
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 03-09-2013, 09:31 PM #11
Member
- Join Date
- Nov 2012
- Posts
- 27
- Rep Power
- 0
Re: setting a boolean field when being read from a file
what like airCon = scanner.next(); or next Boolean
- 03-10-2013, 08:42 AM #12
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Re: setting a boolean field when being read from a file
Don't guess; if you'd read the API documentation for the Scanner class you could've read that a String representation of boolean value is "true" or "false"; that's no what you want. Also, read my original reply again; it answers your question (but as usual it is ignored).
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 03-11-2013, 12:37 AM #13
Member
- Join Date
- Nov 2012
- Posts
- 27
- Rep Power
- 0
Similar Threads
-
Read Complex XML and write the data to a fixed field length flatfile
By SindhuP in forum XMLReplies: 1Last Post: 09-06-2012, 11:53 AM -
Boolean.True and Boolean.False, why do some people use these?
By Pojahn_M in forum New To JavaReplies: 3Last Post: 09-13-2011, 12:01 AM -
Boolean methods & how to read this in plain English
By bigsonny in forum New To JavaReplies: 6Last Post: 06-19-2011, 09:27 PM -
how to read openproj(Projity) file i.e. ,POD file(Project Management file)
By mahendra.athneria in forum New To JavaReplies: 0Last Post: 02-11-2009, 09:53 AM -
how to insert date field read from Excel using JExcel to database
By saran123 in forum JDBCReplies: 1Last Post: 10-10-2008, 08:47 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks