Java: Program Anatomy & Primitive Data Type Application (Animal Crossing Edition)

In this post, I’ll be discussing the program anatomy and primitive data type application for Java programming. To help me explain it all, I’ll be using the Feynman technique and the Nintendo game Animal Crossing.

This post is part of my Feynman Technique & 20 Hour Method challenge. For more info, please click here.

In a previous post, I discussed Java variables and Data Types. This time around, we’re going to be talking about the anatomy of the basic Java programming code and then use primitive data types in an application.

Anatomy of a Basic Java Application:

1  public class CapitalismIsACage {
2
3     public static void main (String[] args) {
4     System.out.println("Tom Nook is shaking me down for Bells.");
5     }
6  }

Line 1:

  • Public – listed twice in the code above is what they call an access modifier. Think of them as permission switches. There are actually several to choose from: default, private, protected, “package private”, and public. Each has its own rules of who and what gets access to the information side.
  • class – A class is what’s described as a blueprint for an object. It tells us what our object is supposed to look like and do. In this case, the class is an intro to the name of our application, which is…CapitalismIsACage.
  • CapitalismIsACage – This is the name of our class. It tidily sums up Tom Nook’s hold on all Animal Crossing players, since the very first incarnation of the game, but I digress.

Line 3:

  • { } – if you see curly braces, know that whatever is in them is part of that package or scope. Because other packages can live within a larger package (line 4) it lets us know what code is part of which group.
  • static – The variable or method that’s attached to the “static” designation is available at the class level. It actually belongs to the class.
  • void – The method doesn’t return anything.
  • main – Name of the function.
  • ( ) – The brackets are the designation of a function.
  • String[] args – The parameters of the function, and a place for the arguments for the function (if there are any).
  • public static void main (String [] args) – This is called the “main method”. If you use a java compiler, you’ll notice a “run” function that is made available on this line. It is because this is the starting point of the program. The main method is executed first when a program is run.

Line 4:

  • System – this is a baked-in java class keyword that represents our own system.
    • out – it’s a field in the system class.
    • println – this is the shortcode for “print line”. Although we aren’t printing anything, it means we’re expecting an output for what’s in ( ).

The output is pretty straight forward:

Tom Nook is shaking me down for Bells.

Java Primitive Data Type Application

We’ve discussed Java data types in a previous post, so we won’t go over them here, but, we will be going over how they are applied to an actual application. Here’s my code:

1  public class AnimalCrossingSpecs{
2
3      public static void main(String[] args) {
4          byte numberOnlinePlayers = 8;
5          byte numberIslandResidents = 4;
6
7          short museumItemsAvailable = 316;
8          short potentialNeighbors = 397;
9
10         int firstHouseLoanCost = 98000;
11         int houseUpgradeCost = 198000;
12         int backRoomAdditionCost = 348000;
13         int leftRoomAdditionCost = 548000;
14         int rightRoomAdditionCost = 758000;
15         int secondFloorAdditionCost = 1248000;
16
17         long basementAdditionCost = 2498000L;
18         long numberOfGlobalPlayers = 11000000L;
19
20         float gamePrice = 59.99F;
21         float gameFileSize = 6.8F;
22
23         double oddsOfCatchingACoelacanth = 2.333333331;
24
25         boolean seasonalUpdates = true;
26         char ESRBRating = 'E';
27
28         System.out.println("Animal Crossing: New Horizons");
29         System.out.println("Price: $" + gamePrice);
30         System.out.println("File size : " + gameFileSize + "GB");
31         System.out.println("ESRB Rating: " + ESRBRating + " (for Everyone)");
32         System.out.println("Number of co-op players per island: " + numberIslandResidents);
33         System.out.println("Number of online players per island: " + numberOnlinePlayers);
34         System.out.println("Choices of potential neighbors: " + potentialNeighbors + "characters");
35         System.out.println("Seasonal Updates: " + seasonalUpdates);
36         System.out.println("Items available to build out your museum : " + museumItemsAvailable + " (fossils, bugs, artwork, and aquatic wildlife)");
37         System.out.println("Odds of catching a Coelacanth: " + oddsOfCatchingACoelacanth + "%");
38         System.out.println("Cost of paying off your first home: " + firstHouseLoanCost + " Bells");
39         System.out.println("Cost of paying off your first home upgrade " + houseUpgradeCost + " Bells");
40         System.out.println("Cost of 1st room addition: " + backRoomAdditionCost + " Bells");
41         System.out.println("Cost of 2nd room addition: " + leftRoomAdditionCost + " Bells");
42         System.out.println("Cost of 3rd room addition " + rightRoomAdditionCost + " Bells");
43         System.out.println("Cost of top floor addition: " + secondFloorAdditionCost + " Bells");
44         System.out.println("Cost of basement addition: " + basementAdditionCost + " Bells");
45         System.out.println("Number of global players: " + numberOfGlobalPlayers);
46
47     }
48  }

In this code we addressed all the primitive variable types:

  • Whole numbers:
    • byte
    • short
    • int
    • long
  • Floating-point numbers:
    • Float
    • Double
  • Booleans
  • Single characters (Char)

Each of them followed the same method (data type, name = value;). You might have noticed there are a lot of “System.out” lines (starting from line 28) that utilize each of these declared variables. And, if you haven’t realized it, variable names are case sensitive and when called are exactly as declared and in camel casing.

At the end of every float and long value, there’s an “F” or an “L” following after it. The reason why is because it prevents them from being converted into an efficiency number, like a shortcode version of itself. The F and L ensure that when it gets reproduced, it does so as-listed. But if you don’t mind the shortcode, you can leave the letters out. As a reminder, shortened numbers don’t always revert back to their exact values, so if you require an exact output, add the F/L.

Output:

Animal Crossing: New Horizons
Price: $59.99
File size : 6.8GB
ESRB Rating: E (for Everyone)
Number of co-op players per island: 4
Number of online players per island: 8
Choices of potential neighbors: 397characters
Seasonal Updates: true
Items available to build out your museum : 316 (fossils, bugs, artwork, and aquatic wildlife)
Odds of catching a Coelacanth: 2.333333331%
Cost of paying off your first home: 98000 Bells
Cost of paying off your first home upgrade 198000 Bells
Cost of 1st room addition: 348000 Bells
Cost of 2nd room addition: 548000 Bells
Cost of 3rd room addition 758000 Bells
Cost of top floor addition: 1248000 Bells
Cost of basement addition: 2498000 Bells
Number of global players: 11000000

Yes, Animal Crossing can be hella expensive when you play and Tom Nook WILL take advantage of the fact that you are on an island and he’s the sole provider of everything! Tom Nook is your home builder, your banker, loan officer, vendor, and travel agent, but at least you know you’re not alone.

Happy coding from the Cheng-Delgrosso family.

…well, officially in a couple of months. 👰🤵

For more info on program anatomy and primitive data type application for Java, please click on the links below: