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: 80% (5 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...
-
Kane, CPA, is auditing Star Wholesaling Companys financial statements and is about to perform substantive audit procedures on Stars trade accounts payable balances. After obtaining an understanding...
-
The direct labour rate variance for January is a. $300 F b. $300 U c. $400 F d. $400 U A company makes bulk cookies sold in restaurants. The following standards have been developed: Standard Inputs...
-
The following transactions of Happy Music Company occurred during 2012 and 2013: Requirement 1. Record the transactions in Happy Music Companys journal. Explanations are notrequired. 2012 Purchased a...
-
(2 points) The types of civil cases that a private citizen can file in federal district courts include: cases in which any state in the United States is one of the parties. cases between citizens of...
-
Bob and carol was divorced and Bob no longer wanted to keep the $100,000 life insurance policy he had previously purchased. He sold the policy to his friend Bill for $10,000 and Bill named himself...
-
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...
-
Consider a three-year project with the following information: initial fixed asset investment \($375,000;\) straight-line depreciation to zero over the three-year life; zero salvage value; price...
-
If the sales were $270,000, the variable costs $330000 and fixed costs $40000. calculate the profit or loss.
-
Outline three strategies you could use to utilize emotional intelligence to increase team performance in line with organizational objectives. Outline three strategies you could implement to encourage...
-
NU Inc. is not paying any dividends now. However, NU Inc. is planning to start paying annual dividends 3 years from now. The first dividend will be $2. The growth rate will be 6% for 6 years and then...
-
Mark is planning to retire in 20 years with a retirement fund of $500,000. He is also considering investing in an annuity that promises a 5% yearly return, compounded annually. Future value needed:...
-
Sheffield Corporation's December 31, 2025, trial balance includes the following accounts: Investment in Starling Common Stock, $65,000; Retained Earnings, $147,000; Treasury Stock, $5,000;...
-
Researchers at Harris Interactive wondered if there was a difference between males and females in regard to some common annoyances. They asked a random sample of males and females, the following...
-
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...
-
You should be able to arrive at the audited balance by referring to the balance sheet and the adjustments, if any, that you may be able to identify based on available findings and information. If...
-
me now ROI and Investment Decisions Allard, Inc., presented two years of data for its Frozen Foods Division and its Canned Foods Division. Frozen Foods Division: Year 1 Year 2 Sales $35,200,000...
-
Question 3 Conversion costs include: I. Depreciation of the production facility II. Direct labor III. Indirect labor IV. Indirect materials A. I only OB. I, II, and III OC. I, III and IV O D. All of...
Study smarter with the SolutionInn App