Question

Draw the UML class diagram of the class Quadrilateral based on the all the requirements below....

  1. Draw the UML class diagram of the class Quadrilateral based on the all the requirements below.
  1. The name of the class is Quadrilateral
  2. The class QuadrilateralType has four private member variables: SideA, SideB , SideC and SideD all of type integer
  3. A default constructor to finalize all variables to 0
  4.   Another constructor (int s1, int s2, int s3, int s4) to initialize the member variables.   Initialize your variables using the following data (SideA = 3, SideB = 3, SideC = 5 and SideD = 5)   
  5. public int ComputePerimeter (int s1, int s2, int s3, int s4) - returns the perimeter of the Quadrilateral (SideA + SideB + SideC+ SideD)          
  6. public bool IsSquare (int s1, int s2, int s3, int s4) – returns a Boolean value if the Quadrilateral has all four sides of equal length and prints a message stating that the Quadrilateral is a Square.
  1. Write the complete definition of the member methods of the class Quadrilateral as described above.
  1. Write a complete program to test your Methods using the Quadrilateral class definitions as described in parts above.

Hint: (See the class Clock example we practiced in class and in Chapter 8 as a reference!)

Note to receive full credit you must have include your detailed Algorithm explaining your reasoning/logic!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

============================================================

UML Class diagram:

Quadrilateral - Side A: int - SideB: int - Sidec: int - SideD: int + Quadrilateral () + Quadrilateral (int s1, int s2, int s3

============================================================

Solution using C++

============================================================

Program code to copy:

/** C++ program to calculate perimeter of Quadrilateral

* and to find is it Square or not */

#include <iostream>

using namespace std;

/* Quadrilateral class */

class Quadrilateral

{

/* Private class member variables/fields */

private:

int SideA;

int SideB;

int SideC;

int SideD;

public:

/* Default constructor to finalize all variables to 0 */

Quadrilateral() {

SideA=0;

SideB=0;

SideC=0;

SideD=0;

}

/* Constructor to initialize the variables with parameters */

Quadrilateral(int s1, int s2, int s3, int s4) {

SideA = s1;

SideB = s2;

SideC = s3;

SideD = s4;

}

/* Setters and Getter methods for all class member variables */

int getSideA() {

return SideA;

}

void setSideA(int sideA) {

SideA = sideA;

}

int getSideB() {

return SideB;

}

void setSideB(int sideB) {

SideB = sideB;

}

int getSideC() {

return SideC;

}

void setSideC(int sideC) {

sideC = sideC;

}

int getSideD() {

return SideD;

}

void setSideD(int sideD) {

SideD = sideD;

}

/* Method to compute perimeter */

int ComputePerimeter(int s1, int s2, int s3, int s4) {

return s1+s2+s3+s4;

}

/* Method to find is Quadrilateral square */

bool IsSquare (int s1, int s2, int s3, int s4) {

return (s1+s2+s3+s4) == (4*s1);

}

}; /* End of class Quadrilateral */

/* Main or Driver method to test all Quadrilateral class methods */

int main()

{

/* Creating instance of Quadrilateral class */

Quadrilateral q = *new Quadrilateral(3, 3, 5, 5);

cout << "**** Quadrilateral Details ****" << endl;

cout << endl;

cout << "Length of Side A: " << q.getSideA() << endl;

cout << "Length of Side B: " << q.getSideB() << endl;

cout << "Length of Side C: " << q.getSideC() << endl;

cout << "Length of Side D: " << q.getSideD() << endl;

cout << endl;

/* Calling ComputePerimeter method to compute perimeter */

cout << "Perimeter: " << q.ComputePerimeter(3, 3, 5, 5) << endl;

cout << "Is Square: ";

/* Calling IsSquare method to find is Square ot not */

if(q.IsSquare(3, 3, 5, 5) == 0)

cout << "Yes" << endl;

else

cout << "No" << endl;

return 0;

} /* End of main method/function */

------------------------------------------------

Program code screenshots:

1 2 /** C++ program to calculate perimeter of Quadrilateral * and to find is it Square or not */ #include <iostream> 3 4 5 us

32 33 34 /* Setters and Getter methods for all class member variables */ int getSideA return SideA; } 35 36 37 void setSidea(

1* Method to find is Quadrilateral square */ bool Is Square (int si, int s2, int s3, int 54) { return (s1+2+3+54) (451); } };

--------------------------------------------------------

Sample Output:

**** Quadrilateral Details **** Length of Side A: 3 Length of Side B: 3 Length of Side C: 5 Length of Side D: 5 Perimeter: 16

===============================================================

Solution using Java

===============================================================

Program code to copy:

Quadrilateral.java

/* Quadrilateral.java class */
public class Quadrilateral {
  
   /* Class private instance member variables/fields */
   private int SideA;
   private int SideB;
   private int SideC;
   private int SideD;
  
   /* Default constructor to finalize all variables to 0 */
   public Quadrilateral() {
       super();
       SideA = 0;
       SideB = 0;
       SideC = 0;
       SideD = 0;
   }

   /* Constructor to initialize the variables with parameters */
   public Quadrilateral(int s1, int s2, int s3, int s4) {
       super();
       SideA = s1;
       SideB = s2;
       SideC = s3;
       SideD = s4;
   }

   /* Setters and Getter methods for all class member variables */
   public int getSideA() { return SideA; }

   public void setSideA(int sideA) { SideA = sideA; }

   public int getSideB() { return SideB; }

   public void setSideB(int sideB) { SideB = sideB; }

   public int getSideC() { return SideC; }

   public void setSideC(int sideC) { SideC = sideC; }

   public int getSideD() { return SideD; }

   public void setSideD(int sideD) { SideD = sideD; }
  
   /* Method to compute perimeter */
   public int ComputePerimeter(int s1, int s2, int s3, int s4) {
       return s1+s2+s3+s4; /* sum of all sides */
   }
  
   /* Method to find is Quadrilateral square */
   public boolean IsSquare (int s1, int s2, int s3, int s4) {
       /* Checking sum of all sides is equal to 4 times a side */
       return (s1+s2+s3+s4) == (4*s1);
   }

} /* End of class Quadrilateral */

TestQuadrilateral.java

/* TestQuadrilateral.java class to test Quadrilateral class */
public class TestQuadrilateral {

   /* Main or Driver method to test all Quadrilateral class methods */
   public static void main(String[] args) {
      
       /* Creating instance of Quadrilateral class */
       Quadrilateral q = new Quadrilateral(3, 3, 5, 5);
      
       System.out.println("\n**** Quadrilateral Details ****\n");
       System.out.println("Length of Side A: " + q.getSideA());
       System.out.println("Length of Side B: " + q.getSideB());
       System.out.println("Length of Side C: " + q.getSideC());
       System.out.println("Length of Side D: " + q.getSideD());
      
       /* Calling ComputePerimeter method to compute perimeter */
       System.out.println("\nPerimeter: " + q.ComputePerimeter(3, 3, 5, 5));
      
       /* Calling IsSquare method to find is Square or not */
       System.out.print("Is Square: ");
       if(q.IsSquare(3, 3, 5, 5))
           System.out.println("Yes");
       else
           System.out.println("No");
      
   } /* End of main method/function */

} /* End of class TestQuadrilateral */

---------------------------------------------------------

Program code screenshots:

Quadrilateral.java

