Skip to content

Commit

Permalink
refactore: Refactored kinematics >> uvm >> time 1
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmjr committed Jun 16, 2023
1 parent 87d1f50 commit 8e0b51b
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
public class MUV implements MUVIF {
private static MUV instance;

private Time1 time1;
private Time2 time2;
private Time3 time3;
private Time4 time4;

public MUV() {
time1 = Time1.getInstance();
time2 = Time2.getInstance();
time3 = Time3.getInstance();
time4 = Time4.getInstance();
Expand Down Expand Up @@ -205,8 +203,8 @@ public Speed4 speed4(double initialVelocity,
double deltaTime,
double acceleration) {
return new Speed4(initialVelocity,
deltaTime,
acceleration);
deltaTime,
acceleration);
}

//
Expand All @@ -230,23 +228,21 @@ public Speed4 speed4(double initialVelocity,
// Time
// First variation of time: ∆t = ∆v / acceleration
@Override
public String time1(double deltaVelocity, double acceleration) {
return time1.time(deltaVelocity, acceleration);
public Time1 time1(double deltaSpeed, double acceleration) {
return new Time1(deltaSpeed, acceleration);
}

@Override
public String time1(
double deltaVelocity,
String deltaVelocityUnit,
double acceleration,
String accelerationUnit,
String unitOfResult) {
return time1.time(
deltaVelocity,
deltaVelocityUnit,
acceleration,
accelerationUnit,
unitOfResult);
public Time1 time1(double deltaSpeed,
int deltaVelocityUnit,
double acceleration,
int deltaSpeedUnit,
int unitOfResult) {
return new Time1(deltaSpeed,
deltaVelocityUnit,
acceleration,
deltaSpeedUnit,
unitOfResult);
}

// Second variation of time: ∆t = (vf - vi) / acceleration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,14 @@ public abstract Speed4 speed4(
int accelerationUnit,
int unitOfResult);

public abstract String time1(double deltaSpeed, double acceleration);
public abstract Time1 time1(double deltaSpeed, double acceleration);

public abstract String time1(
public abstract Time1 time1(
double deltaSpeed,
String deltaSpeedUnit,
int deltaSpeedUnit,
double acceleration,
String accelerationUnit,
String unitOfResult);
int accelerationUnit,
int unitOfResult);

public abstract String time2(
double initialSpeed,
Expand Down
141 changes: 127 additions & 14 deletions app/src/main/java/com/mjr/twaire/code/physic/kinematics/muv/Time1.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,146 @@
package com.mjr.twaire.code.physic.kinematics.muv;

public final class Time1
{
import com.mjr.twaire.code.physic.Calculation;

public final class Time1 extends Calculation {
@Deprecated
private static Time1 instance;
private double deltaSpeed;
private double acceleration;

private int deltaSpeedUnit;
private int accelerationUnit;
private int unitOfResult;

private double step1;
private boolean hasCustomUnits;

protected Time1() {}

protected Time1(double deltaSpeed, double acceleration) {
this.deltaSpeed = deltaSpeed;
this.acceleration = acceleration;
hasCustomUnits = false;
calculate();
}

protected Time1(double deltaSpeed,
int deltaSpeedUnit,
double acceleration,
int accelerationUnit,
int unitOfResult) {
this.deltaSpeed = deltaSpeed;
this.acceleration = acceleration;
this.deltaSpeedUnit = deltaSpeedUnit;
this.accelerationUnit = accelerationUnit;
this.unitOfResult = unitOfResult;
hasCustomUnits = true;
calculate();
}

@Override
public Time1 calculate() {
if (hasCustomUnits)
calculateWithCustomUnits();
else
calculateWithoutCustomUnits();
return this;
}

private void calculateWithCustomUnits() {
}

private void calculateWithoutCustomUnits() {
step1 = deltaSpeed / acceleration;
}

@Override
public double getResult() {
return step1;
}

@Override
public String getSteps() {
if (hasCustomUnits)
return null;
StringBuilder resolution = new StringBuilder();
String deltaSpeed = (this.deltaSpeed < 0) ? "(" + this.deltaSpeed + "m/s)" : this.deltaSpeed + "m/s";
String acceleration = (this.acceleration < 0) ? "(" + this.acceleration + "m/s²)" : this.acceleration + "m/s²";
resolution.append("∆t= " + deltaSpeed + " ÷ " + acceleration);
resolution.append("t = " + step1 + "s");
return resolution.toString();
}

public Time1 setDeltaSpeed(double deltaSpeed) {
this.deltaSpeed = deltaSpeed;
return this;
}

private Time1 ()
{}
public double getDeltaSpeed() {
return deltaSpeed;
}

public Time1 setAcceleration(double acceleration) {
this.acceleration = acceleration;
return this;
}

public double getAcceleration() {
return acceleration;
}

public Time1 setDeltaSpeedUnit(int deltaSpeedUnit) {
this.deltaSpeedUnit = deltaSpeedUnit;
return this;
}

public int getDeltaSpeedUnit() {
return deltaSpeedUnit;
}

public Time1 setAccelerationUnit(int accelerationUnit) {
this.accelerationUnit = accelerationUnit;
return this;
}

public int getAccelerationUnit() {
return accelerationUnit;
}

public Time1 setUnitOfResult(int unitOfResult) {
this.unitOfResult = unitOfResult;
return this;
}

public int getUnitOfResult() {
return unitOfResult;
}

@Override
public String getFormula() {
return "∆t = ∆v ÷ a";
}

protected String time (
@Deprecated
protected String time(
double deltaSpeed,
double acceleration)
{
double acceleration) {
return String.valueOf(deltaSpeed / acceleration);
}

protected String time (
@Deprecated
protected String time(
double deltaSpeed,
String deltaSpeedUnit,
double acceleration,
String accelerationUnit,
String unitOfResult)
{
String unitOfResult) {
return null;
}

public static Time1 getInstance ()
{
if (instance == null)
{
@Deprecated
public static Time1 getInstance() {
if (instance == null) {
instance = new Time1();
}
return instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public Time1Test () {

@Test
public void time1Test () {
Double deltaSpeed = 3.0;
Double acceleration = 8.0;
String result = "0.375";
assertEquals(result, muv.time1(deltaSpeed, acceleration));
double deltaSpeed = 3.0;
double acceleration = 8.0;
double result = 0.375;
assertEquals(result, muv.time1(deltaSpeed, acceleration).getResult());
}
}

0 comments on commit 8e0b51b

Please sign in to comment.