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 8: Use of Has-A relation in Java

  • 10 questions Complexity: Medium

class Item
{
private String name, brand;
private int price;
public Item(String n, String b, int p)
{
//initialize the data members of the current object using the parameters.
}
public String toString()
{
//Details of an Item are returned in the following format String.
//Name: Item Name
//Brand: Brand Name
//Price: Item Price
}
}

class Cart
{
private Item items[]; //array to store items in the cart
private int size; // variable to store the no. of items in the cart.
public Cart()
{
//An array of 10 elements is created
//and the size is initialized to 0.
}
public void add(Item item)
{
//The item is added to the items array and
//the size is incremented.
}
}

java Customer ↵

Shopping Menu:
1. Add Item
2. View Cart
3. Exit

Enter Your choice: 1 ↵

Enter Name: I1 ↵
Enter Brand: B1 ↵
Enter Price: P1 ↵
Item is successfully added to the cart.

Shopping Menu:
1. Add Item
2. View Cart
3. Exit

Enter Your choice: 2 ↵

Your Cart contains following Items:

Name  Brand  Price
I1B1P1

.........................................

The program is terminated, only when the exit option is selected by the user.

class LinkList
{
private Node first,last; // data members to store the reference of first and last nodes of the list
public void add(Object value)
{
//For the given value a Node object is created and
//is added to the list.
}
public void iterate()
{
//Values of all the nodes of the list are displayed on the console.
}
public class Node  //  Nested class to represent the nodes of the list, starts
{
private Object value; // data member to store the value of a node.
private Node next; // data member to store the reference of the next node.
public Node(Object value)
{
//The given value is assigned to the node data member
//and the next reference variable is set to null.
}
} //  Nested class ends

} //  List class ends

Define a class named ListTest which contains main() method. In the main() method, a LinkList object is created, some elements are added to it and their values are displayed.

class Country
{
private String name, capital; // data members to store the name and capital of a country.
private HeadOfState hos; // data member to store the details of the head of state of a country.
public Country(String n, String c, HeadofState hos)
{
//Initializer statements.
}
public void display()
{
//Display the details of a country in the following format:
//Name: Country Name
//Capital: Country Capital
//Head Of State: Title, Name
}
public static class HeadOfState  //  Static nested class to represent the Head of state of a country
{
private String title, name; // data members to store the title and name of a head of state.
public HeadOfState(String title, String name)
{
//Initializer statements.
}
public String toString()
{
//Details of the HeadOfState are returned in the following format:
//Title Name
}

} //  Country class ends

Let the HeadOfState objects be named h1 & h2 and be initialized by
("President", "R.N.Kovind") & ("Queen", "Elizabeth II")
and the Country objects be initialized by ("India", "New Delhi", h1) & ("UK", "London", h2).

java CountryTest ↵

Details of the first country:
Name: India
Capital: New Delhi
Head Of State: President, R.N.Kovind

Details of the second country:
Name: UK
Capital: London
Head Of State: Queen, Elizabeth II

class Topic
{
private String name;
private int weightage;
public Topic(String name, int weightage)
{
//initializer statements
}
public void display()
{
//Details of a Topic are displayed in the following format
//Name: ..........
//Weightage: ..........
}
}

class Course
{
private String name;
private int fee;
private Topic[] topics;
public Course(String name, int fee, Topic[] topics)
{
//initializer statements
}
public void display()
{
//Details of a Course are displayed in the following format.
//Course Name: Name
//Course Fee: Fee
//Topics Details:
//Topic Name    Weightage
// ...................     ...........
}
}

Let 3 Topic objects be initialized by ("IOC", 30), ("AOP", 20) and ("Web MVC", 50) values
and are stored in an array named topics[]. Let the Course object be initilized as ("Spring",5000, topics).


java CourseTest ↵

Course Name: Spring
Course Fee: 5000
Topics details:
Topic     Weightage
IOC             20
AOP            30
Web MVC   50

class Customer
{
private String name;
private Address address;
public Customer(String name, Address address)
{
//initializer statements
}
public void display()
{
//Details of a Customer are displayed in the following format
//Customer Name: ..............
//Billing Address:
//Street: .........
//City: ............
//State: .........
//Pin: ............
}
}

class Address
{
private String street, city, state, pin;
public Address(String street, String city, String state, String pin)
{
//initializer statements
}
public void display()
{
//Details of an Address are displayed in the following format
//Street: .........
//City: ............
//State: .........
//Pin: ............
}
}

Define a class named CustomerTest which contains main() method. In the main() method, two Address and two Customer objects are created and their details are displayed.

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.