Consider the following code, which is a portion of SomeClass. The instance variable is initialized by...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Consider the following code, which is a portion of SomeClass. The instance variable is initialized by the constructor. The method is supposed to add the value passed as a parameter with the instance variable and update the value of the instance variable. However, there is a problem. Re-write this code, without renaming any variable names, to resolve the problem. (6 points) private int number; public void addNumbers (int number) { number = number + number; System.out.println("The local variable is: " + number); System.out.println("The instance variable is: " + number); Q2. Consider the following segment of code: SomeClass someObject1= new SomeClass(23); SomeClass someObject2 = new SomeClass (98.6); SomeClass someObject3 = new SomeClass(23, 98.6); Write the SomeClass class based on the statements above. Include any instance variables and the complete constructors, including the assignment of variables. (Other code exists in SomeClass but will not be written at this time.) (6 points) ■Q3. Write a class method called findRemainder that will accept two integer values and calculate and return their remainder after division. (6 points) ■Q4. Consider the following statement: double hours = someObject.convertToHours (18.4) Write a partial class that shows a class constant and an instance method. Write an instance method that converts minutes to hours using a class constant representing the number of minutes in one hour. The value passed to the method represents the amount of time in minutes. (6 points) Q5. Write two methods to calculate the tip for a meal eaten at a restaurant. One method has been partially provided for you. A server for an individual table at a restaurant is usually tipped between 15 and 20% of the cost of the meal. However, some restaurants don't leave the amount of the tip up to the customer and charge a fixed percentage of the meal. First, complete the calcTip method shown below that is based on the cost of the meal and percent of the customer's choice. Then, write a complete overloaded method called calcTip, which calculates the tip at the rate of 17.5%. (6 points) //post condition: returns the amount of the tip public double calcTip(double percent, double mealCost) { } //complete the code for the first method here //second method to be written here. Consider the following code, which is a portion of SomeClass. The instance variable is initialized by the constructor. The method is supposed to add the value passed as a parameter with the instance variable and update the value of the instance variable. However, there is a problem. Re-write this code, without renaming any variable names, to resolve the problem. (6 points) private int number; public void addNumbers (int number) { number = number + number; System.out.println("The local variable is: " + number); System.out.println("The instance variable is: " + number); Q2. Consider the following segment of code: SomeClass someObject1= new SomeClass(23); SomeClass someObject2 = new SomeClass (98.6); SomeClass someObject3 = new SomeClass(23, 98.6); Write the SomeClass class based on the statements above. Include any instance variables and the complete constructors, including the assignment of variables. (Other code exists in SomeClass but will not be written at this time.) (6 points) ■Q3. Write a class method called findRemainder that will accept two integer values and calculate and return their remainder after division. (6 points) ■Q4. Consider the following statement: double hours = someObject.convertToHours (18.4) Write a partial class that shows a class constant and an instance method. Write an instance method that converts minutes to hours using a class constant representing the number of minutes in one hour. The value passed to the method represents the amount of time in minutes. (6 points) Q5. Write two methods to calculate the tip for a meal eaten at a restaurant. One method has been partially provided for you. A server for an individual table at a restaurant is usually tipped between 15 and 20% of the cost of the meal. However, some restaurants don't leave the amount of the tip up to the customer and charge a fixed percentage of the meal. First, complete the calcTip method shown below that is based on the cost of the meal and percent of the customer's choice. Then, write a complete overloaded method called calcTip, which calculates the tip at the rate of 17.5%. (6 points) //post condition: returns the amount of the tip public double calcTip(double percent, double mealCost) { } //complete the code for the first method here //second method to be written here.
Expert Answer:
Answer rating: 100% (QA)
1 public class SomeClass private int number public SomeClassint number thisnumber number public void addNumbersint number thisnumber thisnumber number SystemoutprintlnThe local variable is number Syst... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Following is a portion of management's report on internal control by Milacron Inc. in 2004. Item 9A. Controls and Procedures Disclosure Controls and Procedures (Interim Analysis) Disclosure controls...
-
Consider the following code fragment, taken from some package:
-
Write a paper on Health-Care Fraud
-
An upward force of 20 kN is applied at the top of a tripod as depicted in Figure. Determine the forces in the legs of the tripod. 24m. 0,8 m
-
The General Fund of the village of Oxendine transferred $150,000 to a Special Revenue Fund; $35,000 to a Capital Projects Fund; and $25,000 to Enterprise Fund A. In the same reporting period,...
-
Mr. Prestages foot and lower leg were caught in a combine manufactured by defendant SperryNew Holland. He and his wife sued Defendant for damages arising out of the accident. Their first cause of...
-
At December 31, 2013, Crawford Company had a balance of $15,000 in Allowance for Doubtful Accounts. During 2014, Crawford wrote off accounts totaling $14,100. One of those accounts ($1,800) was later...
-
3. Write a test program which has a static method that takes a shape argument and displays information about it (its radius, its area and volume, if applicable). Writing this to display information...
-
Janice Morgan, age 24, is single and has no dependents. She is a freelance writer. In January 2021, Janice opened her own office located at 2751 Waldham Road, Pleasant Hill, NM 88135. She called her...
-
9. [5] Consider the following variation of PARTITION (for Quicksort) due to N. Lomuto. To partition A[p..r], this version grows two regions, A[p..i] and A[i+1..j] such that every element in the first...
-
Side EF of square DEFG has a length of 2 cm and is also the radius of circle F. What is the area of the entire shaded region? Provide all evidence of your calculations. D 2 cm
-
Which diversity and culture wield too much influence and yield ambiguity and diminished productivity as a result? If so, where is that point and why? If not, why not?
-
A female patient with atrial fibrillation has the following lab results: Hemoglobin of 11 g/dl, a platelet count of 150,000, an INR of 2.5, and potassium of 2.7 mEq/L. Which result is critical and...
-
4. A 3 MeV photon interacts with a lead nucleus and creates an electron-positron pair. The elec- tron and positron travel perpendicular to the initial direction of travel of the photon. Find the...
-
Consider the following. y=x y = 2-x --2 7 5 4 X 2 (a) Find the area of the region by integrating with respect to x. 9/2 (b) Find the area of the region by integrating with respect to y. X
-
For the data in Exercise 17-19, use the FIFO method to summarize total costs to account for, and assign these costs to units completed and transferred out, and to units in ending work in process....
-
What is the value of the double variable x after each of the following statements is executed? a) x = Math.Abs(7.5); b) x = Math.Floor(7.5); c) x = Math.Abs(0.0); d) x = Math.Ceiling(0.0); e) x =...
-
Create the GUI in Fig. 14.1 (you do not have to provide functionality). Figure 14.1 Calculator GUI 4 1 9, 6. 3. 2.
-
Fill in the blanks in each of the following statements: a) ___________are used to document an app and improve its readability. b) A decision can be made in a C# app with a(n) ___________. c)...
-
What is the minimum speed for orbiting Earth in a close orbit? What is the maximum speed? What happens above this speed?
-
What connection did Newton make between a falling apple and the Moon?
-
Why will a projectile that moves horizontally at 8 km/s follow a curve that matches the curvature of Earth?
Study smarter with the SolutionInn App