Object-oriented (java) with Strike Gundam

Introduction

Created for object-oriented learning. I imagined the assembly of Strike Gundam and Strike Dagger, and created it with the common features of each in mind.

procedure

It was created by the following procedure.

  1. Creating an interface → Three types of striker packs are used as the interface.
  2. Creating a superclass → The X100 series frame is a super class.
  3. Creating a subclass → Strike Gundam and Strike Dagger are subclasses.
  4. Creating a Factory class → Create an instance in the Factory class and describe to call the method.

Creating an interface

Create an ale, sword, and launcher in the form of an interface, and describe each armament as follows.

Striker.java


package practice;

public interface Striker {
	
	String[] arrayAile = {"57mm high energy beam rifle", "Beam saber", "Anti-beam shield"};
	String[] arraySword = {"15.78m anti-ship sword "Schwert Geber"", "Beam Boomerang "Midas Messer"", "Rocket anchor "Panzer Eisen""};
	String[] arrayLauncher = {"320mm ultra-high impulse cannon "Agni"", "120mm anti-ship Vulcan cannon", "350mm gun launcher"};

}

Creating a superclass

Strike Gundam and Strike Dagger use the X100 series frame as the basic skeleton. Another feature is the striker pack system. Describe these features in X100frame.java as follows.

X100frame.java


package practice;

//Since it is assumed that it will be inherited, it is abstract.
public abstract class X100frame {
	private String name = "";
	private String type = "X100 series frame";
	private String feature = "Striker pack system";
	
	public X100frame(String name) {
		this.name = name;
	}
	
	public String getName() {
		return this.name;
	}
	
	public String getType() {
		return this.type;
	}
	
	public String getFeature() {
		return this.feature;
	}

    public void list() {
		System.out.println("Armed list:");
		System.out.println("-------------------------");
	}

//Since it will be overridden on the subclass side, write an empty method
    public abstract void printData();
	public abstract void printDataPersonal();
    public abstract void printDataAile();
	public abstract void printDataSword();
	public abstract void printDataLauncher();
	
}

Creating a subclass

Create Strike Gundam as STRIKE class and Strike Dagger as DAGGER class. At that time, inherit the X100frame class so that the three interfaces created in step 1 can also be used.

STRIKE.java


package practice;

//Inherit the X100frame class and enable the interface Striker
public class STRIKE extends X100frame implements Striker {

	public STRIKE() {super("Strike Gundam"); }
//Features of bare strike only
	private String Model = "GAT-X105";
	private String Armor = "Phase shift armor";
	private double height = 17.72;
	private double weight = 64.80;
	private String WEAPON[] = {"Egerstern", "Armor Schneider"};

//Method to output the features of only the plain strike
    @Override
	public void printData() {
		System.out.println("Mobile suit name:" + this.getName());
		System.out.println("Model number:" + this.Model);
    //Frames and features inherit from the X100frame class
		System.out.println("flame:" + this.getType());
		System.out.println("Feature:" + this.getFeature());
		System.out.println("Armor:" + this.Armor);
		System.out.println("Overall height:" + this.height + "m");
		System.out.println("weight:" + this.weight + "t");
		System.out.println();
	}

    @Override
	public void printDataPersonal() {
		for(int a = 0; a < WEAPON.length; a++ ) {
			System.out.print(WEAPON[a] + " ");
			}
		System.out.println();
		System.out.println("------------");
	}

//Outputs armament when equipped with a striker pack
    @Override
	public void printDataAile() {
		for(int a = 0; a < arrayAile.length; a++ ) {
			System.out.print(arrayAile[a] + " ");
			}
		System.out.println();
		System.out.println("------------");
	}
	
	@Override
	public void printDataSword() {
		for(int a = 0; a < arraySword.length; a++ ) {
			System.out.print(arraySword[a] + " ");
			}
		System.out.println();
		System.out.println("------------");
	}
	
	@Override
	public void printDataLauncher() {
		for(int a = 0; a < arrayLauncher.length; a++ ) {
			System.out.print(arrayLauncher[a] + " ");
			}
		System.out.println();
		System.out.println("------------");
	}
	
}

Strike Gundam

DAGGER.java


package practice;

//Inherit the X100frame class and enable the interface Striker
public class DAGGER extends X100frame implements Striker {

	public DAGGER() {super("Strike Dagger"); }
//Features of the bare strike dagger only
	private String Model = "GAT-01A1";
	private String Armor = "Laminated armor (body only)";
	private double height = 18.00;
	private double weight = 57.05;
	private String WEAPON[] = {"Egerstern", "52mm cannon pod", "Beam carbine", "12.5mm anti-personnel machine gun x 2"};

//Method to output the features of the elementary strike dagger only
    @Override
	public void printData() {
		System.out.println("Mobile suit name:" + this.getName());
		System.out.println("Model number:" + this.Model);
    //Frames and features inherit from the X100frame class
		System.out.println("flame:" + this.getType());
		System.out.println("Feature:" + this.getFeature());
		System.out.println("Armor:" + this.Armor);
		System.out.println("Overall height:" + this.height + "m");
		System.out.println("weight:" + this.weight + "t");
		System.out.println();
	}

