Question

In: Computer Science

For java code: Create a library to do it all. The attached file has all the...

For java code: Create a library to do it all. The attached file has all the directions and methods that need to be included in your library (.jar). You will create a .jar file, and a tester app that will include your .jar file (Add External JAR).

The attached file below:

Create a java project called MyLibrary, a package called net.dtcc.lib, and a class called AllInOne. The class should have the following methods, each method should return the answer:
Area:
Area of Rectangle
Area of Square
Area of Triangle
Area of Circle
Area of Trapezoid
Area of Ellipse
Area of Pentagon
Area of Parallelogram
Area of Rhombus
Area of Hexagon
Area of Polygon
** Pass in appropriate variables

Fractions:
Adding 2 fractions
Subtracting 2 fractions
Multiplying 2 fractions
Dividing 2 fractions
** Pass in numerator/denominator of first number; numerator/denominator of second number

Binary:
Binary to decimal conversion  
** Pass in binary number

Temperature:
Celcius to Fahrenheit
Celcius to Kelvin
Fahrenheit to Celcius
Fahrenheit to Kelvin
** Pass in temperature to be converted 

Volume:
Volume of Cube
Volume of Box
Volume of Cylinder
Volume of Cone
Volume of Sphere
** Pass in appropriate variables

Perimeter:
Perimter of Square
Perimeter of Rectangle
** Pass in appropriate variables

Circumference:
Circumference of Circle
** Pass in appropriate variables

Pythagorus Theorem:
** Pass in 2 values (a,b)

Once you have finished the class, create a library (.jar) file with the name Taz2015.jar

Next create another java project called Tester, a package called .net.dtcc.tester, and a class called LibTester. You will need to import your Taz2015.jar to the project (hint: remember derby.jar?). In this class, you should test each method in the library.

Solutions

Expert Solution

Steps to do the assignment.

  1. Create a java project called MyLibrary.
  2. Create package called net.dtcc.lib.
  3. Inside the newly created package create a new class called AllInOne.
  4. Copy paste the source code given in AllInOne.
  5. Right-click on the Project name
  6. Select Properties
  7. Click Packaging
  8. Check Build JAR after Compiling
  9. Check Compress JAR File
  10. Click OK to accept changes
  11. Right-click on a Project name
  12. Select Build or Clean and Build
  13. Jar would be created inside MyLibrary\dist
  14. create another java project called Tester
  15. Create a package called net.dtcc.tester, and a class called LibTester
  16. For adding the previously created jar, right click project(Tester), select properties
  17. Select libraries and then click on add/jar folder. Browse the jar previously created and click ok.
  18. Create a main method in LibTester and use the methods we defined in AllInOne.

Source code

1. AllInOne .java

public class AllInOne {

public double areaOfRectangle(double l, double b) {
return l * b;
}

public double areaOfSquare(double a) {
return a * a;
}

public double areaOfTriangle(double base, double height) {
return (base * height) / 2;
}

public double areaOfCircle(double r) {
return 3.14 * r * r;
}

public double areaOfTrapezoid(int b1,
int b2,
int h) {
return ((b1 + b2) / 2) * h;
}

public double areaOfEllipse(float a, float b) {

return (float) 3.142 * a * b;

}

public double areaOfPentagon(double a) {

return (double)(Math.sqrt(5 * (5 + 2 *
(Math.sqrt(5)))) * a * a) / 4;
}

public double areaOfParallelogram(double base, double height) {
return base * height;
}

public double areaOfRhombus(double l1, double l2) {
return (double)(l1 * l2) / 2;
}

public double areaOfHexagon(double s) {
return ((3 * Math.sqrt(3) *
(s * s)) / 2);
}

public double areaOfPolygon(double X[], double Y[],
int n) {
double area = 0.0;
int j = n - 1;
for (int i = 0; i < n; i++) {
area += (X[j] + X[i]) * (Y[j] - Y[i]);
j = i;
}
return Math.abs(area / 2.0);
}

private int gcd(int a, int b) {
if (a == 0) {
return b;
}
return gcd(b % a, a);
}

// Function to convert the obtained fraction
// into it's simplest form
private void lowest(int den3, int num3) {
// Finding gcd of both terms
int common_factor = gcd(num3, den3);

// Converting both terms into simpler
// terms by dividing them by common factor
den3 = den3 / common_factor;
num3 = num3 / common_factor;
System.out.println(num3 + "/" + den3);
}

//Function to add two fractions
public void addFraction(int num1, int den1,
int num2, int den2) {
// Finding gcd of den1 and den2
int den3 = gcd(den1, den2);

// Denominator of final fraction obtained
// finding LCM of den1 and den2
// LCM * GCD = a * b
den3 = (den1 * den2) / den3;

// Changing the fractions to have same denominator
// Numerator of the final fraction obtained
int num3 = (num1) * (den3 / den1) + (num2) * (den3 / den2);

// Calling function to convert final fraction
// into it's simplest form
lowest(den3, num3);
}

public void substractFraction(int num1, int den1,
int num2, int den2) {
addFraction(num1, den1, -1 * num2, den2);
}

public void multiplyFraction(int num1, int den1,
int num2, int den2) {
int num = num1 * num2;
int den = den1 * den2;
System.out.println(num + "/" + den);
}

public void divideFraction(int num1, int den1,
int num2, int den2) {
int num = num1 * den2;
int den = den1 * num2;
System.out.println(num + "/" + den);
}

public int binaryToDecimal(int n) {
int num = n;
int dec_value = 0;

// Initializing base
// value to 1, i.e 2^0
int base = 1;

int temp = num;
while (temp > 0) {
int last_digit = temp % 10;
temp = temp / 10;

dec_value += last_digit * base;

base = base * 2;
}

return dec_value;
}

public double celciusToFahrenheit(double c) {
return (double) c * (9 d / 5) + 32;
}

public double fahrenheitToCelcius(double fah) {
return (double)((fah - 32) * 5) / 9;
}

public double fahrenheitToKelvindouble(double fah) {
return 273.5 d + ((fah - 32.0 d) * (5.0 f / 9.0 d));
}

public double celciusToKelvin(double c) {
return (float)(c + 273.15);
}

public double volumeOfSquare(double a) {
return a * a * a;
}

public double volumeOfBox(double l, double b, double h) {
return l * b * h;
}

public double volumeOfCylinder(double height, double radius) {
return 3.14 * (radius * radius) * height;
}

public double volumeOfCone(double height, double radius) {
return 3.14 * (radius * radius) * height / 3;
}

public double volumeOfSphere(double r) {
return (4 * 22 * r * r * r) / (3 * 7);
}

public double perimeterOfSquare(double a) {
return 4 * a;
}

public double perimeterOfSquare(double a, double b) {
return 2 * (a + b);
}

public double circumferenceOfCircle(double r) {
return 2 * 3.14 * r;
}

public double pythagorusTheorem(double a, double b) {
double c = (a * a) + (b * b);
return Math.sqrt(c);
}

}

2. LibTester.java

public class LibTester {
public static void main(String[] args) {
AllInOne allInOne = new AllInOne();
double triangleArea = allInOne.areaOfTriangle(3.4, 9.5);
System.out.println(triangleArea);
}
}

Sample output:


Related Solutions

Create a java program that has a code file with main() in it and another code...
Create a java program that has a code file with main() in it and another code file with a separate class. You will be creating objects of the class in the running program, just as the chapter example creates objects of the Account class. Your system handles employee records and processes payroll for them. Create a class called Employee that holds the following information: first name, last name, monthly salary, and sales bonus. The class should have all the gets...
Create a Java class named ReadWriteCSV that reads the attached cis425_io.txt file that you will save...
Create a Java class named ReadWriteCSV that reads the attached cis425_io.txt file that you will save in your workspace as src/cis425_io.txt and displays the following table: -------------------------- | No | Month Name | Days | -------------------------- | 1 | January | 31 | | 2 | February | 28 | | 3 | March | 31 | | 4 | April | 30 | | 5 | May | 31 | | 6 | June | 30 |. | 7...
Java Code Question: The program is supposed to read a file and then do a little...
Java Code Question: The program is supposed to read a file and then do a little formatting and produce a new txt file. I have that functionality down. My problem is that I also need to get my program to correctly identify if a file is empty, but so far I've been unable to. Here is my program in full: import java.io.*; import java.util.Scanner; public class H1_43 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter...
Read previously created binary file using ObjectInputStream Create an appropriate instance of HashMap from Java library...
Read previously created binary file using ObjectInputStream Create an appropriate instance of HashMap from Java library Populate the HashMap with data from binary file Display the information read in a user friendly format Problem: Given: Words.dat – a binary file consisting of all the words in War and Peace Goal: Read the words in from the binary file and figure out how many times each word appears in the file. Display the results to the user. Use a HashMap with...
Convert the attached C++ code to working Java code. Be judicious in the change that you...
Convert the attached C++ code to working Java code. Be judicious in the change that you make. This assignment is not about re-writing or improving this code, but rather about recognizing the differences between C++ and Java, and making the necessary coding changes to accommodate how Java does things. PLEASE DO NOT use a built-in Java QUEUE (or any other) container. Additional resources for assignment: #include <iostream> #include <string> using namespace std; class pizza { public: string ingrediants, address; pizza...
The code file is attached. Portion of the code is given (1, 2, 3, 4). You...
The code file is attached. Portion of the code is given (1, 2, 3, 4). You have to write the code for the remaining items (5, 6, 7). #include <iostream> using namespace std; struct node { int data; node* next; }; node* head=NULL; void appendNode(int value) { node *newNode, *curr; newNode = new node(); newNode->data=value; newNode->next=NULL; if (!head) head=newNode; else { curr=head; while (curr->next) curr = curr->next; curr->next = newNode; } } void insertNode(int value) { node *newNode, *curr, *previous;...
Modify the attached files to do the following in java: 1) Add all necessary Getters and...
Modify the attached files to do the following in java: 1) Add all necessary Getters and Setters to the Class file. 2) Add code to compare two instances of the class to see which one comes before the other one based on the zipcode. //Address1.java public class Address {    // attributes    private String street, aptNum, city, state;    private int zip;    // constructors    public Address(String street, String aptNum, String city, String state, int zip)    {...
ASSIGNMENT: Write a program and use the attached file (babynames.txt) as input file, and create two...
ASSIGNMENT: Write a program and use the attached file (babynames.txt) as input file, and create two output tiles. One file listing out all boys names, and the other file listing out all girls name. CODE: (teacher gave some of the code below use it to find the answer please String B is the boy names String E is girl names) import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Scanner; /** This program reads a file with numbers, and writes the numbers...
ASSIGNMENT: Write a program and use the attached file (babynames.txt) as input file, and create two...
ASSIGNMENT: Write a program and use the attached file (babynames.txt) as input file, and create two output tiles. One file listing out all boys names, and the other file listing out all girls name. CODE: (teacher gave some of the code below use it to find the answer please String B is the boy names String E is girl names) import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Scanner; /** This program reads a file with numbers, and writes the numbers...
Write a java program that can create, read, and append a file. Assume that all data...
Write a java program that can create, read, and append a file. Assume that all data written to the file are string type. One driver class and a class that contains the methods. The program should have three methods as follows: CreateFile - only creating a file. Once it create a file successfully, it notifies to the user that it creates a file successfully. ReadingFile - It reads a contents of the file. This method only allow to read a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT