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);

           

      }

}