Look at the following Polygon class:
public class Polygon
{
private int numSides;

public Polygon()
{
numSides = 0;
}

public void setNumSides(int sides)
{
numSides = sides;
}

public int getNumSides()
{
return numSides;
}
}
Write a public class named Triangle that is a subclass of the Polygon class. The Triangle class should have the following members:
a private int field named base
a private int field named height
a constructor that assigns 3 to the numSides field and assigns 0 to the base and height fields
a public void method named setBase that accepts an int argument. The argument's value should be assigned to the base field
a public void method named setHeight that accepts an int argument. The argument's value should be assigned to the height field
a public method named getBase that returns the value of the base field
a public method named getHeight that returns the value of the height field
a public method named getArea that returns the area of the triangle as a double.
Use the following formula to calculate the area: Area = (height * base) / 2.0

Answers

Answer 1

Answer: This is the complete program for this with the highest level of explanation.

This program is written in the Java programming language.

The name of this file is Triangle.java

public class Triangle extends Polygon {

   // private fields to store the dimensions of the triangle

   private int base;

   private int height;

   // constructor to initialize the fields and set the number of sides

   public Triangle() {

       // call the setNumSides method inherited from Polygon to set the number of sides to 3

       setNumSides(3);

       // initialize base and height to 0

       base = 0;

       height = 0;

   }

   // setter method for the base field

   public void setBase(int b) {

       base = b;

   }

   // setter method for the height field

   public void setHeight(int h) {

       height = h;

   }

   // getter method for the base field

   public int getBase() {

       return base;

   }

   // getter method for the height field

   public int getHeight() {

       return height;

   }

   // method to calculate and return the area of the triangle

   public double getArea() {

       // calculate the area using the formula (base * height) / 2.0

       return 0.5 * base * height;

   }

}

The name of this file is Polygon.java

public class Polygon {

   private int numSides;

   public Polygon() {

       numSides = 0;

   }

   public void setNumSides(int sides) {

       if (sides == 3) {

           numSides = sides;

       } else {

           System.out.println("Error: Invalid number of sides for a triangle");

       }

   }

   public int getNumSides() {

       return numSides;

   }

}

The name of this file is Main.java

import java.util.Scanner;

public class Main {

   public static void main(String[] args) {

       Scanner scanner = new Scanner(System.in);

       // Create a new Polygon object and set its number of sides to 3

       Polygon polygon = new Polygon();

       polygon.setNumSides(3);

       // Print out the number of sides of the polygon

       System.out.println("Number of sides: " + polygon.getNumSides());

       // Obtain input from user for the base and height of a triangle

       System.out.print("Enter the base of the triangle: ");

       int base = scanner.nextInt();

       System.out.print("Enter the height of the triangle: ");

       int height = scanner.nextInt();

       // Create a new Triangle object and set its base and height

       Triangle triangle = new Triangle();

       triangle.setBase(base);

       triangle.setHeight(height);

       // Calculate the area of the triangle and print it out

       double area = triangle.getArea();

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

   }

}

This will be the output generated by this program.

Number of sides: 3

Enter the base of the triangle: 10

Enter the height of the triangle: 15

Area of the triangle: 75.0

Step 2/2

This is the complete explanation for this program.

This Triangle class is a subclass of the Polygon class, which means it inherits all of the methods and variables of the Polygon class.

This Triangle class has two private instance variables: base and height. These variables are used to store the dimensions of the triangle.

This Triangle class has a constructor that initializes the number of sides to 3 and sets the base and height variables to 0.

This Triangle class has four public methods:

a. This set Base method, which sets the value of the base variable to the given value.

b. This set Height method, which sets the value of the height variable to the given value.

c. This get Base method, which returns the value of the base variable.

d. The get Height method, which returns the value of the height variable.

Explanation:

This triangle class has a public get Area method that calculates the area of the triangle using the formula (base * height) / 2.0 and returns the result as a double.

Final answer

This is the image of the output generated by this code.

This is the image of the final output.

This is the complete summary of the entire program.

