Rewrite the Course class in Listing 10.6 to add a clone method to perform a deep copy
Question:
Rewrite the Course class in Listing 10.6 to add a clone method to perform a deep copy on the students field.
Transcribed Image Text:
Listing 10.6 - Course.java public class Course i private String courseNane: private string ) students new string(1001; private int numberofstudents: public Course (String courselame) this.courselane - courseName; public void addstudent (String student) I studenta (numberorstudents) student: numberofstudents+ public Stringti getstudents () return students: public int getlumberorstudents () return numberofstudents; public string getCourselame () zeturn courselane; public void dropstudent (String st udent) II Left as an exercise in Exercise 9.9 The implementation listed above will crash if more than 100 students are added. The addStudent method should be rewriten as folows: public void addstudent (String student) ( 1f (numstudents < 100) I students (numberorstudents) - student: numberofstudents++ else System.out.printin ("Course is ful1"): Returning a reference to the students array is a serious security issue since the dient class is able to make modifications. The getStudent method should be rewritten as follows: public string 1 getstudents () ( Stringtl studentaCopy - new String(numberotstudents): Systen.arraycopy (atudents, 0 , studentsCopy, 0, numberofstudents) : return studentaCopy:
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 75% (4 reviews)
public class Exercise1313 Main method public static void mainString args Course1 course1 new Course1...View the full answer
Answered By
David Ngaruiya
i am a smart worker who concentrates on the content according to my clients' specifications and requirements.
4.50+
7+ Reviews
19+ Question Solved
Related Book For
Introduction To Java Programming And Data Structures Comprehensive Version
ISBN: 9780136520238
12th Edition
Authors: Y. Daniel Liang
Question Posted:
Students also viewed these Computer science questions
-
Rewrite the Course class in Listing 10.6. Use an ArrayList to replace an array to store students. Draw the new UML diagram for the class. You should not change the original contract of the Course...
-
A biology class has 32 students. Of these, 10 students are biology majors and 14 students are male. Of the biology majors, four are male. Find the probability that a randomly selected student is male...
-
The bags clone method creates a copy of an ArrayBag. As with other clone methods, adding or removing elements from the original bag will not affect the copy, nor vice versa. However, these elements...
-
Determine the resultant force and specify where it acts on thebeam measured from A . Assume F = 540 lb . Part A Determine the magnitude of theresultant force. Part B Determine the distance between A...
-
Each morning a student takes a shower that lasts 15 minutes, with a standard deviation of 4 minutes. Find an estimate of the probability that the student spends between 11 and 12 hours in the shower...
-
The mean monthly rent of students at Oxnard University is $875 with a standard deviation of $219. (a) John's rent is $1,325. What is his standardized z-score? (b) Is John's rent an outlier? (c) How...
-
Which of the following is an activity not usually associated with forensic accounting and fraud examination consulting and litigation support? 1. A. Assessing fraud risk associated with internal...
-
Effects of operating leverage on profitability Webster Training Services (WTS) provides instruction on the use of computer software for the employees of its corporate clients. It offers courses in...
-
6. Some particles (certain atomic nuclei, and certain mediating particles) have spin 1. This means that in a Stern-Gerlach experiment they yield three measurements: h, 0, -h. This means that now we...
-
The cash account for Pala Medical Co. at June 30, 20Y1, indicated a balance of $166,436. The bank statement indicated a balance of $195,688 on June 30, 20Y1. Comparing the bank statement and the...
-
A university posts its employees salaries at http:// liveexample.pearsoncmg.com/data/Salary.txt. Each line in the file consists of a faculty members first name, last name, rank, and salary (see...
-
Write a program that draws two filled circles with radius 15 pixels, centered at random locations, with a line connecting the two circles. The line should not cross inside the circles, as shown in...
-
The accounting for BANs depends on events subsequent to year-end. In anticipation of issuing of long-term bonds, a state issues $200 million of 60-day BANs to finance highway construction. It expects...
-
NewTech purchases computer equipment for $264,000 to use in operating activities for the next four years. It estimates the equipments salvage value at $28,000. rev: 07_27_2017_QC_CS-94103 Exercise...
-
Assuming riskless arbitrage opportunities do not exist, one cannot expect to have a return greater than the risk-free rate without taking on some risk. In order to obtain greater returns on...
-
Suppose your current monthly net salary is 1000 euros, presumably it should increase every year by 6.0% until your retirement (you are planning to retire exactly in 25 years from now, your planned...
-
Misty's gross pay is $770 per week. Misty has provided her TFN and claims the tax-free threshold. This week Misty goes on leave and is to be paid 6 weeks leave in advance. Misty is not eligible for...
-
what is the yield to maturity for a bond that matures in 15 years, is callable in 6 years ,has a coupon rate of 4.5% and a price of $995 and a call premium of $45?
-
(a) What is the energy of a pendulum (L = 1.0 m, m = 0.50 kg) oscillating with an amplitude of 5.0 cm? (b) The pendulum's energy loss (due to damping) is replaced in a clock by allowing a 2.0-kg mass...
-
The 2017 financial statements of the U.S. government are available at: https://www.fiscal.treasury.gov/fsreports/rpt/finrep/fr/fr_index.htm Use these to answer the following questions: a. Statement...
-
Modify Listing 14.21, ClockPane.java, to add the animation into this class and add two methods start() and stop() to start and stop the clock. Write a program that lets the user control the clock...
-
Write a program that animates a pendulum swinging, as shown in Figure 15.35. Press the UP arrow key to increase the speed and the DOWN key to decrease it. Press the S key to stop animation and the R...
-
Write a program that simulates car racing, as shown inFigure 15.34a. The car moves from left to right. When it hits the right end, it restarts from the left and continues the same process. You can...
-
The beta of firm A is 1.5 and the beta of firm B is 0.5. What is the difference in returns between firm A and B if the market risk premium is 6%?
-
Company ABC owns 1 0 0 % of Company DEF. Company ABC sells sneakers to wholesalers and retail stores. Company DEF manufactures sneaker boxes. Jeff is the only shareholder of Company ABC. During 2 0 2...
-
Submit a two - page ( maximum ) executive summary in which you document your recommendation of the top 3 problems / calculations ( identified with the chapter, number identification, and topic area )...
Study smarter with the SolutionInn App