I have a Project class and I want that to hold projects that I want to be doing. I’m a jewelry and want to essentially have a file from each project I have going on. Each file has, right now, a name, date started, deadline date, and description. I want to call the printPro() I just don’t know how.
The Project class looks like this:
public class Project {
String name;
int date;//start date
int fDate;//finish date
String description;
public Project(String gName, int gDate, int gFDate, String gDescription){
// mean they are the ones that are given.
}
public void receivedName(String receivedName) {
name= receivedName;
}
public void receivedDate(int receivedDate) {
date= receivedDate;
}
public void receivedFDate(int receivedDate) {
fDate= receivedDate;
}
public String returnName(){
return name;
}
public int returnDate(){
return date;
}
public int returnFDate(){
return fDate;
}
public String returnDescription(){
return description;
}
public String printPro(int index){
String tempString = ("Project Name: " + name +
"\nStart Date: " + date +
"\nFinish Date: " + fDate + "\nDescription: " + description);
return tempString;
}
public void printProject(int index){
System.out.println("Project Name: " + name +
"\nStart Date: " + date +
"\nFinish Date: " + fDate + "\nDescription: " + description);
}
}
Right now all I have is everything running though a console. I was going to build a Window later when I learn how to create and import a text file. Anyway here is the code for the console:
public class Top{
Math help = new Math();//Creates a Math object
People person = new People();//Creates a People object
// Project nProject= new Project();
ArrayList<Project> mProject = new ArrayList<Project>();
Project[] storeProject; //Tried to create an array of Projects I could just add to.
Project[] storeTempProject;
StringTest sTest = new StringTest(); // This is my class to use the console.
String choice; //Temporary strings
String redo;
public static void main (String [] args){
// ============Project Menu =========================
private void project() {
System.out.println("ADD, DELETE, REVIEW, or BACK?");
sTest.stringReader();
choice = sTest.getString();
if (sTest.test(choice, "add")){
System.out.println("What would you like to call this project?");
sTest.stringReader();
String name = sTest.getString();
System.out.println("When would you like it to start?");
sTest.stringReader();
String startDate = sTest.getString();
int sDate = Integer.parseInt(startDate);
System.out.println("When would you like it to end?");
sTest.stringReader();
String finishDate = sTest.getString();
int fDate = Integer.parseInt(finishDate);
System.out.println("What is the description of your project?");
sTest.stringReader();
String projectDescription = sTest.getString();
mProject.add(new Project(name, sDate, fDate, projectDescription));
}
}
I took out some unnecessary stuff out of my code so it doesn’t bog down this question. If you need more info let me know. I have been searching for an hour now so I’m assuming this doesn’t work and I need to do it another way.
I’m not entirely sure on your question, but maybe this what you are after:
You can call methods on the elements of your ArrayList like this:
To display the first one just do:
Will return the first Project in the ArrayList. To return second just change the argument to ‘get’ to 1. You should be able to work out how to get the rest.