I'll try to explain this as clearly as I can. I am trying to narrow down my code for an assignment by turning three of the classes used into a package that the program will access through an import statement. Here is my original code:
import javax.swing.JOptionPane;
public class AssignmentTen
{
public static void main (String[] args)
{
System.out.println();
int num = Integer.parseInt(args[0]);
int eNumber;
String input2;
String input3;
String input4;
String input5;
String input6;
int input7;
int input8;
int input9;
int input10;
Employee[] employees = new Employee[num];
for (int i = 0; i < num; i++)
{
eNumber = getInt ("Enter Employee Number:");
input2 = getString ("Enter Employee First Name:");
input3 = getString ("Enter Employee Last Name:");
input4 = getString ("Enter Employee Street:");
input5 = getString ("Enter Employee City:");
input6 = getString ("Enter Employee State (Initials):");
input7 = getInt ("Enter Employee Zip Code (5 Digits):");
input8 = getInt ("Enter Employee Hire Month (MM):");
input9 = getInt ("Enter Employee Hire Day (DD):");
input10 = getInt ("Enter Employee Hire Year(YYYY):");
Name name = new Name(input2, input3);
Address address = new Address (input4, input5, input6, input7);
Date hireDate = new Date (input8, input9, input10);
employees[i] = new Employee (eNumber, name, address, hireDate);
System.out.println("#" + employees[i].empNumber + "\n" + employees[i].empName + "\n" + employees[i].empAddress + "\nHire Date: " + employees[i].empHireDate + "\n\n");
}
}
public static int getInt(String paramString)
{
String str = JOptionPane.showInputDialog(paramString);
return Integer.parseInt(str);
}
public static String getString(String paramString)
{
String str = JOptionPane.showInputDialog(paramString);
return str;
}
}
class Employee
{
Number empNumber;
Name empName;
Address empAddress;
Date empHireDate;
public Employee(Number empNumber, Name empName, Address empAddress, Date empHireDate)
{
this.empNumber = empNumber;
this.empName = empName;
this.empAddress = empAddress;
this.empHireDate = empHireDate;
}
}
class Name
{
String firstName;
String lastName;
Name(String first, String last)
{
firstName = first;
lastName = last;
}
public String toString()
{
return firstName + " " + lastName;
}
}
class Address
{
String eStreet;
String eCity;
String eState;
int eZipCode;
Address(String street, String city, String state, int zipCode)
{
eStreet = street;
eCity = city;
eState = state;
eZipCode = zipCode;
}
public String toString()
{
return eStreet + " " + eCity + " " + eState + " " + eZipCode;
}
}
class Date
{
int month;
int day;
int year;
Date(int eMonth, int eDay, int eYear)
{
month = eMonth;
day = eDay;
year = eYear;
}
public String toString()
{
return month + "/" + day + "/" + year;
}
}
I need to take the Name class, the Address class, and the Date class and put them into a package called util. First of all, I organize all of my java programs in a folder called My Java Programs (C:\MyJavaPrograms) as I was instructed to do so. To create what I think is supposed to be the package, I copied each class and put them into their own individual file, I put the statement 'package.util' at the top, and then I named them Name.java, Address.java, and Date.java and I put them in a folder called util, which is located in C:\MyJavaPrograms.
Afterwards, I put the statement 'import util.*;' at the top of my original code and put it in C:\MyJavaPrograms. For one reason or another, the file won't compile. I've already done a lot of googling for my problem, including reading up on this, which doesn't help me, at least to the extent that I understand what is wrong.
I suspect that there is a problem with my classpath, although I do not have any idea what I can do to fix it. If it helps with figuring out the problem, I do know that I can't use the javac command in the command prompt without going to this thread and typing in one of the responses.
Ideally, I would want to compile my new assignment and have it do exactly what the code I posted at the top of this question would do now, except it does it while utilizing a pacakage with the extra classes. I would really appreciate it if someone could send me in the right direction.