    @Override
	public void printDataPersonal() {
		for(int a = 0; a < WEAPON.length; a++ ) {
			System.out.print(WEAPON[a] + " ");
			}
		System.out.println();
		System.out.println("------------");
	}

//Outputs armament when equipped with a striker pack
    @Override
	public void printDataAile() {
		for(int a = 0; a < arrayAile.length; a++ ) {
			System.out.print(arrayAile[a] + " ");
			}
		System.out.println();
		System.out.println("------------");
	}
	
	@Override
	public void printDataSword() {
		for(int a = 0; a < arraySword.length; a++ ) {
			System.out.print(arraySword[a] + " ");
			}
		System.out.println();
		System.out.println("------------");
	}
	
	@Override
	public void printDataLauncher() {
		for(int a = 0; a < arrayLauncher.length; a++ ) {
			System.out.print(arrayLauncher[a] + " ");
			}
		System.out.println();
		System.out.println("------------");
	}
	
}

Strike Dagger

Creating a Factory class

Create an instance and call each method.

Factory.java


package practice;

public class Factory {
	
	public static void main(String[] args) {
		STRIKE s = new STRIKE();
		DAGGER d = new DAGGER();
		s.printData();
		s.list();
		s.printDataPersonal();
		s.printDataAile();
		s.printDataSword();
		s.printDataLauncher();
		System.out.println();
		d.printData();
		d.list();
		d.printDataPersonal();
		d.printDataAile();
		d.printDataSword();
		d.printDataLauncher();
	}
	
}

Output result

It was output like this.

Mobile suit name: Strike Gundam
Model number: GAT-X105
Frame: X100 series frame
Features: Striker pack system
Armor: Phase shift armor
Overall height: 17.72m
Weight: 64.8t

Armed list:
-------------------------
Egerstern Armor Schneider
------------
57mm high energy beam rifle beam saber vs beam shield
------------
15.78m anti-ship sword "Schwert Geber" Beam boomeran "Midas Messer" Rocket anchor "Panzer Eisen"
------------
320mm ultra-high impulse gun "Agni" 120mm anti-ship Vulcan gun 350mm gun launcher
------------

Mobile suit name: Strike Dagger
Model number: GAT-01A1
Frame: X100 series frame
Features: Striker pack system
Armor: Laminated armor (body only)
Overall height: 18.0m
Weight: 57.05t

Armed list:
-------------------------
Egerstern 52mm Cannon Pod Beam Carbine 12.5mm anti-personnel machine gun x 2
------------
57mm high energy beam rifle beam saber vs beam shield
------------
15.78m anti-ship sword "Schwert Geber" Beam boomeran "Midas Messer" Rocket anchor "Panzer Eisen"
------------
320mm ultra-high impulse gun "Agni" 120mm anti-ship Vulcan gun 350mm gun launcher
------------

That is all.

Recommended Posts

Object-oriented (java) with Strike Gundam
[Java] Object-oriented
Object-oriented FizzBuzz (Java)
[Java] Object-oriented summary_Part 1
[Java] Object-oriented syntax-Constructor
Object-oriented (Java) basics
[Java] Object-oriented summary_Part 2
[Java] Object-oriented syntax-Package
Install java with Homebrew
Change seats with java
Install Java with Ansible
Comfortable download with JAVA
Switch java with direnv
Download Java with Ansible
Let's scrape with Java! !!
Build Java with Wercker
Endian conversion with JAVA
Easy BDD with (Java) Spectrum?
Use Lambda Layers with Java
Java multi-project creation with Gradle
Getting Started with Java Collection
Java Config with Spring MVC
Basic Authentication with Java 11 HttpClient
Check compliance with object-oriented exercise
Let's experiment with Java inlining
Run batch with docker-compose with Java batch
[Template] MySQL connection with Java
Rewrite Java try-catch with Optional
Install Java 7 with Homebrew (cask)
[Java] JSON communication with jackson
Java to play with Function
Enable Java EE with NetBeans 9
[Java] JavaConfig with Static InnerClass
Let's operate Excel with Java! !!
Version control Java with SDKMAN
RSA encryption / decryption with java 8
Paging PDF with Java + PDFBox.jar
Object-oriented summary by beginners (Java)
[Java] Content acquisition with HttpCliient
Java version control with jenv
Troubleshooting with Java Flight Recorder
Java 3 major elements (object-oriented) memorandum
Streamline Java testing with Spock
Connect to DB with Java
Connect to MySQL 8 with Java
Error when playing with java
Using Mapper with Java (Spring)
Java study memo 2 with Progate
Getting Started with Java Basics
Seasonal display with Java switch
Use SpatiaLite with Java / JDBC
Study Java with Progate Note 1
Compare Java 8 Optional with Swift
HTML parsing with JAVA (scraping)
Run Java VM with WebAssembly
Screen transition with swing, java
Java unit tests with Mockito
[Java 8] Duplicate deletion (& duplicate check) with Stream
Java lambda expressions learned with Comparator
Build a Java project with Gradle
Install java with Ubuntu 16.04 based Docker