• Skip to main content
  • Skip to primary sidebar

Founder at work

Master the skills to create and launch your next SaaS company

  • About Me
  • Reviews
  • Resources
  • Community
  • Contact
  • Lessons
  • Series
  • Search
  • Login

How to get started using UML?

April 7, 2013 by Rick Hernandez Leave a Comment

Unified modeling Language is a standard that is used to model certain Object Oriented principles. In the short example i will display what Composition is and how its used.

Lets get started with the main App Concert, this the main program where
A type of Time is created and italicized by the passed parameter. giving us
a start and end time. then a concert type is created and then they are printed
out the console.

Main Class
public class ConcertApp 
{
    public static void main(String[] args)
    {
        Time start = new Time(3,12,1);
        Time end = new Time(1,0,0);
        Concert myConcert = new Concert("one long concert", start , end);
        System.out.printf("%s", myConcert);
    }
}
Concert Class

Lets take a closer look at the concert class, it has a couple of private members
which are type of Time, then the concert main method is overloaded, then at last we have
a toString to return the specific format.

public class Concert 
{
    private String name;
    private Time startTime;
    private Time endTime;

    public Concert(String n, Time start, Time end)
    {
        name = n;
        startTime = start;
        endTime = end;
    }

    @Override
    public String toString()
    {
        return String.format("%s %s %s", name, startTime, endTime);
    }    
}
Class Time

The Class Time has some private integers hour, minute, and seconds. Then we have
our setters and finish up with the toString.

public class Time
{
    private int hours;
    private int minutes;
    private int seconds;

    public Time(int h, int m, int s)
    {
        setTime(h, m, s);
    }

    public Time()
    {
    }

    public void setHours(int h)
    {
        hours = ((h >= 0 && h < 24) ? h : 0);
    }
    public void setMinutes(int m)
    {
        minutes = ((m >= 0 && m < 60) ? m : 0);
    }
    public void setSeconds(int s)
    {
        seconds = ((s >= 0 && s < 60) ? s : 0);
    }


    public void setTime(int h, int m, int s)
    {
        setHours(h);
        setMinutes(m);
        setSeconds(s);
    }

    public String toString()            
    {
        return String.format("%02d:%02d:%02d", hours, minutes, seconds);
    }
}
Rick Hernandez

I always had a passion for the field of STEM (Science, Technology, Engineering, and Math) and I knew I wanted to do something to make a difference in the world. I just didn’t know where to start. I was an immigrant in a new country, grew up in a tough environment, and wasn’t sure how… Read More

Share this:

  • Click to share on Twitter (Opens in new window)
  • Click to share on Facebook (Opens in new window)

Related

Filed Under: Java, Programming

Primary Sidebar

Learn How To Take Your Idea And Convert It Into An App From Scratch Even If You Have Never Written A Single Line Of Code.

  • How to Find Your Next Great App Idea
  • The Secret To Getting PAID To Build Your Own App
  • How To Create Your App (SaaS, Mobile, VR, AR, Game)
  • How To Monetize Your Apps
Learn More
4.82 Ratings

Copyright © 2025 · JSecademy Blog Theme on Genesis Framework · WordPress · Log in