Site icon TestingDocs.com

Generate Java code from Raptor Flowchart

Overview

In this tutorial, we will learn steps involved to Generate Java code from Raptor Flowchart. We can generate structured code as well as object-oriented code in OO(Object-oriented) mode. When we create object-oriented flowcharts with classes we can use the OO mode in Raptor.

https://www.testingdocs.com/modes-in-raptor-flowchart/

Create Class in Raptor

https://www.testingdocs.com/creating-objects-in-raptor-flowcharts/

Example

Let’s create a class called Dog 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 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 generate 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 in 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:

https://www.testingdocs.com/raptor-a-flowchart-tool/

RAPTOR official website: https://raptor.martincarlisle.com/

Exit mobile version