Wednesday, May 25, 2016

Adding Tutorial

Today, I added the tutorial to the app. I included 3 sections: general info, controls, and menu buttons explained. I used the ScrollPane class (in Scene2d UI) that Jiho figured out to make it a scrolling window. This is updated on the website version that can be found here:

http://www.pages.drexel.edu/~njw59/

Below are some screenshots showing the content of the tutorial window.












Monday, May 23, 2016

Week 8 Update

Overview
We are at a point now where the app is just about done. We made a lot of progress over the last couple weeks and just this morning (Monday of Week 9) sent the app to a physics teacher for beta testing with his students.

Progress
One major change I made was updating the launch simulation to be more realistic. I incorporated the Runga Kutta method instead of Euler’s Method to provide more accuracy with less processing. The code used can be found here:


I also finished adding functionality to the menu buttons. They now all do what they’re supposed to do on click. Jiho also got the icons set up and I implemented those in as well. In addition, I added tooltips that pop up when someone mouses over a button and I added messages that show up to alert the user with the selected body and warnings such as when a body isn’t selected.

New Menu Icons

Messge overlay showing selected body (Body_1) and alert

Tooltip explaining function of scale button

Here’s the code for the menu:



And here’s the code for the message overlay:


Ebed made an assortment of 10 skins to put on the bodies. He made them different colors but all similar so that they would look consistent. Below is a texture atlas with 9 of them. I then put them into the app and set it up so that they would be randomly put on a body every time one was created.

Texture atlas of 9 body skins
The last major change I made was making it so that the app can be used online. I contacted the computer science department here at Drexel and they helped set me up with a free website. I then used Android Studio and libGDX to export the app in html form (see FAQ for a how-to). The app can be found and used here:


I then sent the app to my high school physics teacher who said he would test it out with his students over the next few days. Ebed created a survey that the students will fill out so that we can decide what changes need to be made. Here’s the survey:


Future Plans
In the next week, we need to plan out our presentation and finish our report. We will compile and analyse the results of the survey to do the results section of our report. We’re hoping we get nominated for the poster fair that will take place at the end of next week. Only one group from our section will make it.

Sunday, May 22, 2016

Upcasting and Downcasting


           Upcasting and downcasting allows you to change the reference variable type for an object. The type of the reference variable determines what methods you can call, but it’s the type of the object that the variable refers to which determines the methods that will be called. Unlike downcasting, upcasting is guaranteed by polymorphism.

            Similar to casting numbers, when down casting you need to specify what you’re casting to in parentheses before the variable. The variable your downcasting to must refer to the object type that your downcasting to. When your upcasting or downcasting you can't change the object only the reference variable.

Casting Numbers


In java you can cast from type to type as long as there in the same class. For example you can cast a floating number to a double, but not an integer to a string. Some types can only hold a certain amount of memory. So when converting between types you must be careful that the type you’re casting to can hold that value. If you do convert a number that doesn’t fit in that type, it may cut off the extra spaces. For example if you cast a floating number to an integer it will cut of the decimals. (It won’t round the number. Math.round does that for you.) When casting a number you must set a variable equal to the variable you want to cast. In parenthesis before the casted variable you must put the type you want to convert to.

Below shows code where I did many different casts. At the bottom I tried to cast a value of 128 to a byte. The problem is that a byte only holds up to 127, so what you get as an output is byte’s minimum, -127.

public class App {

      public static void main(String[] args){
            byte byteValue = 20;
            short shortValue = 55;
            int intValue = 808;
            long longValue = 3332322;
            float floatValue = 8834.8f;
            double doubleValue = 32.4;      
            
            System.out.println(Byte.MAX_VALUE);
            intValue = (int)longValue;
            System.out.println(intValue);
            doubleValue = intValue;
            System.out.println(doubleValue);       
            intValue = (int)floatValue;
            System.out.println(intValue);

            //ByteMax is 127;
            // the following won't work as we expect it to .
            //128 is to big for a byte.
            byteValue = (byte)128;
            System.out.println(byteValue);
          
      }
}

Wednesday, May 18, 2016

Encapsulation


Today I watched a tutorial on encapsulation. This is an extension of the public private and protected tutorial. Explaining why we declare instance variables, and methods private within a class. You want to declare a method private when you are only going to use it within the class. In general try not to make instance variables public unless they are constants. One reason we due this is to reduce cross linkages, you don’t want one class getting entangled in another class. Another thing the tutorial talked about is API documents. This is just the documents of built in classes for java. For example String is a built in class, meaning you don’t have to make a String class to create a String object in java. The API document gives you information on everything about the class, interfaces, instance variables, methods, constructers, etc. You will notice that in the built in classes there aren’t many instance variables that are public, except constants. The point of encapsulation is to define things private as much as you can unless, you need to use them outside that class.

Tuesday, May 17, 2016

Planets and App Logo

Today I spent time working on different skins for planets. Since you can't just copy images from online, because of legal reasons, I used Photoshop to make my own planets. One problem with our orbit simulator is that it runs slow. So we are looking for ways to increase the operation speed. One idea we thought of, was getting rid of friction. What we wanted to do was make planets that are symmetric so the rotation due to friction wouldn't matter. So however I spin a planet it will look exactly the same.

