Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package fisiks;
- import java.util.ArrayList;
- import java.util.Scanner;
- //------------------------------------------------
- //FISIKS HOMEWORK HELPER WRITTEN BY JOSEPH AQUIARE
- // RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE
- // FEEL FREE TO EDIT, FORK, ETC.
- // http://www.gnu.org/licenses/gpl.html
- //------------------------------------------------
- public class Fisiks {
- static int RUNTIMECOUNT = 0;
- static introduction i = new introduction();
- static velocity v = new velocity();
- static acceleration a = new acceleration();
- static ArrayList<equation> e = new ArrayList<equation>();
- static Scanner sc = new Scanner(System.in);
- public static void main(String[] args){
- e.add(v);
- e.add(a);
- i.intro();
- prompt();
- }
- static void prompt(){
- if(RUNTIMECOUNT > 0){
- System.out.println("AVAILABLE EQUATIONS:");
- for(int i = 0; i < e.size(); i++)
- System.out.println((i+1) + ") " + Fisiks.e.get(i));
- }
- RUNTIMECOUNT++;
- System.out.println("\nWhat equation would you like to use? (Ex. \"1\")");
- e.get(sc.nextInt() - 1).askInfo();
- }
- public ArrayList<equation> getList(){
- return e;
- }
- }
- class introduction extends Fisiks{ //intro seqence
- void intro(){
- System.out.println("FISIKS HOMEWORK HELPER - V1.0.0\n\n" +
- "AVAILABLE EQUATIONS:");
- for(int i = 0; i < super.getList().size(); i++)
- System.out.println((i+1) + ") " + Fisiks.e.get(i));
- }
- }
- //DEFAULT EQUATION PARENT CLASS
- class equation{
- private String eq = "DEFAULT EQUATION";
- public String toString(){
- return eq;
- }
- public void askInfo() {
- }
- }
- // VELOCITY EQUATION CHILD CLASS
- class velocity extends equation{
- private String eq = "VELOCITY: v = d/t";
- private double d,v,t;
- private Scanner sc = new Scanner(System.in);
- double DandT(double distance, double time){
- System.out.print("v = ");
- return distance/time;
- }
- double DandV(double distance, double velocity){
- return distance/velocity;
- }
- double VandT(double velocity, double time){
- return velocity*time;
- }
- public void askInfo(){
- System.out.println("You've asked for: " + toString() + "\n" +
- "What are you solving for? (Ex. \"t\")");
- String s = sc.nextLine();
- switch(s){
- //velocity solving sequence
- case("v"): System.out.println("Please enter d, and then t:");
- System.out.print("D:");
- d = sc.nextDouble();
- System.out.print("T:");
- t = sc.nextDouble();
- System.out.println(DandT(d,t) + " m/s");
- break;
- //distance solving sequence
- case("d"): System.out.println("Please enter v, and then t:");
- System.out.print("V:");
- v = sc.nextDouble();
- System.out.print("T:");
- t = sc.nextDouble();
- System.out.println(VandT(v,t) + " m");
- break;
- //time solving sequence
- case("t"): System.out.println("Please enter d, and then v:");
- System.out.print("D:");
- d = sc.nextDouble();
- System.out.print("V:");
- v = sc.nextDouble();
- System.out.println(VandT(d,v) + " s");
- break;
- }
- System.out.println("Would you like to use another equation? (Ex. \"y\"/\"n\")");
- String answer = sc.nextLine();
- switch(answer){
- case("y"): Fisiks.prompt(); break;
- default: System.exit(0);
- }
- }
- public String toString(){
- return eq;
- }
- }
- //ACCELERATION EQUATION CHILD CLASS
- class acceleration extends equation{
- private String eq = "ACCELERATION: a = v/t";
- private double a,v,t;
- private Scanner sc = new Scanner(System.in);
- double VandT(double velocity, double time){
- return velocity/time;
- }
- double VandA(double velocity, double acceleration){
- return velocity/acceleration;
- }
- double AandT(double acceleration, double time){
- return acceleration*time;
- }
- public void askInfo(){
- System.out.println("You've asked for: " + toString() + "\n" +
- "What are you solving for? (Ex. \"a\")");
- String s = sc.nextLine();
- switch(s){
- //acceleration solving sequence
- case("a"): System.out.println("Please enter v, and then t:");
- System.out.print("V:");
- v = sc.nextDouble();
- System.out.print("T:");
- t = sc.nextDouble();
- System.out.println(VandT(v,t) + " m/s^2");
- break;
- //velocity solving sequence
- case("v"): System.out.println("Please enter a, and then t:");
- System.out.print("A:");
- a = sc.nextDouble();
- System.out.print("T:");
- t = sc.nextDouble();
- System.out.println(AandT(a,t) + " m/s");
- break;
- //time solving sequence
- case("t"): System.out.println("Please enter v, and then a:");
- System.out.print("V:");
- v = sc.nextDouble();
- System.out.print("A:");
- a = sc.nextDouble();
- System.out.println(VandA(v,a) + " s");
- break;
- }
- System.out.println("Would you like to use another equation? (Ex. \"y\"/\"n\")");
- String answer = sc.nextLine();
- switch(answer){
- case("y"): Fisiks.prompt(); break;
- default: System.exit(0);
- }
- }
- public String toString(){
- return eq;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement