Gregory Desrosiers Montreal

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Thursday, 30 May 2013

JAVA Program: Object-Oriented Programming Class, the PopMusicClass

Posted on 17:09 by Unknown
Hello, everyone.

I want to share with you something new out of my knowledge of JAVA Programming; a fresh, original class I've designed where everything's quite simple, but is new to people who are yet unaware of the object-oriented programming approach.

Basically, the purpose of this approach is to create programs and methods that can be reused by any other programs developed in the same programming language. In fact, this approach was done to design the original JAVA classes that most JAVA programmers experience every time we write something. String, Short, Integer, File, Exception, Scanner, JLabel; all of the net classes that exist in today's versions of JAVA SDKs.

Here, what I have designed here is a class called PopMusicClass where it is designed to hold data of pop culture songs, especially those made today. It's not Beethoven or Scott Joplin's music. It's rather the music that we are making today.

I'll show you the code first, then tell you what it consists of.


public final class PopMusicClass
{
private String nameOfSong;
private String artist;
private String nameOfAlbum;

private short yearOfRelease;
private String releaseDate;

private String recordingStudio;
private String mixingStudio;

private String writers;
private String publishingRecord;
private String distributionStudio;

private String format;

public static void main(String[] args) // Testing only
{
PopMusicClass object1 = new PopMusicClass();
PopMusicClass object2 = new PopMusicClass("Firework", "Katy Perry", "Teenage Dream", (short)2010, "October 26, 2010",
"Roc the Mic Studios", "Roc the Mic", "Perry, Mikkel S. Eriksen, Tor Erik Hermansen, Sandy Wilhelm, Ester Dean",
"Capitol Records", "N/A", "CD, Downloadable form");

System.out.println(object1 + "\n\n" +  object2);
}

public PopMusicClass()
{
nameOfSong = null;
artist = null;
nameOfAlbum = null;

yearOfRelease = 1930;
releaseDate = null;

recordingStudio = null;
mixingStudio = null;

writers = null;
publishingRecord = null;
distributionStudio = null;
format = null;
}

public PopMusicClass(String nameOfSong, String artist, String nameOfAlbum, short yearOfRelease, String releaseDate, 
String recordingStudio, String mixingStudio, String writers, String publishingRecord, String distributionStudio,
String format)
{
this.nameOfSong = nameOfSong;
this.artist = artist;
this.nameOfAlbum = nameOfAlbum;

this.yearOfRelease = yearOfRelease;
this.releaseDate = releaseDate;

this.recordingStudio = recordingStudio;
this.mixingStudio = mixingStudio;

this.writers = writers;
this.publishingRecord = publishingRecord;
this.distributionStudio = distributionStudio;
this.format = format;
}

public void setNameOfSong(String nameOfSong)
{
this.nameOfSong = nameOfSong;
}

public void setArtist(String artist)
{
this.artist = artist;
}

public void setNameOfAlbum(String nameOfAlbum)
{
this.nameOfAlbum = nameOfAlbum;
}

public void setYearOfRelease(short yearOfRelease)
{
this.yearOfRelease = yearOfRelease;
}

public void setReleaseDate(String releaseDate)
{
this.releaseDate = releaseDate;
}

public void setRecordingStudio(String recordingStudio)
{
this.recordingStudio = recordingStudio;
}

public void setMixingStudio(String mixingStudio)
{
this.mixingStudio = mixingStudio;
}

public void setWriters(String writers)
{
this.writers = writers;
}

public void setPublishingRecord(String publishingRecord)
{
this.publishingRecord = publishingRecord;
}

public void setDistributionStudio(String distributionStudio)
{
this.distributionStudio = distributionStudio;
}

public void setFormat(String format)
{
this.format = format;
}

public String getNameOfSong()
{
return nameOfSong;
}

public String getArtist()
{
return artist;
}

public String getNameOfAlbum()
{
return nameOfAlbum;
}

public short getYearOfRelease()
{
return yearOfRelease;
}

public String getReleaseDate()
{
return releaseDate;
}

public String getRecordingStudio()
{
return recordingStudio;
}

public String getMixingStudio()
{
return mixingStudio;
}

public String getWriters()
{
return writers;
}

public String getPublishingRecord()
{
return publishingRecord;
}

public String getDistributionStudio()
{
return distributionStudio;
}

public String getFormat()
{
return format;
}

public boolean equals(Object o)
{
if (o instanceof PopMusicClass)
{
PopMusicClass object = ((PopMusicClass)o);

return this.nameOfSong.equals(object.nameOfSong) && this.artist.equals(object.artist) &&
this.nameOfAlbum.equals(object.nameOfAlbum) && this.yearOfRelease == object.yearOfRelease &&
this.releaseDate.equals(object.releaseDate) && this.recordingStudio.equals(object.recordingStudio) &&
this.mixingStudio.equals(object.mixingStudio) && this.writers.equals(object.writers) &&
this.publishingRecord.equals(object.publishingRecord) && 
this.distributionStudio.equals(object.distributionStudio) &&
this.format.equals(object.format);
}
else
return false;
}

public String toString()
{
return nameOfSong + "\nArtist: " + artist + "\n\nName of Album: " + nameOfAlbum + "\n\nYear of Release: " + yearOfRelease + 
"\nRelease Date: " + releaseDate + "\n\nRecording Studio: " + recordingStudio + "\nMixing Studio: " + mixingStudio + 
"\nWriters: " + writers + "\n\nPublishing Record: " + publishingRecord + "\n\nDistribution Studio: " + distributionStudio +
"\nFormat: " + format;
}
}

The program consists of  11 fields, two constructors, 11 set methods, 11 get methods, and two methods that override those with the same name and signature from the Object class: equals and toString. Oh, and the final modifier in the header of the class definition is to tell the compiler that this class cannot be inherited.

The main method you see at the top of the code is to test with constructing and displaying them on the console. The other methods were not tested for validation.

For those of you who don't know what Object-Oriented Programming is, it's simply a term to describe reusable programs and data structures that the only way you can modify data and prevent so many bugs happening in your program is to call in the class methods defined in the object you create. This is to prevent accidental corruption that can bug your programs and cause multiple problems.

How it works is that the data that each object carries is encapsulated in such a way that the user has no way of gaining access to that data directly; the only way to access it is indirectly through the methods that operate on it. That's why the data fields are declared with the access specifier "private." When it comes time to program something else other than this class, it's important to ensure that we do not actually call in one of the object's fields and assign it with a new value or reference to an object.

As for the methods, because the user or programmer is able to call in those methods in a different program, they are declared with either "default", "protected:, or even "public" access modifier.

Anyway, I apologize to say, but I'm kind of lazy to keep on talking about this. I think I'll leave other explanations for another time, so I'll see you later!

Ciao!
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • The Quebec Ministerial Exam of College English (English Exit Exam)
    Hello, everyone. How you doing? I'm good. There is some unfortunate news for me to deliver, though I am planning to try to work myself a...
  • Computer Game Collection
    Hello, people! Before I happen to leave this very foundation of Champlain College Saint-Lambert (that's where I'm learning to get wh...
  • String Letter Counter (JAVA Program)
    Hello, guys. This is another JAVA Program I want to share with you guys. It's a counter for a specific letter in an entered string strai...
  • DOS Games to Play
    Hello, people. If there's one thing that I want to do when I have lots of money, it's to play full version DOS Games on my Windows P...
  • JAVA Program: Command-based String Remover in Text Files
    Hello, everyone. Let me share with you the code on one of the programs I did back in March 2013, while doing my Data Structures class. This ...
  • The Black Glove [Short Poem by me]
    This is a poem written by me back in April 2010. I'm not sure if this was for an assignment, but this is what I got. It may not be good ...
  • Fundraising Project (To Autism Society Canada)
    Hi, everyone! How are you people doing? I am feeling tired and stuff, but there are a couple of things I want to bring up with you. Tomorrow...
  • Best VGM Series
    Hello, guys. I want to present to you a series of YouTube imports of video game music, with some of them already recorded but in a form that...
  • Princess Peach In India [Story Idea]
    Here's a really fancy story I have made, although it is more of an initial idea and comes from a visual I had more than two years ago. E...
  • Super Mario Script 1 (v 2.3) [Super Mario Galaxy font, with a few photos]
    Hello there. Do you recognize the font of this text? I'll give you two clues. The one below is the a sample sentence of different sizes....

Blog Archive

  • ▼  2013 (38)
    • ►  August (2)
    • ►  July (9)
    • ►  June (12)
    • ▼  May (12)
      • JAVA Program: Number Loop (Experimental Program of...
      • JAVA Program: Displaying Unlimited Strings on a GU...
      • JAVA Program: Command-based String Remover in Text...
      • Arcade Games to check out
      • JAVA Program: Random 0s and 1s Table with Refresh ...
      • JAVA Program: Object-Oriented Programming Class, t...
      • Announcement on "The Asperger Computer"
      • JAVA Program : Hello World!
      • Introducing myself (original blog on Autism Suppor...
      • Demonstration of JAVA Classes
      • Non-fiction e-book, The Asperger Computer, reveals...
      • The Asperger Computer - Facebook Edition
    • ►  April (2)
    • ►  January (1)
  • ►  2012 (24)
    • ►  December (13)
    • ►  November (3)
    • ►  October (5)
    • ►  September (1)
    • ►  August (2)
Powered by Blogger.

About Me

Unknown
View my complete profile