When making the app logo, I wanted to make sure the color scheme looked appealing. This will be the first thing the user sees, so it must look good. I experimented with different colors to try and get the most visual appealing one. In the process I asked friends which colors they liked the best, knowing that I am not the target audience. Below is the logo I made in Photoshop.


Monday, May 16, 2016

Polymorphism


Polymorphism essential means that if you have a child class of a parent class you can use the child class anywhere you would use the parent class.  For example you can declare variable with type of parent class to objects of child class. Then when you call a method to that variable it will call the method in the child class. When you run the method the type of the variable doesn’t matter. What matters is the type object containing the variables that’s going to run. So if you make a variable with a parent class type, but it refers to a child class object. It’s going to run the code in the child class.

Below shows many examples of polymorphism. In the main method I made a tree object and a plant object. Tree is a child class of plant. So we can declare a variable type plant to a tree object. We can now call a method that is in both the plant and tree class. When the method is called it will run the code in the tree class. If you try and call a method not in the plant class using a tree object it won’t work. This is shown in the comment below where shedLeaves is a method only in the tree class.



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

            Plant plant1 = new Plant();
            Tree tree = new Tree();         
            Plant plant2 = tree;
         
            plant2.grow();          
            tree.shedLeaves();
        
            //plant2.shedLeaves();
          
            doGrow(tree);
  
      }
    
      public static void doGrow(Plant plant){
            plant.grow();
      }

}


Sunday, May 15, 2016

Private, Public, Protected


Normally you don’t want to make instance variables public, and access them through methods. An exception to this rule would be when you want to make a constant variable. When you make an instance variable private you can only access it inside the class. This means if I make a child class I cannot use that private variable in that class. If for some reason you want a variable to be accessible in a child class and package, but nowhere else, you can make it protected. The last option is having no access modifier. This makes it so you can access that variable only in the same package.

Interface


Unlike classes when making a method in an interface, you don’t define a body. In fact you don’t even put code in an interface method. When implementing an interface into a class you write (implements interface_name), after the header of the class. This will force you to have all the methods that the interface has. In eclipse the body of the methods will automatically be added to the class. You then can add code to the method in your class telling it what to do. If you want to implement multiple interfaces, separate the names with a coma.
You can use that interface type to create new objects of classes that have that interface implemented. When you make a new object with a type interface, you no longer have access to all the methods in that class, you only have access to the interface methods. When you call a method with a parameter type interface, you must pass an object into a method that implements that specific interface.
Here’s an analogy that may help you understand interfaces better. Say you were making tons of different types of bikes. Each type of bike has two wheels a frame, and handle bars. An interface would allow you to make methods for each of those parts. Then when you make a class for a new type of bike you can implement that interface. This will add all the methods (wheels, frame, and handle bars) into the class. This will make sure your bike has all those parts.

Saturday, May 14, 2016

Week 7 Update

Progress

In week 7, we finished graphics on the menu buttons and body information window. The body information is one of the functionality in the menu. When the user clicks the planet and open this window, it shows the planet's information. It shows the position of a planet on x and y axis, the velocity and mass of the planet. In this window, the user can change any variables and all changes are saved, the changes are applied to the planet. This is screen shots of menu buttons and the body information window.

 Future Plans

We will keep focusing on our graphics and button functionalities. Not all buttons have all their functions. As we mentioned in the final report, we are going to have feedback from high school teacher. We are going the send our app to a high school teacher we already talked to and we will get feedback by week 9. 

Wednesday, May 11, 2016

Week 6 Update


Weekly Update



Although we spent most of time this week on our rough draft for the final report. A lot of progress was made to the dialogue box, and the menu icons.



The dialogue box will pop up when the user presses the info button under the main menu tab. This dialogue box gives the user the ability to manual change the information of a selected body. As shown in the image below there is a save button. When pressed the selected body is updated to the new specifications. It even gives the user an option to name the planet, in order to keep track of his creation. Allowing a user to input specific values for these variables, will give students the ability to calculate the gravitational force, and centripetal acceleration.

Image 2: This is an example of a dialogue
box without a body selected.

Image 1: This is an example of a dialogue
box without a body selected


The second big task we did this week was making the icons for the menu buttons. When doing this we found free icons online. We then download the icons and made a texture atlas out of them using libGDX’s texture packer. The texture atlas is shown in the image below. After loading in the texture atlas we were able to access each icon, by locating the image in the texture atlas. The buttons were chosen to best resemble there function. For example the info button is an [i], and the add planet button is a [+]. We hope these buttons will make the simulator easier to use. If we find out this isn’t the case, we may switch back to words for the buttons, or change the graphics.

Image 3: This is an example of a texture atlas.


Tuesday, May 10, 2016

Inheritance


Inheritance is when you make an extension of a class. This extension is called the child class of the parent. You can extend a class, by writing extends (parent_class_name). When you make a child class that gives the class access to all the methods in the parent class. Inheritance is used when you want to add new methods to the parent class. So the child class is the parent class plus a little more. Some classes can’t be extended, like the String class which is a final class.



