Hi all! I am extremely new to java and to computer programming in general so I greatly appreciate all our help. Here's my problem, I am trying to write a program that reads in a basic text file with some names and some numbers, and inputs the given information into an array list. Each line of the text file is supposed to serve as a separate object in the array list. The major problem for me is that I am required to use 2 classes to do this. One class must be the main class and the other class is supposed to hold Get and Set methods for each piece of information in each object in the ArrayList, and I am very clueless as to how to use get and set methods. Here is the code that I have so far....i know the Driver class is where the get and set methods are supposed to go...i just dont know what they are supposed to look like or how to do them. Please help me if you can, I am very desperate! Thank you so much in advance.
Here is the main code:
import java.util.ArrayList;
import java.util.Scanner;
import java.util.*;
import java.io.*;
import java.awt.*;
public class C_Part {
/********************************************************************
Creates the C_Part Class
********************************************************************/
public static void main (String[]args)
{
Scanner scan = new Scanner(new File(args[0]));
Scanner scanner = null;
ArrayList <Driver> drivers = new ArrayList <Driver> ();
if (args.length != 1)
{
System.out.println ("The name of the file to be read for " +
" the report is expected.");
System.exit(1);
}
try
{
File file = new File (args[0]);
scanner = new Scanner (file);
}
catch(IOException ioe)
{
System.out.println ("The file " + args[0] + " does not exist");
System.exit(1);
}
int count = 0;
while (scanner.hasNext()){
scanner.nextLine();
count++;
}
for (int i=0; i<count; i++){
String Fname = scanner.next();
String Lname = scanner.next();
double fares = scanner.nextDouble();
double gaspaid = scanner.nextDouble();
double distance = scanner.nextDouble();
double gallons = scanner.nextDouble();
Driver d = new Driver(Fname, Lname, fares,
gaspaid, distance, gallons);
drivers.add(d);
}
d.setfirstname(Fname);
d.setlastname(Lname);
}
}
And here is the Driver that is supposed to hold get and sets!
public class Driver
{
public String Fname;
public String Lname;
private double fares;
private double gaspaid;
private double distance;
private double gallons;
public Driver (){
getFname(String firstname);
setFname(String firstname);
}
}