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
-
Why is organizing such an important management function?
-
Completely impenetrable to the layperson, the ancient text was _______ even to experts in the field. a. Abstruse b. Unequivocal c. Opaque d. Lucid e. Incontrovertible f. Obtuse
-
What are two numbers that are 23 away from 0 ?
-
The management of Peterson Manufacturing Company has asked for your assistance in deciding whether to continue manufacturing a part or to buy it from an outside supplier. The part, called Tropica, is...
-
a consulting contract sold for $9000 which covers 6 month of service. With 40% chance receiving $1200 bonus. how much revenue to recognize under each method ? What if prb of bonus change to 60%?
-
Sam Easton started out as a real estate agent in Atlanta ten years ago. After working two years for a national real estate firm, he transferred to Dallas, Texas, and worked for another realty agency....
-
Explain how managers use planning techniques to evaluate opportunities and threats in the organization's environment and formulate the strategy?
-
Analyze Telstra's Twitter account using Leximancer and provide an overview of the result. please provide a picture of them (the result you get on the Leximancer website) as you analyze Telstra's...
-
Provide an alternate perspective on the advantages of using SWOTT over SWOT analysis. Identify an additional aspect of the environmental analysis not covered by SWOTT that would be important to...
-
The graph of y = f(x) is shown below. What are all of the real solutions of f(x) = o? 2 -10 14 4 9 8 10
-
2. Kofi is interested in the effect of the introduction of the Free Senior High School (Free -SHS) in the Ghana on the unemployment rate (Number of unemployed/ Labour force) and applies a...
-
Find the page in the slides, with the code below and the corresponding memory drawing. How many boxes are drawn and what is the total memory used (the sum of the sizes of those boxes)? struct node *...
-
Topic:Fixed Income investment outside US. The report is on 1.A comparison of the government and corporate bond markets between the US and XYZ (a country market of your choice) The comparison could...
-
The following exercises are not grouped by type. Solve each equation. x610x -9
-
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)...
-
On1 January 2006, F Limited commenced business selling goods on hire purchase. Under the _ terms of the agreements, an initial deposit of 20 per cent is payable on delivery, followed by four equal...
-
The financial statements of J. Foot Ltd are made up to 31 March in each year. Work on Contract 349 started on 1 July 2006 and completed on 31 January 2008. The total contract price was 580,000, but a...
-
Dundas Limited purchased a machine under a hire purchase agreement on 1 January 2008. The agreement provided for an immediate payment of 2,000, followed by five equal instalments of 3,056, each...
Study smarter with the SolutionInn App