Question
1. Consider the following code, which is a portion of SomeClass. The instance variable is initialized by the constructor. The method is supposed to multiply
1. Consider the following code, which is a portion of SomeClass. The instance variable is initialized by the constructor. The method is supposed to multiply the value passed as a parameter by 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. private int number; public void multiplyNumbers(int number) { number = number * number; System.out.println("The local variable is: " + number); System.out.println("The instance variable is: " + number); }
2. 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.)
3. Write a class method called subtractThese that will accept two integer values and calculate and return their difference.
4. 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.
5. Write two methods to calculate the tip for a pizza delivery. One method has been partially provided for you. It is customary to tip the pizza delivery person $1.50 per pizza or 10% of the total cost. Complete the following pizzaTip method shown below to tip based on the number of pizzas. Then write an overloaded method to calculate the tip based on the total cost of the pizzas. //post condition: return the amount of the tip public double pizzaTip(int numPizzas) { //complete the code for the first method here } //second method to be written here
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started