• Post Reply Bookmark Topic Watch Topic
  • New Topic

Challenge Program  RSS feed

 
Griffin Romain
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to demonstrate the replace, delete, insert, change options in Java, but I am having issues, here is my code. These options must be called into another class.



That is my main string. Here is my Tester.



If I could get some help that would be awesome.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We love to help, but "having issues" is not terribly clear. Can you be more specific - does it compile? Does it crash? Does it give wrong output (and if so, what output are you expecting?)? The more specific you can be, the easier it is to help you figure out the issue.
 
Campbell Ritchie
Marshal
Posts: 55793
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

There is some good stuff there, but it needs improvement.
Please explain what you mean by replace, delete, insert, change options. Do you mean to add and remove things from a List? Have you gone through any tutorials about Lists, e.g. this one?
Why have you got a static method called printBooks taking an array of students (should read Student) which doesn't seem to have anything to do with books? Why is the method static in the first place? Why are you calling an array “list”? That is a sure‑fire recipe for confusion. I think it has confused me into thinking you had a List.
What have you been taught about arrays? Do you know that they are always fixed length, but that it is usually easy to create an array of a different length? Do you know that you can always reassign an array element with the = operator? You seem to have made a good start with your methods. Don't pass lots of arguments to a method. Pass a few as possible, e.g. 1 Student rather than name and five qzs. Don't do so much in the methods to change the array. Have a findIndex method and use that index for replace or add methods. Don't lose the last item. Create an array 1 larger than the old array and copy the data into that.

You have a main() method far too long. You should create a class which contains the array and does all the printing.

Your student class has 5 fields with confusing names (qz1???) and one field with an obvious name (StudentName, though it should be studentName or better name), but the fields ought all to be private. You need to complete the getXXX methods (it would appear your IDE has filled in one of the methods already, but I am not convinced it got it right). Give the Student class a hasSameName method too. Checking the same name should be done inside the Student class. I think you will have to get the Student class beaten into submission before you use the array.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!