The Help With Assignment Blog is intended to provide with tips and tricks to students so that they are able to do better at school and college. The Blog is associated with HelpWithAssignment.com (HwA), a leading provider of online tuitions in University subjects.

Showing posts with label java assignment help. Show all posts
Showing posts with label java assignment help. Show all posts

Friday, September 2, 2011

Java Programming Example

Java Programming Sample

The programming example is about how to calculate the factorial of a number

Java Factorial Example

This Java Factorial Example shows how to calculate factorial of a given number using Java.

public class NumberFactorial {

public static void main(String[] args) {

int number = 5;

/*

* Factorial of any number is !n.

* For example, factorial of 4 is 4*3*2*1.

*/

int factorial = number;

for(int i =(number - 1); i > 1; i--)

{

factorial = factorial * i;

}

System.out.println("Factorial of a number is " + factorial);

}

}

/*

Output of the Factorial program would be

Factorial of a number is 120

*/

For more details you can visit our websites at http://www.helpwithassignment.com/programing-assignment-help and http://www.helpwiththesis.com

A Simple Example of Writing Code in Java

Java Programming Example

This Java Programming Example is to find the area of a circle

Calculate Circle Area using Java Example

This Calculate Circle Area using Java Example shows how to calculate area of circle using it's radius.

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

public class CalculateCircleAreaExample {

public static void main(String[] args) {

int radius = 0;

System.out.println("Please enter radius of a circle");

try

{

//get the radius from console

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

radius = Integer.parseInt(br.readLine());

}

//if invalid value was entered

catch(NumberFormatException ne)

{

System.out.println("Invalid radius value" + ne);

System.exit(0);

}

catch(IOException ioe)

{

System.out.println("IO Error :" + ioe);

System.exit(0);

}

/*

* Area of a circle is

* pi * r * r

* where r is a radius of a circle.

*/

//NOTE : use Math.PI constant to get value of pi

double area = Math.PI * radius * radius;

System.out.println("Area of a circle is " + area);

}

}

/*

Output of Calculate Circle Area using Java Example would be

Please enter radius of a circle

19

Area of a circle is 1134.1149479459152

*/

For more details you can visit our websites at http://www.helpwithassignment.com/programing-assignment-help and http://www.helpwiththesis.com

An Example in Java Programming

Java Program Example

The example Java program is about how to calculate the area of a rectangle.

Calculate Rectangle Area using Java Example

This Calculate Rectangle Area using Java Example shows how to calculate area of Rectangle using it's length and width.

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

public class CalculateRectArea {

public static void main(String[] args) {

int width = 0;

int length = 0;

try

{

//read the length from console

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

System.out.println("Please enter length of a rectangle");

length = Integer.parseInt(br.readLine());

//read the width from console

System.out.println("Please enter width of a rectangle");

width = Integer.parseInt(br.readLine());

}

//if invalid value was entered

catch(NumberFormatException ne)

{

System.out.println("Invalid value" + ne);

System.exit(0);

}

catch(IOException ioe)

{

System.out.println("IO Error :" + ioe);

System.exit(0);

}

/*

* Area of a rectangle is

* length * width

*/

int area = length * width;

System.out.println("Area of a rectangle is " + area);

}

}

/*

Output of Calculate Rectangle Area using Java Example would be

Please enter length of a rectangle

10

Please enter width of a rectangle

15

Area of a rectangle is 150

*/

For more details you can visit our websites at http://www.helpwithassignment.com/programing-assignment-help and http://www.helpwiththesis.com

Java Subclassing and Inheritance With An Example

Java Subclassing and Inheritance

Classes in Java exist in hierarchy. A class in Java can be declared as a subclass of another class using the extends keyword. A subclass inherits variables and methods from its superclass and can use them as if they were declared within the subclass.

For example, if in a class,

class Animal {

float weight;

void eat() {

}

}

class Mammal extends Animal {

//inherits weight

int heartRate;

//inherits eat()

void breathe() {

}

}

In this example, an object of type Mammal has both the instance variable weight and the method eat(). They are inherited from Animal.

A class can extend only one other class. To use the proper terminology, Java allows single inheritance of class implementation. A subclass can be further subclassed. Normally, subclassing specializes or refines a class by adding variables and methods.

For example:

class Cat extends Mammal {

//inherits weight and inheritance

boolean longhair;

//inherits eat() and breathe()

void purr() {

}

}

The Cat class is a type of Mammal that is ultimately a type of Animal. Cat objects inherit all the characteristics of Mammal objects and in turn, Animal objects. Cat also provides additional behavior in the form of the purr() method and the long hair variable.

A subclass inherits all members of its superclass not designed as private. Other levels of visibility affect what inherited members of the class can be seen from outside of the class and its subclasses, but at a minimum, a subclass always has the same set of visible members as its parent. For this reason, a subclass always has the same set of visible members as its parent and instances of the subtype can be used anywhere instances of the supertype are allowed.

Another example,

Cat simon = new Cat ();

Animal creature = simon;

The Cat instance simon in the example can be assigned to the Animal type variable creature because Cat is a subtype of Animal. Similarly, any method accepting an Animal object would accept an instance of a cat or any Mammal type as well. This is an important aspect of polymorphism in an object-oriented language such as Java. This is used to refine a class’s behavior as well as add new capabilities to it.

For more details you can visit our websites at http://www.helpwithassignment.com/programing-assignment-help and http://www.helpwiththesis.com

Java Programming Assignment Help

All Java programs use objects, and the type of an object is defined by its class or interface. Every Java program is defined as a class and nontrivial programs usually include a number of classes and interface definitions.

A class is a collection of fields that hold values and methods that operate on those values. Classes are the most fundamental structural element of all Java programs. One cannot write a code in Java without defining a class. All Java statements appear within methods and all methods are implemented within classes.

A class defines a new reference type. An object is an instance of a class. A point class defines a type that is the set of all possible two-dimensional points. A point object is a value of that type: it represents a single two-dimensional point.

Objects are usually created by instantiating a class with the new keyword and a constructor invocation, such as

Point p = new Point (1.0, 2.0);

A class definition consists of a signature and a body. The class signature defines the name of the class and may also specify other important information. The body of a class is a set of members enclosed in curly braces. The members of a class may include fields and methods, constructors and initializers and nested types.

Members can be static or nonstatic. A static member belongs to the class itself while a nonstatic member is associated with the instances of a class. The signature of a class may declare that the class extends another class. The extended class is known as the superclass and the extension is known as the subclass. A subclass inherits the members of its superclass and may declare new members or override inherited methods with new implementations.

The signature of a class may also declare that the class implements one or more interfaces. An interface is a reference type that defines method signatures but does not include method bodies to implement the methods. A class that implements an interface is required to provide bodies for the interface’s methods. Instances of such a class are also instances of the interface type that it implements.

The members of a class may have access modifiers public, protected, or private which specify their visibility and accessibility to clients and to subclasses. This allows classes to hide members that are not part of their public API. When applied to fields, this ability to hide members enables an object-oriented design technique known as data encapsulation. Classes and interfaces are the most important of the five fundamental reference types defined by Java. Arrays, enumerated and annotation types are the other three.

For more details you can visit our websites at http://www.helpwithassignment.com/programing-assignment-help and http://www.helpwiththesis.com

Thursday, February 3, 2011

Java at HelpWithAssignment.com (Basic Date Formatting)

Basic Date Formatting

Let us see an example for Basic Date Formatting.

package com.ack.j2se.date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class BasicDateFormatting {
public static void main( String[] args ) throws Exception {
// get today's date
Date today = Calendar.getInstance().getTime();

// create a short version date formatter
DateFormat shortFormatter
= SimpleDateFormat.getDateInstance( SimpleDateFormat.SHORT );

// create a long version date formatter
DateFormat longFormatter
= SimpleDateFormat.getDateInstance( SimpleDateFormat.LONG );

// create date time formatter, medium for day, long for time
DateFormat mediumFormatter
= SimpleDateFormat.getDateTimeInstance( SimpleDateFormat.MEDIUM,
SimpleDateFormat.LONG );

// use the formatters to output the dates
System.out.println( shortFormatter.format( today ) );
System.out.println( longFormatter.format( today ) );
System.out.println( mediumFormatter.format( today ) );

// convert form date -> text, and text -> date
String dateAsText = shortFormatter.format( today );
Date textAsDate = shortFormatter.parse( dateAsText );
System.out.println( textAsDate );
}
}

Here in the above coding we can see that the program is used to fetch date. Date formats are of four types, Short, Medium, Long and Full. The above functions are used to call the date and date & time formats as well.
// get today's date
Date today = Calendar.getInstance().getTime(); initializes the date function. And the following line // create a short version date formatter
DateFormat shortFormatter
This and the following lines of code are written to include the different date and date time formats. The various date and date time formats are:
SHORT is completely numeric, such as 12.13.52 or 3:30pm
MEDIUM is longer, such as Jan 12, 1952
LONG is longer, such as January 12, 1952 or 3:30:32pm
FULL is pretty completely specified, such as Tuesday, April 12, 1952 AD or 3:30:42pm PST.

At HelpWithAssignment.com we provide the best Assignment help, Homework help and Online Tutoring in Java and other Programming languages. Our tutors are experts in Java and other Programming Languages like C, C++, C#, ASP.net, JSP.net, QBasic, Perl, Fortran, etc. The list is not exhaustive.

For more details you can visit our website at http://www.helpwithassignment.com and http://www.helpwithassignment.com/programing-assignment-help
This article is in contiuation with our previous articles on Java (Finding Factorial) and Java (Finding even and odd number)

Tuesday, February 1, 2011

Java Programming help at HelpWithAssignment.com (Finding Factorial)

Java Factorial Example
This Java Factorial Example shows how to calculate factorial of a given number using Java.

public class NumberFactorial {
public static void main(String[] args) {

int number = 5;
/*
* Factorial of any number is !n.
* For example, factorial of 4 is 4*3*2*1.
*/

int factorial = number;

for(int i =(number - 1); i > 1; i--)

{
factorial = factorial * i;

}

System.out.println("Factorial of a number is " + factorial);
}
}

Here in the code we can see that in the first few lines the definition for a factorial is defined. Now, this definition is being applied in the following lines as “int factorial = number” or factorial of an integer equals to the number – 1; the number must be greater than 1 and the integer i is decremented by 1 until 1 is arrived at. The next process is the multiplication of the numbers obtained. This is seen in factorial = factorial*i. This will give the exact value of the factorial.

At HelpWithAssignment.com we provide the best Assignment help, Homework help and Online Tutoring in Java and other Programming languages. Our tutors are experts in Java and other Programming Languages like C, C++, C#, ASP.net, JSP.net, QBasic, Perl, Fortran, etc. The list is not exhaustive.

For more details you can visit our website at http://www.helpwithassignment.com/ and http://www.helpwithassignment.com/programing-assignment-help
You can follow us on our blogs at http://helpwithassignment.blogspot.com/ and http://helpwithassignment.wordpress.com/
This is in continuation with our previous articles on Java and Java Assignment help

Monday, January 31, 2011

Java Programming help at HelpWithAssignment.com

Java is one of the most popular Programming languages in use today in Application software and Web Applications. It is a general-purpose, concurrent, class based and object oriented language that is specifically designed to have implementation dependencies as possible.

Let us look at an example on finding whether a Number is Even or an Odd number.

public class FindEvenOrOddNumber {

public static void main(String[] args) {

//create an array of 10 numbers
int[] numbers = new int[]{1,2,3,4,5,6,7,8,9,10};

for(int i=0; i < numbers.length; i++){
/*
* use modulus operator to check if the number is even or odd.
* If we divide any number by 2 and reminder is 0 then the number is
* even, otherwise it is odd.
*/
if(numbers[i]%2 == 0)
System.out.println(numbers[i] + " is even number.");
else
System.out.println(numbers[i] + " is odd number.");

}
}
}

Here in this example an array is being created and defined. Here “for(int i=0; i < numbers.length; i++){ “ is meant to be the initialization and definition. For(int i=0; I < numbers.length; i++ means that the I cannot be zero and must be greater than the divisor in this case because as we move forward in the code we can see that the definition for the array says that if the number is divided by 2 and the remainder is 0 then the number is an even number. But, mathematically 0 is neither an odd nor an even number, so clearly this rule cannot be broken.

The array “create an array of 10 numbers” is being initiated with a loop “for(int i=0; i < numbers.length; i++){ /*” to calculations to be performed which completes the whole array and the outputs of whether the numbers are even or odd are returned.

At HelpWithAssignment.com we provide the best Java Assignment and Homework help. We also offer Online Tutoring in Java. For more help on Java Programming help you can visit our website at http://www.helpwithassignment.com/programing-assignment-help .

This article is in continuation with our previous article on Java Assignment Help

Thursday, August 12, 2010

Java Assignment Help at HelpwithAssignment.com

Java is a programming language which appeared in 1995. It is very similar to its predecessors C and C++ although its not from the makers of C. Java was developed by Sun MicroSystems. It’s now very popular among most of the Programmers. The reason for the success of Java can be attributed to the fact that it is highly portable. This is one of the reasons for the success of Java. And also Java was launched with the slogan, “Write Once and Run Anywhere” (WORA). This feature also made Java a low-cost alternative.

Surprisingly Java was not for the internet. Instead the primary motivation was the need for platform independent language that could be used to create software to be embedded in various consumer electronic devices, such as toasters, microwave ovens and remote controls. And the internet at the time of Java’s release was mushrooming with many platforms with many operating systems. And that turned out to be a boon for Java and its subsequent acceptance over the internet.

In a span of few years Java went from relative obscurity to being the most important language of the internet. The impact of Java cannot be understated. It transformed the web into a highly interactive environment, setting a new standard for computer language design along the way.

At HelpWithAssignment.com we provide the best assistance in Java. We have roped in computer experts who have done their Masters and PhDs from the top Universities. They can teach online and prepare A grade Assignments in Java and other related technologies. Visit our website http://www.helpwithassignment.com/ for further details.