• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

accessing the last part of the file?

 
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I have the majors file which looks like Computer Programming, true, CPT207,IST567,CPT187.... I got the major name, and whether its a certificate or not, but I also need to show the classes required for the majors.
here are the main two classes

Major:
Theres my add required courses method, and the array list they need to go into


catalog:
Theres the load majors method where im guessing I have to add something to get the courses from the file, but not sure what.


and just in case here is the output. the first half is ok because that is my other list. The bottom half is the major name, and whether its true or false but I still need the required courses for each major



ACC-100,Basic Accounting,3
ACC-101,Accounting Principles I,3
ACC-102,Accounting Principles II,3
ACC-111,Accounting Concepts,3
ACC-112,Organizational Accounting,3
ACC-124,Individual Tax Procedures,3
ACC-150,Payroll Accounting,3
ACC-201,Intermediate Accounting I,3
ACC-202,Intermediate Accounting II,3
ACC-203,Intermediate Accounting III,3
ACC-221,Corporate Taxation,3
ACC-226,Tax Audit and Research,3
ACC-240,Computerized Accounting,3
ACC-245,Accounting Applications,3
ACC-260,Auditing,3
ACC-265,Not-For-Profit Accounting,3
ACC-275,Selected Topics in Accounting,3
BUS-101,Introduction to Business,3
BUS-112,Service Management Systems,3
BUS-121,Business Law I,3
BUS-136,Compensation and Benefits,3
BUS-176,International Marketing,3
BUS-210,Intro to e-Commerce Business,3
BUS-220,Business Ethics,3
BUS-250,Intro to Int'l Business,3
CPT-101,Introduction to Computers,3
CPT-102,Basic Computer Concepts,3
CPT-114,Computers and Programming,3
CPT-167,Intro to Programming Logic,3
CPT-172,Microcomputer Database,3
CPT-174,Microcomputer Spreadsheets,3
CPT-179,Microcomputer Word Processing,3
CPT-187,Object-Oriented Logic & Design,3
CPT-209,Computer Systems Management,3
CPT-210,Computer Resource Management,3
CPT-220,e-Commerce,3
CPT-237,Advanced Java Programming,3
CPT-238,Internet Scripting,3
CPT-242,Database,3
CPT-244,Data Structures,3
CPT-262,Advanced Web Page Publishing,3
CPT-264,Systems and Procedures,3
CPT-268,Computer End-User Support,3
CPT-270,Advanced Microcomputer Apps,3
CPT-282,Information Systems Security,3
CPT-283,PHP Programming I,3
CPT-290,Multimedia Concepts & Apps,3
IST-161,Intro to Network Administration,3
IST-162,Introduction to Workstation Network,3
IST-163,Internet Server Netwk Config,3
IST-164,Implementing Windows Network,3
IST-165,Implementing Windows Directory,3
IST-166,Network Fundamentals,3
IST-190,LINUX Essentials,3
IST-191,LINUX System Administration,3
IST-192,LINUX Network Applications,3
IST-196,Cloud Storage Fundamentals,3
IST-198,Cloud Essentials,3
IST-201,Cisco Internetworking Concepts,3
IST-202,Cisco Router Configuration,3
IST-203,Advanced Cisco Router Config,3
IST-204,Cisco Troubleshooting,3
IST-205,Cisco Advanced Routing,3
IST-207,Cisco Multilayer Switching,3
IST-220,Data Communications,3
IST-239,Datum and JavaScript,3
IST-250,Network Management,3
IST-253,LAN Service and Support,3
IST-260,Network Design,3
IST-263,Windows Network Security,3
IST-268,Computer Forensics,3
IST-269,Digital Forensics,3
IST-272,Relational Database,3
IST-286,Technical Support Internship I,3
IST-287,Tech Support Internship II,3
IST-291,Fund of Network Security I,3
IST-293,IT and Data Assurance I,3
IST-294,IT and Data Assurance II,3
MAT-110,College Algebra I,3
MAT-120,Probability and Statistics,3
MGT-101,Principles of Management,3
MGT-110,Office Management,3
MGT-120,Small Business Management,3
MGT-121,Small Business Operations,3
MGT-201,Human Resource Management,3
MGT-210,Employee Selection & Retention,3
MGT-230,Managing Information Resources,3
MGT-235,Production Management,3
MGT-240,Management Decision Making,3
MGT-250,Situational Supervision,3
MGT-255,Organizational Behavior,3
MGT-270,Managerial Communication,3
LOG-125,Transportation and Logistics,4
LOG-215,Supply Chain Management,4
LOG-240,Purchasing Logistics,4
ECO-210,Macroeconomics,3
ECO-211,Microeconomics,3
BAF-101,Personal Finance,3
LOG-235,Traffic Management,4
edu.tridenttech.Biggs.Cpt.project1.Course@55f96302edu.tridenttech.Biggs.Cpt.project1.Course@3d4eac69 // etc Deleted because the long line makes the post difficult to read.
Computer Programming, true
Database, false
Accounting, true
Information Systems, true
Supply Chain Management, true
Network Administration, true
A+/Network+ Technician, false



 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't display lists of things in getXXX methods. Return the value (or better still a defensive copy of it).