6 7 3 /* Quadrilateral.java class */ 4 public class Quadrilateral { 5 1* Class private instance member variables/fields */ pr

/* Setters and Getter methods for all class member variables */ public int getSideA{ return SideA; } public void setSideA(int

TestQuadrilateral.java

5 6 70 9 13 14 15 16 3 /* TestQuadrilateral.java class to test Quadrilateral class */ 4 public class TestQuadrilateral { /* M

-----------------------------------------------------

Sample Output:

**** Quadrilateral Details **** Length of Side A: 3 Length of Side B: 3 Length of Side C: 5 Length of Side D: 5 Perimeter: 16

===================================================================

Hope it will helpfull and do comments for any additional info if needed. Thankyou

===================================================================

Add a comment
Know the answer?
Add Answer to:
Draw the UML class diagram of the class Quadrilateral based on the all the requirements below....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a Java class named Employee to meet the requirements described in the UML Class Diagram...

    Write a Java class named Employee to meet the requirements described in the UML Class Diagram below: Note: Code added in the toString cell are not usually included in a regular UML class diagram. This was added so you can understand what I expect from you. If your code compiles cleanly, is defined correctly and functions exactly as required, the expected output of your program will solve the following problem: “An IT company with four departments and a staff strength...

  • 1) This exercise is about Inheritance (IS-A) Relationship. A) First, draw the UML diagram for class...

    1) This exercise is about Inheritance (IS-A) Relationship. A) First, draw the UML diagram for class Student and class ComputerSystemsStudent which are described below. Make sure to show all the members (member variables and member functions) of the classes on your UML diagram. Save your UML diagram and also export it as a PNG. B) Second, write a program that contains the following parts. Write each class interface and implementation, in a different .h and .cpp file, respectively. a) Create...

  • Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the...

    Hello. I need help writing the following Java Program. Thank you Develop a class encapsulating the concept of a college course, assuming that a course has following attributers: code (for instance COSC1337), a description, and a number of credits (for instance 3). Include a constructor, the accessors, mutators and methods ‘toString’, ‘equals’, and ‘finalize’. Write a client class to test the behavior of the class and its methods. The outline of the class is given as follows: public class Course...

  • Create a UML diagram to help design the class described in exercise 3 below. Do this...

    Create a UML diagram to help design the class described in exercise 3 below. Do this exercise before you attempt to code the solution. Think about what instance variables will be required to describe a Baby class object; should they be private or public? Determine what class methods are required; should they be private or public? Write Java code for a Baby class. A Baby has a name of type String and an age of type integer. Supply two constructors:...

  • In Lab 5, you completed the MyRectangle class, which is a simple representation of a rectangle....

    In Lab 5, you completed the MyRectangle class, which is a simple representation of a rectangle. Review Lab 5 before completing this lab and retrieve the MyRectangle class that you completed for this lab, since you will need it again in this lab. Before starting this lab, edit your MyRectangle class in the following way: • change the declaration of your instance variables from private to protected This will enable access of these variables by your MySquare subclass. Here is...

  • What this Lab Is About: Given a UML diagram, learn to design a class Learn how...

    What this Lab Is About: Given a UML diagram, learn to design a class Learn how to define constructor, accessor, mutator and toStringOmethods, etc Learn how to create an object and call an instance method. Coding Guidelines for All ments You will be graded on this Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc) Keep identifiers to a reasonably short length. Use upper case for constants. Use title case (first letter is u case)...

  • Java Project Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters...

    Java Project Requirements: Account class Superclass Instance variables clearPassword String Must be at least 8 characters long encryptedPassword : String key int Must be between 1 and 10(inclusive) accountId - A unique integer that identifies each account nextIDNum – a static int that starts at 1000 and is used to generate the accountID no other instance variables needed. Default constructor – set all instance variables to a default value. Parameterized constructor Takes in clearPassword, key. Calls encrypt method to create...

  • Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance...

    Assignment Requirements I have also attached a Class Diagram that describes the hierarchy of the inheritance and interface behaviors . The link to the PDF of the diagram is below MotorVehical.pdf Minimize File Preview User Define Object Assignment: Create a Intellij Project. The Intellij project will contain three user defined classes. The project will test two of the User Define Classes by using the invoking each of their methods and printing the results. You are required to create three UML...

  • Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram)

    Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram) Author -name:String -email:String -gender:char +Author(name:String, email:String, gender:char) +getName():String +getEmail):String +setEmail (email:String):void +getGender():char +tostring ):String . Three private instance variables: name (String), email (String), and gender (char of either 'm' or 'f'): One constructor to initialize the name, email and gender with the given values . Getters and setters: get Name (), getEmail() and getGender (). There are no setters for name and...

  • Create a UML diagram to help design the class described in exercise 3 below. Do this...

    Create a UML diagram to help design the class described in exercise 3 below. Do this exercise before you attempt to code the solution. Think about what instance variables will be required to describe a Baby class object; should they be private or public? Determine what class methods are required; should they be private or public? 3. Write Java code for a Baby class. A Baby has a name of type String and an age of type integer. Supply two...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT