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!
============================================================
UML Class diagram:
============================================================
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:
--------------------------------------------------------
Sample Output:
===============================================================
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
TestQuadrilateral.java
-----------------------------------------------------
Sample Output:
===================================================================
Hope it will helpfull and do comments for any additional info if needed. Thankyou
===================================================================
Draw the UML class diagram of the class Quadrilateral based on the all the requirements below....
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 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 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 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. 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 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 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 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) 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 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...