Advertisement
RageDoc

Fisiks

Mar 10th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.14 KB | None | 0 0
  1. package fisiks;
  2. import java.util.ArrayList;
  3. import java.util.Scanner;
  4. //------------------------------------------------
  5. //FISIKS HOMEWORK HELPER WRITTEN BY JOSEPH AQUIARE
  6. // RELEASED UNDER THE GNU GENERAL PUBLIC LICENSE
  7. //        FEEL FREE TO EDIT, FORK, ETC.
  8. //     http://www.gnu.org/licenses/gpl.html
  9. //------------------------------------------------
  10. public class Fisiks {
  11.     static int RUNTIMECOUNT = 0;
  12.     static introduction i        = new introduction();
  13.     static velocity v            = new velocity();
  14.     static acceleration a        = new acceleration();
  15.     static ArrayList<equation> e = new ArrayList<equation>();
  16.     static Scanner sc            = new Scanner(System.in);
  17.     public static void main(String[] args){
  18.         e.add(v);
  19.         e.add(a);
  20.         i.intro();
  21.         prompt();
  22.     }
  23.     static void prompt(){
  24.         if(RUNTIMECOUNT > 0){
  25.             System.out.println("AVAILABLE EQUATIONS:");
  26.             for(int i = 0; i < e.size(); i++)
  27.                 System.out.println((i+1) + ") " + Fisiks.e.get(i));
  28.         }
  29.         RUNTIMECOUNT++;
  30.         System.out.println("\nWhat equation would you like to use? (Ex. \"1\")");
  31.         e.get(sc.nextInt() - 1).askInfo();
  32.     }
  33.     public ArrayList<equation> getList(){
  34.         return e;
  35.     }
  36. }
  37.  
  38. class introduction extends Fisiks{ //intro seqence
  39.     void intro(){
  40.         System.out.println("FISIKS HOMEWORK HELPER - V1.0.0\n\n" +
  41.                            "AVAILABLE EQUATIONS:");
  42.         for(int i = 0; i < super.getList().size(); i++)
  43.             System.out.println((i+1) + ") " + Fisiks.e.get(i));
  44.     }
  45. }
  46. //DEFAULT EQUATION PARENT CLASS
  47. class equation{
  48.     private String eq = "DEFAULT EQUATION";
  49.     public String toString(){
  50.         return eq;
  51.     }
  52.     public void askInfo() {
  53.     }
  54. }
  55. // VELOCITY EQUATION CHILD CLASS
  56. class velocity extends equation{
  57.     private String eq = "VELOCITY: v = d/t";
  58.     private double d,v,t;
  59.     private Scanner sc = new Scanner(System.in);
  60.     double DandT(double distance, double time){
  61.         System.out.print("v = ");
  62.         return distance/time;
  63.     }
  64.     double DandV(double distance, double velocity){
  65.         return distance/velocity;
  66.     }
  67.     double VandT(double velocity, double time){
  68.         return velocity*time;
  69.     }
  70.     public void askInfo(){
  71.         System.out.println("You've asked for: " + toString() + "\n" +
  72.                            "What are you solving for? (Ex. \"t\")");
  73.         String s = sc.nextLine();
  74.         switch(s){
  75.             //velocity solving sequence
  76.             case("v"):  System.out.println("Please enter d, and then t:");
  77.                         System.out.print("D:");
  78.                         d = sc.nextDouble();
  79.                         System.out.print("T:");
  80.                         t = sc.nextDouble();
  81.                         System.out.println(DandT(d,t) + " m/s");
  82.                         break;
  83.             //distance solving sequence    
  84.             case("d"):  System.out.println("Please enter v, and then t:");
  85.                         System.out.print("V:");
  86.                         v = sc.nextDouble();
  87.                         System.out.print("T:");
  88.                         t = sc.nextDouble();
  89.                         System.out.println(VandT(v,t) + " m");
  90.                         break;
  91.             //time solving sequence
  92.             case("t"):  System.out.println("Please enter d, and then v:");
  93.                         System.out.print("D:");
  94.                         d = sc.nextDouble();
  95.                         System.out.print("V:");
  96.                         v = sc.nextDouble();
  97.                         System.out.println(VandT(d,v) + " s");
  98.                         break;
  99.         }
  100.         System.out.println("Would you like to use another equation? (Ex. \"y\"/\"n\")");
  101.         String answer = sc.nextLine();
  102.         switch(answer){
  103.             case("y"): Fisiks.prompt(); break;
  104.             default: System.exit(0);
  105.         }
  106.     }
  107.     public String toString(){
  108.         return eq;
  109.     }
  110. }
  111. //ACCELERATION EQUATION CHILD CLASS
  112. class acceleration extends equation{
  113.     private String eq = "ACCELERATION: a = v/t";
  114.     private double a,v,t;
  115.     private Scanner sc = new Scanner(System.in);
  116.     double VandT(double velocity, double time){
  117.         return velocity/time;
  118.     }
  119.     double VandA(double velocity, double acceleration){
  120.         return velocity/acceleration;
  121.     }
  122.     double AandT(double acceleration, double time){
  123.         return acceleration*time;
  124.     }
  125.     public void askInfo(){
  126.         System.out.println("You've asked for: " + toString() + "\n" +
  127.                            "What are you solving for? (Ex. \"a\")");
  128.         String s = sc.nextLine();
  129.         switch(s){
  130.             //acceleration solving sequence
  131.             case("a"):  System.out.println("Please enter v, and then t:");
  132.                         System.out.print("V:");
  133.                         v = sc.nextDouble();
  134.                         System.out.print("T:");
  135.                         t = sc.nextDouble();
  136.                         System.out.println(VandT(v,t) + " m/s^2");
  137.                         break;
  138.             //velocity solving sequence    
  139.             case("v"):  System.out.println("Please enter a, and then t:");
  140.                         System.out.print("A:");
  141.                         a = sc.nextDouble();
  142.                         System.out.print("T:");
  143.                         t = sc.nextDouble();
  144.                         System.out.println(AandT(a,t) + " m/s");
  145.                         break;
  146.             //time solving sequence
  147.             case("t"):  System.out.println("Please enter v, and then a:");
  148.                         System.out.print("V:");
  149.                         v = sc.nextDouble();
  150.                         System.out.print("A:");
  151.                         a = sc.nextDouble();
  152.                         System.out.println(VandA(v,a) + " s");
  153.                         break;
  154.         }
  155.         System.out.println("Would you like to use another equation? (Ex. \"y\"/\"n\")");
  156.         String answer = sc.nextLine();
  157.         switch(answer){
  158.             case("y"): Fisiks.prompt(); break;
  159.             default: System.exit(0);
  160.         }
  161.     }
  162.     public String toString(){
  163.         return eq;
  164.     }
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement