I used the paid version of Progate to clear all Java courses. Java courses are divided into two types. (As of 06/03/2018) The learning course is a course to understand the basics while having the slides explain how Java works. The dojo course uses what you learned in the learning course while looking at the minimum explanation. This is a course to make one work. These are the three features that I found amazing about Java.
--Method ... A mechanism to create an action by yourself and issue a command to a program ――Object-oriented ... A mechanism to create characters (classes) with actions in the world of programs --Inheritance ... When creating a lot of characters (classes), a mechanism to combine information and actions common to them into one
In Java, one character is called a class. I decided to make one game by myself using these three functions.
The theory of capital was thought by an uncle named Marx, "In this world, servants and office workers are poor, and those who own their own company or product become rich." The idea is.
To confirm this, I created a class called Capitalist (People with products / Cap. Below) and Worker (Wor. Below), and made a game to see the movement of their second money. ..
These two are made up of four statuses (name, HP, money, product).
Capitalist person1 = new Capitalist("Capitalist", 10, 500000, 0);
Worker person2 = new Worker("Worker", 10, 500000, 0);
Both have the same initial status.
In this game, we created a class called Person that Cap. And Wor. Inherit.
class Person {
protected String name;
protected int health;
protected int money;
protected double product;
Person(String name, int health, int money, double product){
this.name = name;
this.health = health;
this.money = money;
this.product = product;
}
public String getName() {
return this.name;
}
public int getHealth() {
return this.health;
}
public int getMoney() {
return this.money;
}
public double getProduct() {
return this.product;
}
public void printData(){
System.out.println("name:" + this.name);
System.out.println("Physical strength:" + this.health);
System.out.println("savings:" + this.money);
System.out.println("Product" + this.product);
}
}
The status of the two is encapsulated so that they can only be retrieved from a class that inherits from this class. The method common to both is the PrintOut () method that prints the status.
class Worker extends Person{
public Worker(String name, int health, int money, double product){
super(name, health, money, product);
}
public void work(){
if(this.health == 5){
this.health += 5;
this.money -= 20000;
}else if(this.health > 0){
this.health-= 2;
this.money+= 10000;
}else{
this.health += 5;
this.money -= 20000;
}
}
}
Wor. Works 5 days and rests 2 days repeatedly. I work when I have HP, and when I don't have HP, I rest until I'm completely recovered. In this game "Working" means reducing HP by 2 and increasing money by 10,000. "Resting" means increasing your HP by 5 and reducing your money by 20000.
In other words, Wor. Earns about 200,000 yen in a month and spends about 160,000 yen, so You can collect about 40,000 yen every month.
class Capitalist extends Person{
public Capitalist(String name, int health, int money, double product){
super(name, health, money, product);
}
public void manage(){
invest();
harvest();
}
public void invest(){
if(this.health == 5){
this.health += 5;
this.money -= 20000;
}else if(this.health > 0){
this.health -= 2;
this.money -= 10000;
this.product += 0.02;
}else{
this.health += 5;
this.money -= 20000;
}
}
public void harvest(){
if(this.product >= 1){
this.money += (int)product*1000;
}
}
}
Cap. Invests 5 days and rests 2 days repeatedly. Invest when you have HP, and rest until you're completely recovered when you don't have HP. In this game "Working" means that your HP is reduced by 2, your money is reduced by 10,000, and your product status is increased by 0.02. "Resting" means increasing your HP by 5 and reducing your money by 20000. In other words, Cap. Saves about 360,000 yen in one month.
Another Cap. Has an action called harvest. When Cap. Makes a product (product> = 1), you will receive the number of the product * 1000 yen every day. One product is finally completed in 50 days.
Repeating the actions of Cap. And Wor., Wor. Made more money in the first few years, but decades later Cap. Became richer.
Of course this game is not accurate. Wor. May have salary increases, bonuses, job change events, Cap. May have investment failures and investment efficiency events.
However, I found from this graph that what is said in the theory of capital is roughly correct. I'll aim to be a capitalist!
Recommended Posts