Ask your own question, for FREE!
Computer Science 15 Online
OpenStudy (ellecullen):

Homework help on coding exercises. I did two exercises from Java AU Naturel book for homework. I need help fixing my program. I did exercises 7.6 and 7.13

OpenStudy (ellecullen):

My code: public class PersonnelDataV3 { private Buffin itsFile = new Buffin ("workers.txt"); //private String itsLastN = null; // assuming all workers have a last name private int itsSizeOfWorkers = 100; // supposing we have 100 workers, /** Add to Listing 7.3 coding to tell whether the workers are in increasing * order of names as determined by compareTo. * A sequence of less than two values is considered to be in increasing order in any case. * */ public String findEarliestWorker() { Worker answerSoFar = new Worker (itsFile.readLine()); //1 if (answerSoFar.getName() == null) //2 return "no workers!"; //3 else //4 { Worker data = new Worker (itsFile.readLine()); //5 while (data.getName() != null) //6 { if (data.compareTo (answerSoFar) < 0) //7 answerSoFar = data; //8 data = new Worker (itsFile.readLine()); //9 } //10 return answerSoFar.getName() + " is first of all."; //11 } //12 } /** Here, I added another method, where Ican use compareTo to see if workers are increaseing * in order of names , the compareTo is in charge of that. * */ public String ifOrdered(Object par) { String comparison = ""; String LastN = null; Worker one = (Worker) par; Worker two = (Worker) par; int w = 0; // w for workers // when we have less than 100 workers while (w < itsSizeOfWorkers) { if ( one.LastN.compareTo (two.LastN) < 0) { comparison = false; } else if (one.LastN == null || two.LastN == null) { comparison = true; } // adding onemore value to the current w++; } return comparison; } }

OpenStudy (ellecullen):

Here is the ListingIhave to add to an the wording of the exercise 7.13 Listing: public class PersonnelData { private Buffin itsFile = new Buffin ("workers.txt"); /** Read a file and return the name of the Worker that is * alphabetically first. */ public String findEarliestWorker() { Worker answerSoFar = new Worker (itsFile.readLine()); //1 if (answerSoFar.getName() == null) //2 return "no workers!"; //3 else //4 { Worker data = new Worker (itsFile.readLine()); //5 while (data.getName() != null) //6 { if (data.compareTo (answerSoFar) < 0) //7 answerSoFar = data; //8 data = new Worker (itsFile.readLine()); //9 } //10 return answerSoFar.getName() + " is first of all."; //11 } //12 } //====================== }

OpenStudy (ellecullen):

Exercise 7.13** Add to Listing 7.3 coding to tell whether the workers are in increasing order of names as determined by compareTo. A sequence of less than two values is considered to be in increasing order in any case.

OpenStudy (ellecullen):

The PersonnelDataV3 means that it is exercise 7.13

OpenStudy (e.mccormick):

OK, what probelm are you having with it?

OpenStudy (ellecullen):

I keep getting an error message saying that it can't fins a symbol. I tried defining it..

OpenStudy (e.mccormick):

Which symbol?

OpenStudy (e.mccormick):

See, part of the probnlem is that with a regular pase of the code I can't test it. When I copy it, al I get is this: public class PersonnelDataV3 { private Buffin itsFile = new Buffin ("workers.txt"); //private String itsLastN = null; // assuming all workers have a last name private int itsSizeOfWorkers = 100; // supposing we have 100 workers, /** Add to Listing 7.3 coding to tell whether the workers are in increasing * order of names as determined by compareTo. * A sequence of less than two values is considered to be in increasing order in any case. * */ public String findEarliestWorker() { Worker answerSoFar = new Worker (itsFile.readLine()); //1 if (answerSoFar.getName() == null) //2 return "no workers!"; //3 else //4 { Worker data = new Worker (itsFile.readLine()); //5 while (data.getName() != null) //6 { if (data.compareTo (answerSoFar) < 0) //7 answerSoFar = data; //8 data = new Worker (itsFile.readLine()); //9 } //10 return answerSoFar.getName() + " is first of all."; //11 } //12 } /** Here, I added another method, where Ican use compareTo to see if workers are increaseing * in order of names , the compareTo is in charge of that. * */ public String ifOrdered(Object par) { String comparison = ""; String LastN = null; Worker one = (Worker) par; Worker two = (Worker) par; int w = 0; // w for workers // when we have less than 100 workers while (w < itsSizeOfWorkers) { if ( one.LastN.compareTo (two.LastN) < 0) { comparison = false; } else if (one.LastN == null || two.LastN == null) { comparison = true; } // adding onemore value to the current w++; } return comparison; } } A real mess. You need to put \(\text{```}\) on a blank line above and below the code block. That is the accent on the ~ key. Then it formats the code: ``` public class Blaa(some stuff) { code; code; code; } ``` See how that keeps the formatting? it also makes it copy and paste properly.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!