Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Consider the following code, which is a portion of SomeClass. The instance variable is initialized by the constructor. The method is supposed to add

 

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.

Step by Step Solution

3.54 Rating (168 Votes )

There are 3 Steps involved in it

Step: 1

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... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Visual C# How to Program

Authors: Paul J. Deitel, Harvey Deitel

6th edition

134601548, 134601793, 978-0134601540

More Books

Students also viewed these Programming questions

Question

Consider the following code fragment, taken from some package:

Answered: 1 week ago

Question

Write a paper on Health-Care Fraud

Answered: 1 week ago

Question

Explain and criticize the JamesLange theory of emotion.

Answered: 1 week ago