This program defines two classes: Polygon and Triangle. The Polygon class has one private instance variable, num Sides, and three public methods: Polygon(), set Num Sides(int sides), and get Num Sides (). The Triangle class is a subclass of the Polygon class and features two private instance variables, base and height, as well as six public methods: Triangle (), set Base(int base), set Height(int height), get Base (), get Height (), and get Area ().

The Main class is used to build a Triangle class object and to gather user input for the triangle's base and height. The set Base and set Height methods are used to set the values of the base and height instance variables, respectively.

Answer 2

Answer:

public class Triangle extends Polygon {

private int base;

private int height;

public Triangle() {

setNumSides(3);

base = 0;

height = 0;

}

public void setBase(int baseValue) {

base = baseValue;

}

public void setHeight(int heightValue) {

height = heightValue;

}

public int getBase() {

return base;

}

public int getHeight() {

return height;

}

public double getArea() {

double area = (height * base) / 2.0;

return area;

}

}

Hope This Helps


Related Questions

Create a data disaster recovery plan for a small copy shop

Answers

A data disaster recovery plan is a plan B for an event that takes out all your main data drive and or the information inside.

A sample  disaster recovery plan

To ensure efficient data recovery for a small copy shop, it is imperative to first identify the critical data that is vital to its operations. This would typically include customer information, transaction records, financial data, and vital employee details.

Afterward, a comprehensive backup plan should be drafted using external hard drives or cloud storage solutions. To guarantee the effectiveness of these backup systems in dire situations, it is necessary to carry out routine tests periodically.

In order to safeguard their operations against data disasters, small copy shops must establish and document a comprehensive disaster recovery plan, while also making certain that all staff members are proficient in its implementation.

Obeying these guidelines helps such establishments in limiting business disruption caused by potential data catastrophes.

Learn more about data disaster recovery plan:
https://brainly.com/question/29479562
#SPJ1

1. Consider an automated teller machine (ATM) to which users provide a personal identification number (PIN) and a card for account access. Give examples of confidentiality, integrity, and availability requirements associated with the system and, in each case, indicate the degree of importance of the requirement.

Answers

Sure, I'd be happy to help you with that.

Confidentiality:
One confidentiality requirement of the system is that the transmission of the user's PIN and account information should be encrypted to prevent unauthorized access. This requirement is of utmost importance since the unauthorized disclosure of this information could lead to unauthorized access to the user's financial accounts, which could result in financial loss, fraud, and identity theft.

Integrity:
A requirement for the system's integrity is that the user's account balance, transaction history, and other account information must be accurate at all times. This requirement is of high importance because incorrect or manipulated data could result in the user being misled or experiencing a financial loss.

Availability:
A requirement for the system's availability is that it should always be accessible to users. In case of a system failure or downtime, users should have an alternative method to access their accounts. The importance of this requirement is high because if the system is not available, users cannot withdraw cash, transfer money or access their account, which could cause significant inconvenience and financial loss.
An automated teller machine (ATM) has confidentiality, integrity, and availability requirements associated with the system.

Confidentiality requirement: The ATM system must ensure that user information such as PIN and account number are kept confidential. This requirement is of high importance because if user information is compromised, it can lead to unauthorized access to user accounts and result in financial loss.

Integrity requirement: The ATM system must ensure that user information is not modified or tampered with during transmission or storage. This requirement is of high importance because if user information is modified, it can lead to unauthorized access to user accounts and result in financial loss.

Availability requirement: The ATM system must ensure that the service is available to users when needed. This requirement is of high importance because if the service is unavailable, users may not be able to access their accounts and may face financial loss.

In summary, confidentiality, integrity, and availability requirements associated with the ATM system are all of high importance to ensure that user information is kept secure and user accounts are not compromised.

Why is it important to observe cyber etiquette always?

Answers

Answer:

Oral or in-person communication has the benefit of body language, tone of voice and facial expressions that add to the communication between sender  and recipient. Written communication is devoid of this luxury, often making the writer’s intent unclear.

This is the primary reason for the presence of online etiquette—to allow us to communicate well virtually. Most websites and social media platforms have defined the rules of online behavior that users must follow.

Such codes have been put in place to ensure people interact effectively and avoid conflicts. There can even be legal implications of not following net etiquette.

Explanation:

Answer:

observing cyber etiquette helps create a positive and respectful online environment that benefits everyone.

