1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
maks197457 [2]
3 years ago
12

Given the Solid class, extend it with:

Computers and Technology
1 answer:
andreev551 [17]3 years ago
6 0

Answer:

Following are the code to this question:

Explanation:

//For Solid:

public class Solid//defining a class Solid

{

private String myName;//defining a String variable

public Solid(String name)//defining parameterized constructor

{

myName = name;//holding String value in myName variable

}

public String getName()//defining getName method  

{

return myName;//return value of myName

}

public double volume()//defining method volume that overriden its subclass

{

return 0;//return value

}

public double surfaceArea()//defining method surfaceArea that overriden its subclass

{

return 0;//return value

}

}

//For RectangularPrism:

public class RectangularPrism extends Solid//defining a class RectangularPrism that inherits Solid

{

  protected double length,width,height;//defining double variable

RectangularPrism(String str,double l,double w,double h)//defining parameterized constructor

{

  super(str);//use super method

  this.length=l;//use this to hold value

  this.width=w;//use this to hold value

  this.height=h;//use this to hold value

}

public double volume()//defining volume method  

{

return length*width*height;//calculate and return volume value

}

public double surfaceArea()//defining a  method surfaceArea  

{

return 2*(length*width+width*height+height*length);//calculate and return the surfaceArea

}

}

// For  Cube:

public class Cube extends RectangularPrism//defining Cube class that inherits RectangularPrism  

{

  Cube(String name, double side) //defining parameterized constructor

   {

       super(name, side, side, side);//use super method

   }

  public double volume()//defining volume method  

  {

   return length * length * length;//calculate and return volume

  }

public double surfaceArea()//defining method surfaceArea  

  {

  return 6 * length*length;//calculate and return surfaceArea

   }

}

//for Cylinder:

import java.lang.*;//import lang package  

public class Cylinder extends Solid//defining Cylinder class that inherits Solid

{

  private double radius, height;//defining double variable

  public Cylinder(String str, double r, double h)//defining parameterized constructor

  {

      super(str);//use super Method

      this.radius = r;//use this keyword to hold value

      this.height = h;//use this keyword to hold value

  }

  public double volume()//defining volume method

  {

      return Math.PI * radius * radius * height;//calculate and return volume

  }

  public double surfaceArea()//defining surfaceArea method

  {

     return 2 * Math.PI * radius * (height + radius);//calculate and return surfaceArea

  }

}

//For Pyramid

import java.lang.*;//import package

public class Pyramid extends Solid//defining a Pyramid class that inherits Solid

{  

  private double length, width,height;//defining double variable

  public Pyramid(String str, double l, double w, double h)//defining parameterized constructor  

  {

      super(str);//use super method

      this.length = l;//use this keyword to hold value

      this.width = w;//use this keyword to hold value

      this.height = h;//use this keyword to hold value

  }

public double volume()//defining volume method

{

return (length*width*height)/3.0;//calculate and return volume

}

public double surfaceArea()//defining a method surfaceArea

{

return (length*width)+length*Math.sqrt((Math.pow((width/2),2)+(height*height)))+(width*Math.sqrt((Math.pow((length/2),2)+(height*height))));//calculate and return surfaceArea

}

}

//For Sphere

import java.lang.*;//import package

public class Sphere extends Solid //defining Sphere class that inherits Solid

{

  private double radius;//defining double variable

  public Sphere(String str, double r)//defining parameterized constructor  

  {

      super(str);//use super method

      this.radius = r;//use this to hold value

  }

  public double volume()//defining volume method

  {

      return (4.0/3.0)*Math.PI*radius*radius*radius;//calculate and return volume

  }

  public double surfaceArea()//defining method surfaceArea  

  {

    return 4 * Math.PI * radius * radius;//calculate and return surfaceArea

  }

}

please find attachment.

You might be interested in
Define the body of the function read_data(filename). If filename is None, return the sentence (already defined for your), otherw
Morgarella [4.7K]

Answer:

Answer explained

Explanation:

The main difference between parse_text_into_words( v1 and v2) is I have used splitlines also in v1 so the escape sequence '\n' will not be present in the list of words. while in v2 only split function is used so it will have '\n' present in words list.

Code:

def read_file(fileName = None):

  try:

      File = open(fileName,"r") # opening file in read mode

      for row in File:          # for each line in File

          print(row,end="")

  except IOError:      # handling exception of file opening

      print("Could not read file:",fileName)

def parse_text_into_words_v1(text):

  list_words = []

  list_lines = text.splitlines()

  for i in list_lines:

      list_words.extend(i.split(' '))

  return list_words

def parse_text_into_words_v2(text):

  list_words = []

  list_words.extend(text.split(' '))

  return list_words

def determine_difference(a_list,b_list):

  print("first list:",a_list)

  print("second list:",b_list)

  a_set = set(a_list)

  b_set = set(b_list)

  diff = a_set - b_set

  diff = list(diff)

  print("\nDifference between 2 sets: ",diff)

if __name__ == '__main__':

  print("Reading file using function read_file() to read \"data.txt\" :")

  read_file("data.txt")

  print("\n\n")

  t = '''vhfhyh ghgggj ghchvjhvj'''

  print("\nDemonstrating implementation of parse_text_into_words_v1:")

  l = parse_text_into_words_v1(t) # calling function with text parameter

  print("list of words:")

  print(l)

  print("\nDemonstrating implementation of parse_text_into_words_v2:")

  b = parse_text_into_words_v2(t) # calling function with text parameter

  print("list of words:")

  print(b)

  print("\nDemonstrating difference between two lists")

  a_list = [1,2,3,4,5,6,7,8,9,10]

  b_list = [2,4,6,8,10]

  determine_difference(a_list,b_list) # passing two list to take difference

8 0
3 years ago
What are the risks of logging into a system routing as “root” or some other administrative identity?
Elena L [17]
"Root" in Linus is the the same as Administrator in Windows.
When you log into a system with identity "root" this means that you have administrative privileges (you are not simple user of the system and application). The risk is that as a "Root" you have the authority to make changes in the system and maybe harm the system if you don't know exactly what you are doing.
5 0
4 years ago
The _____ displays numbers with a fixed dollar sign to the left of the number, a comma every three positions to the left of the
slava [35]

Answer: the accounting number format

Explanation:

The standard accounting number format usually contains a dollar sign, a thousands separator and two decimal points, the dollar sign is locked to the far left side of the cell in an enclosure.

How to apply the accounting number format ;

I, select the range and right-click and choose Format Cells.

Ii. In the Format Cells Dialog box, with the Number Tab selected, choose Accounting

Iii. Accept the options shown below and click Ok.

The Accounting Format has been applied.

4 0
3 years ago
When all the input has been read, your program should produce a summary report that includes a list of all the tokens that appea
hichkok12 [17]

Answer:

I dont understand this, what is the question?

5 0
3 years ago
Print even numbers till 50 in python coding.
e-lub [12.9K]

In python, you can use a simple list comprehension to solve this problem.

print([x for x in range(51) if x % 2 == 0])

This code prints all the even numbers from 0 to 50 including 0 and 50.

4 0
3 years ago
Other questions:
  • What should you do when an error message pops up on the screen?
    7·2 answers
  • How do you change brightness on acer laptop?
    7·1 answer
  • The _____ is the area in Microsoft Excel where you can perform file commands such as Save, Open, and Print
    5·2 answers
  • If your accelerator is stuck while driving, first ___.
    14·1 answer
  • Understanding the context of information allows you to apply it to everyday situations as opposed to just___facts like names,dat
    12·1 answer
  • Where do you get your news? Is it owned by a large conglomerate does it matter to you who own your local news outlets? why or wh
    5·1 answer
  • A typical day in programming and software development would involve
    12·1 answer
  • In PC relative addressing mode, the PC and constant need to be added to
    10·1 answer
  • You are working with a database table that contains data about music. The table includes columns for track_id, track_name (name
    10·1 answer
  • A thesis statement is the last sentence of the conclusion. It summarizes the entire paper.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!