4. Write an interface ObjectWithTwoParameters which has a method specification: double area (double d1, double d2) which returns the area of a particular object. Write three classes RectangleClass, TriangleClass, and CylinderClass which implement the interface you created. Also, write a demo class which creates objects of RectangleClass, TriangleClass, and CylinderClass and call the corresponding methods

Answers

Answer 1

Answer:

The java program for the given scenario is as follows.

import java.util.*;

//interface with method area

interface ObjectWithTwoParameters

{

double area (double d1, double d2);

}

class RectangleClass implements ObjectWithTwoParameters

{

//overriding area()

public double area (double d1, double d2)

{

return d1*d2;

}

}

class TriangleClass implements ObjectWithTwoParameters

{

//overriding area()

public double area (double d1, double d2)

{

return (d1*d2)/2;

}  

}

class CylinderClass implements ObjectWithTwoParameters

{

public double area (double d1, double d2)

{

return ( 2*3.14*d1*d1 + d2*(2*3.14*d1) );

}

}

public class Test

{

public static void main(String[] args)

{

//area displayed for all three shapes

ObjectWithTwoParameters r = new RectangleClass();

double arear = r.area(2, 3);

System.out.println("Area of rectangle: "+arear);

ObjectWithTwoParameters t = new TriangleClass();

double areat = t.area(4,5);

System.out.println("Area of triangle: "+areat);

ObjectWithTwoParameters c = new CylinderClass();

double areac = c.area(6,7);

System.out.println("Area of cylinder: "+areac);

}

}

OUTPUT

Area of rectangle: 6.0

Area of triangle: 10.0

Area of cylinder: 489.84

Explanation:

1. The program fulfils all the mentioned requirements.

2. The program contains one interface, ObjectWithTwoParameters, three classes which implement that interface, RectangleClass, TriangleClass and CylinderClass, and one demo class, Test, containing the main method.

3. The method in the interface has no access specifier.

4. The overridden methods in the three classes have public access specifier.

5. No additional variables have been declared.

6. The test class having the main() method is declared public.

7. The area of the rectangle, triangle and the cylinder have been computed as per the respective formulae.

8. The interface is similar to a class which can have only declarations of both, variables and methods. No method can be defined inside an interface.

9. The other classes use the methods of the interface by implementing the interface using the keyword, implements.

10. The object is created using the name of the interface as shown.

ObjectWithTwoParameters r = new RectangleClass();


Related Questions

Double any element's value that is less than minValue. Ex: If minValue = 10, then dataPoints = {2, 12, 9, 20} becomes {4, 12, 18, 20}.
import java.util.Scanner;
public class StudentScores {
public static void main (String [] args) {
Scanner scnr = new Scanner(System.in);
final int NUM_Points = 4;
int[] dataPoints = new int[NUM_POINTS];
int minValue;
int i;
minValue = scnr.nextInt();
for (i = 0; i < dataPoints.length; ++i) {
dataPoints[i] = scnr.nextInt();
}
/* Your solution goes here */
for (i = 0; i < dataPoints.length; ++i) {
System.out.print(dataPoints[i] + " ");
}
System.out.println();
}
}

Answers

Answer:

Following are the code to this question:

for(i=0;i<dataPoints.length;++i) //define loop to count array element  

{

if(dataPoints[i]<minValue) // define condition that checks array element is less then minValue

{

dataPoints[i] = dataPoints[i]*2; //double the value

}

}

Explanation:

Description of the code as follows:

In the given code, a for loop is declared, that uses a variable "i", which counts all array element, that is input by the user. Inside the loop and if block statement is used, that check array element value is less then "minValue", if this condition is true.  So, inside the loop, we multiply the value by 2.

Suppose that a program's data and executable code require 1,024 bytes of memory. A new section of code must be added; it will be used with various values 70 times during the execution of a program. When implemented as a macro, the macro code requires 73 bytes of memory. When implemented as a procedure, the procedure code requires 132 bytes (including parameter-passing, etc.), and each procedure call requires 7 bytes. How many bytes of memory will the entire program require if the new code is added as a procedure? 1,646

Answers

Answer:

The answer is 1646

Explanation:

The original code requires 1024 bytes and is called 70 times ,it requires 7 byte and its size is 132 bytes

1024 + (70*7) + 132 = 1024 + 490 +132

= 1646

write the steps to insert picture water mark​

Answers

Answer:

Is there a picture of the question?

Explanation:

Evaluati urmatoarele expresii


5+2*(x+4)/3, unde x are valoare 18


7/ 2*2+4*(5+7*3)>18


2<=x AND x<=7 , unde x are valoare 23


50 %10*5=


31250/ 5/5*2=

Answers

Answer:

A) 22 ⅓

B) 111>18

C) There is an error in the expression

D) 25

E) 62500

Question:

Evaluate the following expressions

A) 5 + 2 * (x + 4) / 3, where x has a value of 18

B) 7/2 * 2 + 4 * (5 + 7 * 3) & gt; 18

C) 2 <= x AND x<= 7, where x has value 23

D) 50% 10 * 5 =

F) 31250/5/5 * 2 =

Explanation:

A) 5 + 2 * (x + 4) / 3

x = 18

First we would insert the value of x

5 + 2 * (x + 4) / 3

5 + 2(18 + 8) / 3

Then we would evaluate the expression by applying BODMAS : This stands for Bracket, Of, Division, Multiplication, addition and subtraction.

= 5 + 2(26) / 3

= 5 + 52/3

= 5 + 17 ⅓

= 22 ⅓

B) 7/2 * 2 + 4 * (5 + 7 * 3) > 18

we would evaluate the expression by applying BODMAS : This stands for Bracket, Of, Division, Multiplication, addition and subtraction.

7/2 * 2 + 4 * (5 + 7 * 3) >18

= 7/2 × 2 + 4× (5 + 7 × 3)>18

= (7×2)/2 + 4× (5+21) >18

= 14/2 + 4(26) >18

= 7 + 104 >18

= 111>18

C) 2 <= x AND x<= 7, where x has value 23

There is an error in the expression

D) 50% of 10 * 5

we would evaluate the expression by applying BODMAS : This stands for Bracket, Of, Division, Multiplication, addition and subtraction.

The 'of' expression means multiplication

= 50% × 10×5

= 50% × 50

50% = 50/100

=50/100 × 50

= 1/2 × 50

= 25

F) 31250/5/5 * 2

The expression has no demarcation. Depending on how it is broken up, we would arrive at different answers. Let's consider:

31250/(5/5 × 2)

Apply BODMAS

= 31250/[5/(5 × 2)]

= 31250/(5/10)

= 31250/(1/2)

Multiply by the inverse of 1/2 = 2/1

= 31250 × (2/1)

= 62500

An attacker compromises the Washington Post's web server and proceeds to modify the homepage slightly by inserting a 1x1 pixel iframe that directs all website visitors to a webpage of his choosing that then installs malware on the visitors' computers. The attacker did this explicitly because he knows that US policymakers frequent the website. This would be an example of a ___________ attack.

Answers

Answer:

Water holing is the correct answer to this question.

Explanation:

Waterholing:-

It is a kind of attack in which the attacker detects the sites that the targets of the group frequently access and then afflicts the sites with the ransomware. Which afflicts selected representatives of the target group.

The watering hole assault is a data breach wherein the individual attempts to infiltrate a particular demographic of end-users by harming sites reported to be visited by team members. The aim is to compromise a specific target data and gain network access at the perpetrator's place of work.

what should i name my slideshow if its about intellectual property, fair use, and copyright

Answers

Answer:

You should name it honest and sincere intention

Explanation:

That is a good name for what you are going to talk about in your slideshow.

Caches are important to providing a high-performance memory hierarchy to processors. Below is a list of 32-bits memory address references given as word addresses. 0x03, 0xb4, 0x2b, 0x02, 0xbf, 0x58, 0xbe, 0x0e, 0xb5, 0x2c, 0xba, 0xfd For each of these references identify the binary word address, the tag, and the index given a direct mapped cache with 16 one-word blocks. Also list whether each reference is a hit or a miss, assuming the cache is initially empty.

Answers

Answer:

See explaination

Explanation:

please kindly see attachment for the step by step solution of the given problem.

Trace the complete execution of the MergeSort algorithm when called on the array of integers, numbers, below. Show the resulting sub-arrays formed after each call to merge by enclosing them in { }. For example, if you originally had an array of 5 elements, a = {5,2,8,3,7}, the first call to merge would result with: {2, 5} 8, 3, 7 ← Note after the first call to merge, two arrays of size 1 have been merged into the sorted subarray {2,5} and the values 2 and 5 are sorted in array a You are to do this trace for the array, numbers, below. Be sure to show the resulting sub-arrays after each call to MergeSort. int[] numbers = {23, 14, 3, 56, 17, 8, 42, 18, 5};

Answers

Answer:

public class Main {

public static void merge(int[] arr, int l, int m, int r) {

int n1 = m - l + 1;

int n2 = r - m;

int[] L = new int[n1];

int[] R = new int[n2];

for (int i = 0; i < n1; ++i)

L[i] = arr[l + i];

for (int j = 0; j < n2; ++j)

R[j] = arr[m + 1 + j];

int i = 0, j = 0;

int k = l;

while (i < n1 && j < n2) {

if (L[i] <= R[j]) {

arr[k] = L[i];

i++;

} else {

arr[k] = R[j];

j++;

}

k++;

}

while (i < n1) {

arr[k] = L[i];

i++;

k++;

}

while (j < n2) {

arr[k] = R[j];

j++;

k++;

}

printArray(arr, l, r);

}

public static void sort(int[] arr, int l, int r) {

if (l < r) {

int m = (l + r) / 2;

sort(arr, l, m);

sort(arr, m + 1, r);

merge(arr, l, m, r);

}

}

static void printArray(int[] arr, int l, int r) {

System.out.print("{");

for (int i = l; i <= r; ++i)

System.out.print(arr[i] + " ");

System.out.println("}");

}

public static void main(String[] args) {

int[] arr = {23, 14, 3, 56, 17, 8, 42, 18, 5};

sort(arr, 0, arr.length - 1);

}

}