Another thing you can do in a child class, is override methods in the parent class. When overriding a method, the header of the method has to be the same. You can then change what the method does in the child class. So whenever you call that method in the main class, to a child class object it does the override method. If you put @Override before overriding a method the program will make sure that the method is overriding a method in the parent class. So it will make sure you don’t spell the parent method wrong, and just end up creating a totally new class.



Sometimes you won’t be able to access every part of a parent class. For example if you declare an instance variable private it is only accessible in that class. So you won’t be able to use that variable in the child class. You can get rid of private which allows access to that variable with in the package of the class. So if the child class is within the package of the parent class it has access to that variable. Lastly if you make an instance variable protected, you can access the variable anywhere in the package of the class, and in the child classes.


Sunday, May 8, 2016

Static and Final


Static member variables or class variables belong to the class. Unlike instance variable values, each object does not get its own unique value. A class variable belong to the class and sense there is only one class there is only one copy. When writing a class variable you must add the key word static. Later when accessing that class variable, you must use the (class_name. variable_name.)

A static method also uses the key word (static method_name.) You can access a static method by using the (class_name.method_name.) Static methods can access static variables in the class, but they can’t access instance variables.

A static method can be used if you have a method that doesn’t deal with instance data of the class. Another typical use of static method is when you access a constants. We can make or own constant variable by using the key words final and static. When making a constant variable you must set its value in the class, and it will remain constant. This mean you cannot reassign that variable later on. Below shows examples of static variables, static methods, and constants.



class Thing {

      public String name;

      public static String description;

      public final static int LUCKY_NUMBER = 7;

     

      public static int count = 0;

     

      public int id;

     

      public Thing(){

           

            id = count;

            count++;

      }

     

      public void showName(){

            System.out.println("object id; " + id + description + ":" + name);

      }

     

      public static void showInfo(){

            System.out.println(description);

           

      }

}



public class App {

      public static void main(String[] args) {

           

            Thing.description = "I am a thing";

           

            Thing.showInfo();

           

            System.out.println("Before creating objects, count is: " + Thing.count);

           

            Thing thing1 = new Thing();

            Thing thing2 = new Thing();

           

            System.out.println("After creating objects, count is: " + Thing.count);

           

            thing1.name = "bob";

            thing2.name = "sue";

           

           

            thing1.showName();

            thing2.showName();

           

            System.out.println(Math.PI);

           

            System.out.println(Thing.LUCKY_NUMBER);

        }



}


Saturday, May 7, 2016

Constructors


A constructor is a special method that runs every time you create an instance of a class. Constructors unlike regular methods do not need a return type. The name of the constructor always has to be the same of the class you make it in. When you make an instance of a class it will run the constructor. A common use for a constructor is initialization of instance variables. For example if you have a class called dog, and an instance variable “name”. So you want to make objects of that class, where all the dogs’ names are the same. A constructor allows you to make each object have that name, without declaring each name individually to each class. All you have to do is make a new object with the constructor that declares the name. Another useful thing you can do with constructors is call other constructors. The way you call or access a constructor is by using the key word “this()”, where you put your parameters for the constructor your calling in the parenthesis.

Week6. Progress

Progress


This week we mainly focused on graphics and button functionality. We succeed to put graphic on the buttons, and created a function to adjust scales. 

To put images on the buttons, we first had to pack all the icons we want to use into .pack file. 
The icons should be .png file to pack. After pack all the images, there will be two outputs. One is packed png file and the other one is .pack file. To use the images in android studio, those two should go to same file under asset file. We put those two files in asset file and call the pack file from the script. And then call the name of the icon by using getDrawable. This is the picture of menu button.


Future Plans

We are going to keep working on out graphics and button functionality. For now we only worked out with one icon but at the end, each button will have its own icon. Also we are going to keep working on right scales. 

Wednesday, May 4, 2016

Method Parameter


 A method parameter changes how the method works, by making a variable you can pass into it. You can make a parameter in the main method and define the variable when declaring it to a body. A key aspect to remember when defining a variable, is to make sure it is the same type as the parameter in the method. When declaring two variables in a parameter use a comma. When referring to the method put your variables in the same order as declared. When you define the variable for the parameter you can either put it right into the open parenthesis, or you can specify the variable before, and then put that variable into the open parenthesis. Below is code showing three different methods all using parameters to assign data to a body.



            class Robot {

      public void speak(String text) {

            System.out.println(text);

           

      }

      public void jump(int height){

            System.out.println("jumping: " + height);

      }

      public void move(String direction, double distance){

            System.out.println("moving " + distance + "metres in direction" +direction);

      }

}





public class App {



      public static void main(String[] args){

            Robot sam = new Robot();

           

            sam.speak("Hi I'm Sam.");

            sam.jump(7);

            sam.move("west", 12.2);

            String greeting = "Hello there. ";

            sam.speak(greeting);

           

            int value = 14;

                        sam.jump(value);

           

      }

}