Skip to content

Commit

Permalink
Final code for Deliverble 2
Browse files Browse the repository at this point in the history
  • Loading branch information
m_japa authored and m_japa committed Jul 29, 2016
1 parent d9511dd commit abcf72f
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/com/concordia/soen6441/incarnation1/CheersMath_I1.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected double getCos(double x) {
}
i++;
} while (i <= CheersConfig_I1.COS_ITERATIONS);
return round(sum);
return sum;
}

// 4(1 - 1/3 + 1/5 - 1/7 + ...)
Expand Down
10 changes: 5 additions & 5 deletions src/com/concordia/soen6441/incarnation2/CheersMath_I2.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,31 @@ protected double convertDegreeToRadian(double deg) {
protected double roundIntermediate(double nb) {
double prec = Math.pow(10, precision);
nb *= prec;
nb = Math.round(nb);
nb = (int) Math.round(nb);
nb /= prec;
return nb;
}


// Precision of Output value is rounded up to number of decimal places selected by user
protected double roundOutput(double nb){
double prec = Math.pow(10, precisionOutput);
int prec = 10^precisionOutput;
nb *= prec;
nb = Math.round(nb);
nb = (int) nb;
nb /= prec;
return nb;
}

// To get cosine value using built-in method
protected double getCos(double x) {
double sum = Math.cos(x);
return roundIntermediate(sum);
return sum;
}

//To get Pi value using java library
protected double getPi() {
double piValue = Math.PI;
return roundIntermediate(4 * piValue);
return piValue;
}

// http://mathcentral.uregina.ca/QQ/database/QQ.09.00/roble1.html
Expand Down
39 changes: 39 additions & 0 deletions src/com/concordia/soen6441/incarnation2/CheersXML_I2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.concordia.soen6441.incarnation2;

public class CheersXML_I2 {

public static boolean generateXML(double radius, int precision, int precisionOutput, String output){
boolean x = false;
try{
System.out.println("<?xml version="+"\"1.0\""+" encoding="+"\"UTF-8\""+"?>");
System.out.println("<!DOCTYPE cheers [");
System.out.println("<!ELEMENT cheers (input,output)>");
System.out.println("<!ELEMENT input (radius,intermediateprecision,lengthprecision)>");
System.out.println("<!ELEMENT output (length)>");
System.out.println("<!ELEMENT radius (#PCDATA)>");
System.out.println("<!ELEMENT intermediateprecision (#PCDATA)> ");
System.out.println("<!ELEMENT lengthprecision (#PCDATA)> ");
System.out.println("<!ELEMENT length (#PCDATA)>");
System.out.println("<!ATTLIST radius type CDATA #IMPLIED>");
System.out.println("<!ATTLIST intermediateprecision type CDATA #IMPLIED>");
System.out.println("<!ATTLIST lengthprecision type CDATA #IMPLIED>");
System.out.println("<!ATTLIST length type CDATA #IMPLIED>");
System.out.println("]>");
System.out.println("<cheers>");
System.out.println("\t<input>");
System.out.println("\t\t<radius type="+"\"double\""+">"+radius+"</radius>");
System.out.println("\t\t<intermediateprecision type="+"\"int\""+">"+precision+"</intermediateprecision>");
System.out.println("\t\t<lengthprecision type="+"\"int\""+">"+precisionOutput+"</lengthprecision>");
System.out.println("\t</input>");
System.out.println("\t<output>");
System.out.println("\t\t<length type="+"\"double\""+">"+output+"</length>");
System.out.println("\t</output>");
System.out.println("</cheers>");
x = true;
}
catch(Exception e){
System.out.println("XML cannot be generated. Please try again..!");
}
return x;
}
}
3 changes: 1 addition & 2 deletions src/com/concordia/soen6441/ui/CheersUi_I1.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public static void main(String args[]) throws CheersException_I1 {
CheersMath_I1 cheersMath = new CheersMath_I1(radius, precision, precisionOutput);
System.out.println("The two coasters need to be moved " + cheersMath.getLength()
+ " inch far from each other");

case CheersConfig_I1.OPERATION_EXIT:
System.out.println("Program Cheers Ended!");
System.exit(0);
Expand All @@ -63,5 +62,5 @@ public static void main(String args[]) throws CheersException_I1 {
System.out.println("Program ended");
}
}

}
3 changes: 3 additions & 0 deletions src/com/concordia/soen6441/ui/CheersUi_I2.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ public static void main(String args[]) throws CheersException_I2 {
CheersMath_I2 cheersMath = new CheersMath_I2(radius, precision, precisionOutput);
DecimalFormat df = new DecimalFormat("0", DecimalFormatSymbols.getInstance(Locale.ENGLISH));
df.setMaximumFractionDigits(340);
boolean res = CheersXML_I2.generateXML(radius,precision,precisionOutput,df.format(cheersMath.getLength()));
if(res){
System.out.println("The two coasters need to be moved " + df.format(cheersMath.getLength())
+ " inch far from each other");
}

case CheersConfig_I2.OPERATION_EXIT:
System.out.println("Program Cheers Ended!");
Expand Down

0 comments on commit abcf72f

Please sign in to comment.