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
IrinaK [193]
3 years ago
13

Edhesive unit 2 lesson 5 coding activity 1 Write code which creates three regular polygons with 11, 14 and 19 sides respectively

. All side lengths should be 1.0. The code should then print the three shapes, one on each line, in the order given (i.E. The one with 11 sides first and the one with 19 sides last). Sample run: regular hendecagon with side length 1.0 regular tetrakaidecagon with side length 1.0 regular enneadecagon with side length 1.0
Computers and Technology
1 answer:
SVEN [57.7K]3 years ago
4 0

Answer:

public class Polygon {

   private String name;

   private int sides;

   private double sideLength;

   public Polygon(String name, int sides, double sideLength) {

       if (sideLength <= 0) throw new IllegalArgumentException("Length cannot be zero or negative.");

       if (sides <= 0) throw new IllegalArgumentException("Sides cannot be zero or negative.");

       this.name = name;

       this.sides = sides;

       this.sideLength = sideLength;

   }

   public String getName() {

       return name;

   }

   public void setName(String name) {

       this.name = name;

   }

   public double getSideLength() {

       return sideLength;

   }

   public void setSideLength(double sideLength) {

       if (sideLength <= 0) throw new IllegalArgumentException("Length cannot be zero or negative.");

       this.sideLength = sideLength;

   }

   public int getSides() {

       return sides;

   }

   public void setSides(int sides) {

       this.sides = sides;

   }

   (use the at sign here)Override

   public String toString() {

       return "regular " + name + " with side length " + String.format("%.1f", sideLength);

   }

}

public class TestPolygon {

   public static void main(String[] args) {

       Polygon sides11 = new Polygon("hendecagon", 11, 1);

       Polygon sides14 = new Polygon("tetrakaidecagon", 14, 1);

       Polygon sides19 = new Polygon("enneadecagon", 19, 1);

       System. out. println(sides11);

       System. out. println(sides14);

       System. out. println(sides19);

   }

}

Explanation:

This java source code defines a class that creates a regular polygon based on the number of sides given to it.

Below is a screenshot of the program code and output.

You might be interested in
Who programmed the UNIVAC computer and literally "debugged" the first computer?
marysya [2.9K]

Grace Hopper is the first
7 0
3 years ago
Read 2 more answers
A ________ power station uses the energy from a small piece of metal called Uranium ​
grigory [225]

Answer:

nuclear power plant

Explanation:

A nuclear reactor, or power plant, is a series of machines that can control nuclear fission to produce electricity. The fuel that nuclear reactors use to produce nuclear fission is pellets of the element uranium. In a nuclear reactor, atoms of uranium are forced to break apart.

3 0
3 years ago
Read 2 more answers
1. Mark the following statements as true or false. A. Division by zero is an exception while opening an input file that does not
Lilit [14]

A. Division by zero is an exception while opening an input file that does not exist is not an exception.

False. The given except is not related to file operation

B. Suppose you use the assert function to check if certain conditions are met. If the conditions are not met, then the assert function terminates the program.  

True. Yes, it terminates by giving error message

C. One way to handle an exception is to print an error message and exit the program.  

True. Yes, it is one of the safe way to handle exception and stop the program smoothly

D. All exceptions need to be reported to avoid compilation errors.

False. Exceptions are related to run time.

E. Every try block must have a catch block.  

True. A “try block” needs to have catch block but “finally” is optional. There can be more than one catch block for a single “try block”.

F. The order in which catch blocks are listed is not important.

False. It is important to have a good programming skill. If you place the  “Exception class” which is the base for all the other types of exception in the top of catch list then, no other specific exception will get caught which is a very bad programming.

G. If an exception is thrown in a try block, the remaining statements in that try block are executed after executing a catch block.  

False. “Try block” will not get executed.

H. In C , an exception is a value.

True  

I. The class invalid range deals with the string subscript out of range error.

True.

J. In C , any class can be considered an exception class.  

False

K. The exception class must contain at least one member.  

ans: True

L. An exception can be caught either in the function where it occurred, or in any of the functions  

that led to the invocation of the method.  

True. But it is always better to catch exception in the same function.

M. When the function call stack is unwound, the function in which the exception was not caught terminates, but the memory for its local variables remains allocated.

True

7 0
4 years ago
What is the MOST important precaution to take when using social networking sites like Facebook? Use discretion Monitor friend re
leonid [27]
Uh, sure having a strong password is always nice. However, a passphrase is far superior. An example would be: My57goatsequals[4log]. Google Edward Snowden, and all your questions will be answered (concerning privacy). Oh, and by the way, use a VPN (Virtual Private Network) whenever possible.
8 0
3 years ago
Briefly explain intellegence?​
natka813 [3]

Answer:

Intelligence is the ability to think, to learn from experience, to solve problems, and to adapt to new situations. ... Psychologists believe that there is a construct, known as general intelligence , that accounts for the overall differences in intelligence among people.

3 0
3 years ago
Read 2 more answers
Other questions:
  • Is I5 9100 is better than i5 9400
    6·1 answer
  • Nina is trying to learn more about how computers work. She has repeatedly read that the motherboard is the "brain” of the comput
    9·2 answers
  • 3k means about 3 thousand bytes. how would you express two hundred million bytes? .
    8·1 answer
  • A database administrator (DBA) must have a clear understanding of the fundamental business of an organization, be proficient in
    11·1 answer
  • Angelika just submitted her product for the first time, and she had 2 errors, 3 warnings, and 5 notifications. What does she nee
    7·2 answers
  • The replacer parameter of the stringify method accepts a/an ______________ or an array.
    15·1 answer
  • Which statement describes a characteristic of SRAM in a PC?
    12·1 answer
  • When a recipient responds to a meeting request, which statement most accurate descries what occurs?
    5·2 answers
  • Consider a k=8 block cipher.
    10·1 answer
  • A museum is evaluating historical documents for authenticity, reviewing their physical condition, and categorizing them by subje
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!