You have some iffy naming; you have a boolean called isDegree and a method called getIsDegree. A getXXX method returning a boolean shou‍ld usually start is, but isIsDegree would sound dreadful.

Apart from those minor points, I am not quite sure what the problem is. It is not usually possible to read the end of a text file. That might be possible for a random access file, but not as far as I know for a text file.
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From what was suggested to me was that something else has to be done in the load majors method. All I was told was I would need another for loop to get to them.
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, for starters, your Course class could do with overriding toString() so it at least outputs something useful.
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please explain more. I can't see why you need an additional loop. In view of the contents of the file, why are you using a List<String> rather than using the Course class?
Consider giving the Course class a constructor which takes a String in the form
ACC-100,Basic Accounting,3
and does all the splitting for itself. Consider changing the regex you are splitting on to ,\s? which will permit but not require space(s) after the comma. You will have to escape the \: ",\\s?"
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thats why im confused. I was told that in the major class the addRequiredCourse method would take a course as an argument.
So addRequiredCourse(CPT172) or something along those lines. Then in the load major method they said I would use another for loop to walk through everything and call addRequiredCourse
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this is my course class by the way

 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You shou‍ld give all those fields private access.
You can probably create a Major class as a subclass of Course. It might need no fields or methods, only a constructor. If you are clever with the toString method, you can get it to display Major.... rather than Course....
 
Saloon Keeper
Posts: 10687
85
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Cody Biggs wrote:Thats why im confused. I was told that in the major class the addRequiredCourse method would take a course as an argument.
So addRequiredCourse(CPT172) or something along those lines. Then in the load major method they said I would use another for loop to walk through everything and call addRequiredCourse


The design of the loop needed to add the required courses will depend on the structure of the text file that you are reading. Can you copy and paste several lines from your text file and post it?
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:Can you copy and paste several lines from your text file and post it?


I believe the quoted text in the first post is the contents of the file.
 
Carey Brown
Saloon Keeper
Posts: 10687
85
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:

Carey Brown wrote:Can you copy and paste several lines from your text file and post it?


I believe the quoted text in the first post is the contents of the file.


A Major has requiredCourses, where in your text files is that relationship captured?
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The text file looks: Computer programming, true, CPT 230, CPT 270...and so on. First index prints major, then prints whether it is a certificate degree or not, then required courses follows that. I have been thinking though...if I did add another for loop in my loadMajor method, but have it start at index 2 where the required courses would be. That way I can walk through the file with the for loop and add the courses to my addRequiredCourse method.

So like

That would follow my code where the first 2 indexes are added to the array list...on my phone
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry about the above post. On my phone so it didn't have the code tags, thought I remembered what they looked like, but guess not.

(Fixed 'em for you -- Paul C)
 
Carey Brown
Saloon Keeper
Posts: 10687
85
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Cody Biggs wrote:The text file looks: Computer programming, true, CPT 230, CPT 270...and so on. First index prints major, then prints whether it is a certificate degree or not, then required courses follows that. I have been thinking though...if I did add another for loop in my loadMajor method, but have it start at index 2 where the required courses would be. That way I can walk through the file with the for loop and add the courses to my addRequiredCourse method.

So like

That would follow my code where the first 2 indexes are added to the array list...on my phone


Close, but...

Gives you have an array called classMajors and you want to loop through that, not "majors".
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right because of the split I only added the major name and whether it's true or false to majors. Courses would still in the array.
 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds as though you had a design problem. Go back and write down what you are going to do with courses, and what difference it makes if they are majors. You cannot sort that sort of thing out in code; you must work out what you are going to do before you write any code.
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
SO this would be my new loadMajor..so I called addrequired major, and now I need to put in my requiredCourse array list. How would I do that? addrequiredCourse is just a method not a list or anything...so where did all those courses get stored when I called the addrequiredCourse method?

 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My major class just in case

 
Carey Brown
Saloon Keeper
Posts: 10687
85
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
 
Carey Brown
Saloon Keeper
Posts: 10687
85
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Cody Biggs wrote:SO this would be my new loadMajor..so I called addrequired major, and now I need to put in my requiredCourse array list. How would I do that? addrequiredCourse is just a method not a list or anything...so where did all those courses get stored when I called the addrequiredCourse method?


Those courses didn't get stored anywhere, and they won't untill you finish writing the addrequiredCourse() method.
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thats where im confused. im use to reading from a file, and adding it into the list in all one big thing. Not adding part of the file in one place, and the rest in another.
The majCourse is a another major object I made...I wasnt sure if I used the same major object I did with the split would mess up the for loop in anyway.

So for my addrequiredcourse method I obviously need to add it to my requirecourses array list, but how? Theres no other list to read in the array list...unless it would be similiar code to that of the for loop in the loadMjaors method
 
Carey Brown
Saloon Keeper
Posts: 10687
85
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Cody Biggs wrote:thats where im confused. im use to reading from a file, and adding it into the list in all one big thing. Not adding part of the file in one place, and the rest in another.
The majCourse is a another major object I made...I wasnt sure if I used the same major object I did with the split would mess up the for loop in anyway.

If you think about it, you just created a new Major object and assigned it to a reference "major". Now "major" has everything it needs except the required courses, so you'll need to add the required courses to that particular Major object referred to by "major".

So for my addrequiredcourse method I obviously need to add it to my requirecourses array list, but how? Theres no other list to read in the array list...unless it would be similiar code to that of the for loop in the loadMjaors method

Yes, exactly the same, use add().
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sooo how would that work? Would it be the entire load method code or just the new for loop? If it was all of it I would have to read the file in the addrequiredcourse method which I dont want to do, and if it was just the for loop that wouldnt work because I would have to use the same major object as the while loop reading in the list. Besides of all that I would have to make all new variables because I cant use the same ones from another class right?
 
Carey Brown
Saloon Keeper
Posts: 10687
85
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so I would use major instead of majCourse
the loop would start int i =2; i < classMajors.length;i++) because  thats where the first course would be
the point of the loop would be to start at the index courses are located and continue calling addrequiredcourse until the list is finished
                     
I dont see how you can use any of this in addrequiredcourse method in the other class.
I cant use classMajors.length in the other class
so I dont see how I can add the courses to my array list in the other class
if the courses arent stored anywhere after calling addrequiredcourse

 
Campbell Ritchie
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am getting all confused; how would you add a course the list of Majors, and how are you going to add required courses to the Major course, without using code? Explain that and you will find it easier to add prerequisite course to Majors.
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't want to add the courses to the major list. I want to get the courses out of the major list which start at index 2. So from what I was told was I have to make another for loop starting at index 2 and call the addRequiredCourse method. Then I'm suppose to did them to my array list in the other class.

I'm confused on how am I suppose to add them to the array list if my addRequiredCourse method doesn't save them. I can't use the same code in my load majors method. So how am I suppose to get  the courses from addRequiredCourse which aren't saved to my other class and add them to the array list
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's try this: without using any programming terms, what is it you're trying to do?  (So for instance, don't worry about if you have to use a loop or call a certain method.)
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote:Let's try this: without using any programming terms, what is it you're trying to do?  (So for instance, don't worry about if you have to use a loop or call a certain method.)



So I want to get the courses out of the major list, and display them next to the corresponding major.
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good.  So now, the major list is a text file with records that look like this?

Computer Programming, true, CPT207,IST567,CPT187
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Right
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The major is the first field, whether the major is certified is the second, and the courses are the third and greater fields in the file.

Courses have a major, and majors can be certified or not.  Does this suggest a data structure to you?  (that is, how the objects might be related).

The text file is a CSV file.  Do you have a way to read that?  Can you use a third-party library?  If not, can we assume that commas only separate fields?  That is, we don't have records (lines in the file) like:

"Planes, Trains, and Automobiles", false, course, course, course
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The way we were told to read it in was the method would take a string for the file name, then in the main class it looks like loadMajors("whatever the path to the file is") just using the scanner
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You were told this by your Instructor?  So you are given a method called loadMajors("path/to/file"), or you have to write it?  If it is given to you, what does it return?
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well thats the way he taught us. So this is what it looks like



and this is my main where I call the file to load

 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you write the LoadMajors method?
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All right.  Back to the data structure.  A major has a certificated boolean.  So far so good.  But what about a course has a major?  Since you want to list courses and their majors, does this suggest a data structure to you?
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ehh. That's how they are related? I mean they would both be part of the major object that's created
 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So a Major class would have a List of Course objects?  Or would you have a List of Courses that have a Major object?
reply
    Bookmark Topic Watch Topic
  • New Topic