Generate Java code from RAPTOR.
This tutorial will teach us the steps in generating Java code from Raptor Flowchart. We can generate structured and object-oriented code in OO(Object-oriented) mode. We can use the OO mode in Raptor when we create object-oriented flowcharts with classes.
Create Class in Raptor
Example
Let’s create a Dog class and instantiate an object in the Main flowchart. We will generate code for this flowchart.
Sample Dog class. The main flowchart instantiates an object of the Dog class and prints the object information to the Master console window.
UML Class Diagram
Main Flowchart
Generate Java Code
Choose Generate >> Java menu option to generate the code. However, we need to modify the code to change the ?? to datatypes and correct print statements as per the Java language specification.
For example, to instantiate an object. The generated statement would be:
# Creating Objects
?? dogObject = ??;
We need to change this to:
Dog dogObject = new Dog(); // This calls the default no-arg constructor.
# Print statements
printLine(“Name = ” + this.getName());
We need to change this to:
System.out.println(“Name = ” + this.getName());
The generated code is the default IDE on the system. ( IntelliJ IDEA).
Java Code
Main Flowchart
/** * NAME: * DATE: * FILE: * COMMENTS: */ public class Object_Oriented_Java_main { public static void main(String[] args) { // declare variables ?? dogObject = ??; dogObject = new Dog("Tommy",2,3.5); printLine("Name =" + dogObject.getName()); printLine("Age =" + dogObject.getAge()); printLine("Weight =" + dogObject.getWeight()); } // close main } // close Object_Oriented_Java
Dog Class
/** * NAME: * DATE: * FILE: www.TestingDocs.com * COMMENTS: File created by Raptor UML Mode */ public class Dog { private int age; private double weight; private String name; public Dog(String name, int age, double w) { this.name = name; this.age = age; this.weight = w; } // close Dog public int getAge() { return this.age; } // close getAge public double getWeight() { return this.weight; } // close getWeight public void toString() { printLine("Name = " + this.getName()); printLine("Age = " + this.getAge() + " years"); printLine("Weight = " + this.getWeight() + " kg"); } // close toString public String getName() { return this.name; } // close getName public Dog() { } // close Dog } // close Dog
—
Raptor Tutorials on this website can be found at: