6 WEEKS TRAINING

We provide 6 weeks industrial training in Java and Android to B.Tech, B.E. engineering graduates.

6 MONTHS TRAINING

We provide 6 Months live project based industrial training in Java and Android to B.Tech, B.E., MCA, BCA students.

CORPORATE TRAINING

We provide customized and cost effective corporate training in Java, Spring, Hibernate, Web Services, Android, and Angular JS.

Assignment 6: Use of Class and Objects in Java

  • 10 questions Complexity: Medium

class Fraction
{
private int n, d; // data members to store the numerator and denominator
public Fraction(int x, int y) //constructor to initialize Fraction objects
{
//initialize n & d using x & y.
//if the value of y is 0, d is set to 1.
}
public void display() //method to display the value of a fraction
{
//display the value of a fraction in n/d format.
}
public boolean isProper() //method to check whether a fraction is proper or not
{
//A fraction is proper if its n < d.
}
public boolean isEquivalent(Fraction f) //method to check whether two fractions are equivalent or not
{
//Two fractions are equivalent if they represent same value e.g 1/2 and 2/4 are equivalent fractions.
}
}

Let the Fraction object be initialized by values (2, 3), (5, 2) and (12, 18) respectively.

java FractionTest ↵

First fraction is: 2/3
Second fraction is: 5/2
Third fraction is: 12/18
5/2 is an improper fraction.
2/3 and 12/18 are equivalent fractions.

class Complex
{
private int r, i; // data members to store the real and imaginary parts of a complex number
public Complex(int x, int y) //constructor to initialize Complex objects
{
//initialize r & i using x & y.
}
public void display() //method to display the value of a Complex object
{
//display the value of a Complex object in a + bi format.
}
public Complex add(Complex c) //method to add two complex objects
{
//A new Complex object should be created and returned to represent
// the sum of the invoking and parameter complex objects.
}
}

Let the Complex objects be initialized by values (5, 6) and (2, 3).

java ComplexTest ↵

First Complex No. is: 5 + 6i
Second Complex No. is: 2 + 3i
Their sum: 7 + 9i

class Date
{
private int d, m, y; // data members to store the day, month and year of a date.
public Date(int d, int m, int y) //constructor to initialize Date objects
{
//initialize d, m, y of the current object using the d, m, y parameters.
}
public String toString()// method to get the value of a Date object printed
{
//return the value of a Date object as a String in d/m/y format.
}
public boolean isSmaller(Date d)// method to check whether a date is smaller than the other
{
//If the value of invoking Date object is smaller than the given object,
true is returned otherwise false is returned.
}
public int[] diff(Date d) //method to find out the difference of days, months and years in two dates.
{
//The difference of days, months and years in the invoking and parameter Date objects
//is obtained and returned in an int array. The first element of the array should represent
//difference of days; second one, the difference of months and the third one, the difference of years.
}
}

class Person
{
private String name; // data member to store the name of a person.
private Date dob; // data member to store the date of birth of a person.
public Person(String n, int d, int m, int y) //constructor to initialize Person objects
{
//initialize the data members of the current Person object using the parameters.
}
public void display()// method to display the details of a person.
{
//Person details should be displayed in the following format:
//Name: Person Name
//Date Of Birth: dd/mm/yyyy
//Age: ... Years, ... Months, ... Days
}
public void olderOne(Person p) //method to identify the older of the two persons.
{
//Older one of the invoking and given person object is identified and its details are
//displayed in the following format:
//.... is older than .... by ... years, ... months and ... days.
}
}

Let the Person Object be initialized by values ("Ram", 5, 6, 1980) and ("Shayam", 2, 3, 1987)

java PersonTest ↵

First Person Details:
Name: Ram
Date of Birth: 5/6/1980
Age: ... Years, ... Months, ... Days //actual values as per current date should be displayed.

Second Person Details:
Name: Shayam
Date of Birth: 2/3/1987
Age: ... Years, ... Months, ... Days //actual values as per current date should be displayed.
Ram is older than Shayam by 6 Years, 8 Months, 25 Days

class Account
{
private String name; // data member to store the name of an account.
private double balance; // data member to store the balance of an account.
public Account(String n, double b) //constructor to initialize Account objects
{
//initialize the data members of the current Account object using the parameters.
}
public void display() //method to display the details of an Account object
{
//Account details should be displayed in the following format:
//Name: Account Name
//Balance: Account Balance
}
public double getBalance() //method to return the value of balance of an Account object
{
//Value of the balance of the invoking Account object is returned.
}
public void deposit(double amount) //method to deposit amount to an account
{
//If the amount is not negative, It is added to the balance.
}
public void withdraw(double amount) //method to withdraw amount from an account
{
//If the amount is ≤ balance, It is subtracted from the balance.
}
}

class PaymentGateway
{
//method to transfer the given amount from the src to target account.
public static boolean transfer(Account src, Account target, double amount)
{
//If the src account balance ≥ the given amount then the amount is
//transferred from the src to the target account and true is returned
//otherwise false is returned.
}
}

Let the Account objects be initialized by values ("Ram", 10000), ("Shayam", 5000), ("Hari", 1000)

java Bank ↵

First Account Details:
Name: Ram
Balance: 10000

Second Account Details:
Name: Shayam
Balance: 5000

Third Account Details:
Name: Hari
Balance: 1000

Transferring 2000 from Ram to Shayam account...
Successfully transferred, current balance of Ram & Shayam is 8000 and 7000 respectively.

Transferring 1200 from Hari to Ram account...
Transfer failed, current balance of Ram & Hari is 8000 and 1000 respectively.

For queries:  8130-311-892,  9212-468-649

ONE YEAR VALIDITY

Admission is valid for one year i.e students can revise the course any number of times if popular fee plan is opted.

INDUSTRIAL TRAINING CERTIFICATION

Industrial training and course certificates are provided after the successful completion of each course.

PLACEMENT ASSISTANCE

We provide 100% placement assistance to all the students on the basis of monthly assessment tests.