Explanation:

See answer

Other Questions
Exercise 24-5 Payback period computation; even cash flows LO P1 Compute the payback period for each of these two separate investments: A new operating system for an existing machine is expected to cost $520,000 and have a useful life of six years. The system yields an incremental after-tax income of $150,000 each year after deducting its straight-line depreciation. The predicted salvage value of the system is $10,000. A machine costs $380,000, has a $20,000 salvage value, is expected to last eight years, and will generate an after-tax income of $60,000 per year after straight-line depreciation. what is the main factor in the poor health of undeveloped countries?a. too few doctors b. more imports than exportsc. industrial pollutiond. infectious disease help please math please ASAP WILL GIVE BRAINLESTBefore the discovery of the microscope, Linnaeus could classify organisms only into two kingdoms. More kingdoms were introduced later. What characteristic of science does this show? It is permanent. It is changeable. It is always accurate. It is based on predictions. 2. You deposit $1200 into a bank account. Every year that accounts increase by 15 %.a) Identify whether this an Exponential Growth or Decay function and write the equation of thefunction Which article of the Constitution explains how amendments are made? Article I Article II Article V Article VI help please 2 divided by one over 3 the awnser is a fraction what is monopoly? Please explain NEED ASAP WILL MARK BRAINLIEST ON TIMERA student determines that she used 0.0665 mol of sodium hydroxide (NaOH) to completely titrate 25.00 mL of sulfuric acid solution (H2SO4). What is the molarity of the sulfuric acid?0.00131 M0.00262 M1.31 M2.62 M Which are common elements found in procedural texts? Check all that apply.bcllist of necessary materialsa place for commentsa section of definitionsa page of success storiesa series of steps Why did the South use a defensive strategy? anybody know where to find this packet at online ? On March 31, 20Y9, the balances of the accounts appearing in the ledger of Royal Furnishings Company, a furniture store, are as follows: Accounts Receivable $ 170,000 Accumulated Depreciation-Building 750,000 Administrative Expenses 435,000 Building 3,500,000 Cash 80,000 Common Stock 300,000 Cost of Goods Sold 5,500,000 Dividends 175,000 Interest Expense 15,000 Inventory 980,000 Notes Payable 250,000 Office Supplies 20,000 Retained Earnings 1,987,000 Salaries Payable 8,000 Sales 8,245,000 Selling Expenses 575,000 Store Supplies 90,000 A. Prepare a multiple-step income statement for the fiscal year ended March 31, 20Y9. Be sure to complete the statement heading. Refer to the information given in the exercise and to the list of Labels and Amount Descriptions provided for the exact wording of the answer choices for text entries. A colon (:) will automatically appear if it is required. For those boxes in which you must enter subtracted or negative numbers use a minus sign. B. What is a major advantage of the multiple-step income statement over the single-step income statement? Whit Catering uses two measures of activity, jobs and meals, in the cost formulas in its budgets and performance reports. The cost formula for catering supplies is $380 per month plus $94 per job plus $11 per meal. A typical job involves serving a number of meals to guests at a corporate function or at a host's home. The company expected its activity in October to be 20 jobs and 216 meals, but the actual activity was 19 jobs and 221 meals. The actual cost for catering supplies in October was $4,790. The catering supplies in the flexible budget for October would be closest to: HELP ASAP PLEASE!!! The myth of Sigurd the Volsung is filled with treachery and death.Which characters commit harmful deeds? Does each have a justifiablemotive? Is any character completely evil? What effect do characterswho commit evil deeds for good reasons have on the epic? How wouldthe effect be different if they were completely evil? Swim Suits Unlimited is in a highly seasonal business, and the following summary balance sheet data show its assets and liabilities at peak and off-peak seasons (in thousands of dollars): Peak Off-Peak Cash $50 $30 Marketable securities 0 20 Accounts receivable 40 20 Inventories 100 50 Net fixed assets 500 500 Total assets $690 $620 Payables and accruals $30 $10 Short-term bank debt 50 0 Long-term debt 300 300 Common equity 310 310 Total claims $690 $620 From this data we may conclude that a. Swim Suits' current asset financing policy is relatively aggressive; that is, the company finances some of its permanent assets with short-term discretionary debt. b. Without cash flow data, we cannot determine the aggressiveness or conservatism of the company's current asset financing policy. c. Swim Suits follows a relatively conservative approach to current asset financing; that is, some of its short-term needs are met by permanent capital. d. Swim Suits' current asset financing policy calls for exactly matching asset and liability maturities. e. Without income statement data, we cannot determine the aggressiveness or conservatism of the company's current asset financing policy. If water were a nonpolar molecule, how would its properties be different? How does disease affect blood pressure which is equivalent to sin^-1 ( sqrt 3/2 )? Give your answerGive your answer in radians. 4. The batteries on electric vehicles are recharged using electricity from either a wall socket or dedicated chargingunit.A) O TrueB) O False