Explanation:

Observing cyber etiquette is important for several reasons:

Respect: Cyber etiquette is about showing respect for others online. By following the rules of cyber etiquette, you demonstrate that you value the feelings, privacy, and time of other people. It is important to remember that behind every computer screen is a real person, and that person deserves to be treated with respect.

Avoiding misunderstandings: The lack of nonverbal cues such as tone of voice and facial expressions online can easily lead to misunderstandings. By following cyber etiquette, you can avoid accidentally offending someone or causing a misunderstanding that can lead to conflict.

Protecting privacy: Cyber etiquette helps protect your own privacy as well as that of others. By refraining from sharing personal information online, avoiding cyberbullying and respecting the privacy settings of others, you help keep the online world a safe place.

Professionalism: Cyber etiquette is especially important in a professional setting. By maintaining a professional tone and avoiding offensive language, you demonstrate your professionalism and can help build your online reputation.

Overall, observing cyber etiquette helps create a positive and respectful online environment that benefits everyone

5.34 Clone of PRACTICE: Vectors**: Binary to decimal conversion A binary number's digits are only 0's and 1's, which each digit's weight being an increasing power of 2. Ex: 110 is 1*22 + 1*21 + 0*20 = 1*4 + 1*2 + 0*1 = 4 + 2 + 0 = 6. A user enters an 8-bit binary number as 1's and 0's separated by spaces. Then compute and output the decimal equivalent. Ex: For input 0 0 0 1 1 1 1 1, the output is: 31 (16 + 8 + 4 + 2 + 1) Hints: Store the bits in reverse, so that the rightmost bit is in element 0. Write a for loop to read the input bits into a vector. Then write a second for loop to compute the decimal equivalent. To compute the decimal equivalent, loop through the elements, multiplying each by a weight, and adding to a sum. Use a variable to hold the weight. Start the weight at 1, and then multiply the weight by 2 at the end of each iteration.

Answers

The programme then initialises two variables: decimal, which will store the binary number's decimal counterpart, and weight, which will store the weight of the current bit.

How can a binary number be transformed into a decimal?

One of the simplest methods for turning binary integers into decimal numbers is via doubling. We must select the number's leftmost or most significant bit. The result is then stored after adding the second leftmost bit and multiplying the digit by two.

Include the iostream tag.

Integer main() vectorint> bits(8); for (int i = 0; i 8; i++) cin >> bits[i]; #include "vector> using namespace std;

   For (int i = 0; i 8; i++), int decimal = 0, int weight = 1. Decimal += bits[i] * weight, where weight *= 2, and cout decimal endl, where return 0;

To know more about programme visit:-

https://brainly.com/question/30307771

#SPJ1

background information and features of tick-tock . [5]​

Answers

Tick-tock features are:

Algorithm-driven feedCreative video toolsViral challengesGlobal reach

What is the background information?

The story of Tick-tock started in 2016, when Chinese company ByteDance propelled an app called A.me that was said to have permitted clients to form and share brief recordings. It was renamed Douyin three months later.

Tick-tock is known or may be a social media app that permits clients to form and share short-form recordings with a term of 15 seconds to 1 miniature. The app was propelled in 2016 by the Chinese tech company ByteDance.

Learn more about background information  from

https://brainly.com/question/25023780

#SPJ1

Are there more challenges than benefits when dealing with instant messaging with the youth of today 

Answers

As with any form of communication technology, instant messaging with the youth of today comes with both challenges and benefits. While instant messaging can provide convenience and accessibility for communication, it also presents potential challenges and risks.

What is messaging?

Here are some considerations:

Challenges:

Lack of face-to-face communication: Instant messaging often lacks the richness and nuance of face-to-face communication. Nonverbal cues such as tone of voice, facial expressions, and body language may be lost or misinterpreted, leading to misunderstandings or miscommunications.

Reduced social skills: Reliance on instant messaging as a primary mode of communication may reduce the development of important social skills, such as active listening, empathy, and effective verbal and nonverbal communication.

Potential for misinterpretation: The use of abbreviations, emojis, and informal language in instant messaging may lead to misinterpretation or misunderstandings, which can result in conflicts or miscommunications.

Benefits:

Convenience and accessibility: Instant messaging provides a convenient and accessible way for youth to communicate with friends, family, and peers in real-time, regardless of their physical location.

Informal communication: Instant messaging allows for informal and casual communication, which can help youth express themselves more freely and comfortably.

Therefore, , instant messaging with the youth of today has both challenges and benefits. It is important for youth to develop critical digital literacy skills, including effective communication, online etiquette, and cybersecurity awareness, to maximize the benefits and mitigate the challenges of instant messaging.

Read more about messaging  here:

https://brainly.com/question/25307761

#SPJ1

Drag each label to the correct location. Each tile can be used more than once.
Match each task to the phase of the website development process in which it occurs.

Answers

The task and their phases in web development is given below:

Tasks and Phases

Task:

Planning content and functionality

Designing user interface and user experience

Creating and testing website code

Launching the website

Monitoring and updating website content

Phases:

Planning

Design

Development

Launch

Maintenance

Match:

Planning: Planning content and functionality

Design: Designing user interface and user experience

Development: Creating and testing website code

Launch: Launching the website

Maintenance: Monitoring and updating website content

Read more about web development here:

https://brainly.com/question/28349078
#SPJ1

● Move the pen 1 inch along a straight line. (If the pen is lowered, this action draws a 1-inch line from left to right; if the pen is raised, this action just repositions the pen 1 inch to the right.) Turn 90 degrees to the right. Draw a circle that is 1 inch in diameter. Draw a structured flowchart or write structured pseudocode describing the logic that would cause the arm to draw or write the following. Have a fellow student act as the mechanical arm and carry out your instructions. Don't reveal the desired outcome to your partner until the exercise is complete. 1-inch square a. b. 2-inch by 1-inch rectangle string of three beads short word (for example, cat) four-digit number c. d. e.​

Answers

Here is the structured pseudocode to carry out the desired actions below.

What is the pseudocode for the above prompt? Move pen 1 inch along a straight line.Turn 90 degrees to the right.Draw a circle that is 1 inch in diameter.Move pen 1 inch along a straight line, turn 90 degrees to the right, move pen 1 inch along a straight line, turn 90 degrees to the right, move pen 1 inch along a straight line, turn 90 degrees to the right, move pen 1 inch along a straight line.Move pen 2 inches along a straight line, turn 90 degrees to the right, move pen 1 inch along a straight line, turn 90 degrees to the right, move pen 2 inches along a straight line, turn 90 degrees to the right, move pen 1 inch along a straight line.Move pen 1 inch along a straight line, turn 90 degrees to the right, move pen 1 inch along a straight line, turn 90 degrees to the right, move pen 1 inch along a straight line, turn 90 degrees to the right, move pen 1 inch along a straight line.Write the word "cat" by moving the pen to write the letter 'c', then move pen 1 inch along a straight line, turn 90 degrees to the right, move pen 1 inch along a straight line to write the letter 'a', turn 90 degrees to the right, move pen 1 inch along a straight line to write the letter 't'.Move pen 1 inch along a straight line, turn 90 degrees to the right, move pen 1 inch along a straight line, turn 90 degrees to the right, move pen 1 inch along a straight line, turn 90 degrees to the right, move pen 1 inch along a straight line, write the four-digit number.

Learn more about pseudocode  at:

https://brainly.com/question/13208346

#SPJ1

Please help me with this question

Answers

Note that in this case, each sub net mask will have about 30 hosts.

How is this so?

This is derived by stating:

(30 ⁵) - 2

= hosts.

Note as well that  with 29 subnets, we have 3 bits for the subnet ID, leaving 29 bits for the host ID.

This  translates to a subnet mask of 255.255.255. 224.

To find the  I P address of host 2 on subnet 6, we need to determine the network address for subnet 6.

The first sub  net has a net work adress of 227.12.1.0, and each subsequent   subnet will increment by 32.

Therefore, subnet 6 has a net work address of 227.12.1.160 .

Since each subnet can have up to 30 hosts, host 2 on subnet 6 would have an IP address of 227.12.1.162.

Learn more about Subnet mask:
https://brainly.com/question/29974465
#SPJ1

Other Questions
Can someone help me with this,its very hard to do Use the graph below to answer the question.Money Spent on Fooddinner42%lunch30%snacks10%breakfast18%A shopper spent $100 at the store. How many dollars did the shopper spend on snacks?A. $10B. $18C. $30D. $42 evaluate x d/dx f(t) dta assume that two nations, mocka and raino, are both experiencing full employment. the current wage rate in mocka is $20, and the current wage rate in raino is $12. use the table below to answer the questions that follow. instructions: enter your answer as a whole number. a. if migration has no cost and is unimpeded, which of the following will occur? multiple choice 1 migration will cause the wage rate in raino to fall. two workers will move from raino to mocka. four workers will move from raino to mocka. no migration will occur. b. at what amount will the wage rate equalize in both countries? $ 1 someone responsible for planning, designing, creating, operating, securing, monitoring, and maintaining databases is called a( Replace the loading system by an equivalent resultant force and couple moment acting at point A. Assume F1= 35 N , F2= 25 N and F3= 55 N1)Determine the magnitude of the resultant force.2)Determine the angle between the resultant force and the x axis.3) Determine the couple moment acting at point A.200 N m 3 m traceable costs are also calledImmersive Reader (1 Point) period costs. expired costs. product costs. administrative costs what is the solution to Arccos 0.5? Given we have the following Linked List 1 -> 2 -> 2 -> 3 -> 4 -> 5 -> 5 -> 6 -> 7 What will be our output if we passed in our LinkedList to this method? Java: public ListNode abracadabra(ListNode head) { ListNode list = head; while(list != null) { if (list.next == null) { break; } if (list.val == list.next.val) { list.next = list.next.next.next; } else { list = list.next; } } return head; Python: def abracadabra(head): list = head while list: if (list.next == None) : break if (list.val == list.next.val) : list.next = list.next.next.next else : list = list.next return head Pick ONE option O 1 -> 2->2 -> 3 -> 4-> 5 -> 5 -> 6 -> 7 O 1 -> 2 -> 3 -> 4-> 5 -> 6-> 7 O 1 -> 2 -> 4-> 5->7 O 1 -> 3 -> 5 Find the measurement of angle A and round the answer to the nearest tenth(Show work if you can plsss). Common ratio of geometric sequence 4, 3, 9/4 this thing is so tricky help me find the word In this task you will summarize the main points of the Gettysburg Address and express its message in your own words. Write a summary for each paragraph of the Gettysburg Address in the table. Refer to these vocabulary words as you work on this task. control is a(n) cybernetic process that requires continual attention and process improvement from managers to stay on course. A quality control technician at a candle factory tested the eight 16-ounce candles, each 3 inches in diameter. These candles came from the same production run. The table shows the decrease in weight of each candle after burning for 3 hours. Candle makers believe that the rate at which the candles burn is constant. Write an equation that can be used to model the weight, of such a candle as a function of , the number of hours burning. Then, explain how the equation can be used to predict the weight of a candle that has burned for 5 hours. Enter your equation and your explanation in the box provided. A 4-wheel truck with a total mass of 4000 kg having a velocity of 30 m/s tries to stop in 2 seconds. How much force is being exerted to each wheel? Solve the problem and show all calculations/equations. The founders of Warby Parker were most concerned about disruption coming from:a.Their major existing competitorsb.Copycat firms invading their marketc.Failing product qualityd.Three or four folks in a dorm room somewhere coming up with a better idea than theirs."Real, 'win' and waterline are all concepts we learned from:a.The EpiPen Caseb.Matt Williams and Steve Jobs' thoughts on team effectivenessc.Bill Gored.Warby ParkerDarwin's most well known theory says that 'survival of the fittest' determines what species lives or dies. But he also had another theory that is very applicable to capitalism as well. It says that failure to adapt to changing environmental conditions is threatening to life. BOTH of these Darwinian theories apply to strategies in today's highly competitive global business environment.TrueFalse 5 years ago, Mr Tan was 4 times as old as Peiling. Peiling is 48 years younger than Mr Tan now. How old is Mr Tan now? 2. The distance between the points (1, 2p) and (1- p, 1) is 11-9p. Find the possible values of p. All of the following species are isoelectronic except a. ar b. k c. s2- d. cl- e. na