Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi! Iwrote a java program, not for homework, just for myself ,to try to write a time dilation calculator. I used the special relativity formula,

Hi! Iwrote a java program, not for homework, just for myself ,to try to write a time dilation calculator. I used the special relativity formula, and I like my result, I also organized the code into three seperate parts, a public abstract class, a sub class, and a client class to test the program. As of now, while it works, I would appreciate someone reviewing it and seeing how to improve the organization, I think it is not as good as it should be in terms of the three part structures intentions. What follows is my code:

//part one of my code

public abstract class TimeDilation { private String time;

public TimeDilation() { } public TimeDilation(String time) { this.time = time; } public String toString() { return " Time Dilation: " + time; } public abstract double calculateTime(); }

// part two of my code

public class SingleCalculation extends TimeDilation { // instance variables private double observerTime = 0.0; private double spaceCraftTime = 0.0; private double constant = 0.0; private double velocity = 0.0; private double lightSpeed = 0.0; private double denominator = 0.0;

// Overloaded constructor public SingleCalculation(double observerTime, double spaceCraftTime, double constant, double velocity, double lightSpeed, double denominator, String time) { super(time); this.observerTime = observerTime; this.spaceCraftTime = spaceCraftTime; this.constant = constant; this.velocity = velocity; this.lightSpeed =lightSpeed; this.denominator = denominator;

}

public String toString() { System.out.println("");

System.out.println("Single Calculation");

return super.toString() + " Spacecraft time in seconds " + spaceCraftTime + ". Velocity in km per second " + velocity + "."; }

public double calculateTime() { denominator = 1-((velocity*velocity)/(lightSpeed*lightSpeed)); double squareRoot = Math.sqrt(denominator); return observerTime = spaceCraftTime/squareRoot;

} }

// part three of my code to test it

import java.util.ArrayList;

public class TestTimeDilation { public static void main( String [] args ) {

ArrayList myList;

myList = new ArrayList( );

SingleCalculation single = new SingleCalculation(0.0, 1.0, 1.0, 239833.9664, 299792.458, 0.0, ""); myList.add(single);

for(int i =0; i

} } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems A Practical Approach To Design Implementation And Management

Authors: THOMAS CONNOLLY

6th Edition

9353438918, 978-9353438913

More Books

Students also viewed these Databases questions

Question

1. Explain why evaluation is important.

Answered: 1 week ago