Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
149 views

Homework Assignment 1

This homework assignment involves creating classes with constructors, getters/setters, overloaded methods, and inheritance. It asks the student to: 1) Create classes like Student, Utility, Cuboid, Employee with fields, constructors, and methods to calculate totals, volumes, and print details. 2) Take input from command line arguments and validate data types for fields like student ID and gender. 3) Create subclasses that override methods and use polymorphism. The example predicts the output of a Car subclass overriding a run method from the Vehicle superclass. 4) Modularize code into classes and packages with proper encapsulation. The assignment reinforces core Java concepts like OOP principles,
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
149 views

Homework Assignment 1

This homework assignment involves creating classes with constructors, getters/setters, overloaded methods, and inheritance. It asks the student to: 1) Create classes like Student, Utility, Cuboid, Employee with fields, constructors, and methods to calculate totals, volumes, and print details. 2) Take input from command line arguments and validate data types for fields like student ID and gender. 3) Create subclasses that override methods and use polymorphism. The example predicts the output of a Car subclass overriding a run method from the Vehicle superclass. 4) Modularize code into classes and packages with proper encapsulation. The assignment reinforces core Java concepts like OOP principles,
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Homework Assignment 1

1. List the keywords in Java


2. List all the datatypes, size, and ranges in java.
3. Write the syntax of conditional statements and loops in Java with an example for each.
4. Create a class Student with id, marks for 3 subjects, total as static variables, static method to
compute the total, main method to print the student information. Modularize the code to class
and package levels.
5. Create a class Utility with three static methods add () the first add () will take 2 arguments, add
them, and return the result, second add () will take 3 arguments, add them, and return the result,
third add () will accept an array of integers, add elements in the array and return the result.
Invoke the all the three overloaded methods from main () within the same class (use hard coded
input).
6. Upgrade the above Utility class such that the input will be taken from the command line
arguments.

Homework Assignment 2
1. Create a Cuboid class with 3 public instance variables length, breadth and height of type double,
and a method volume (). Create 2 objects with different values obtained by command line
arguments and print the volume of each. (The program must take 6 values as input)
2. Write a Java Program to create Student class with ID, name, gender, and branch. Use getter and
setters. The ID must be 9-digit number, name must not have special characters and digits,
gender must be either M/F and branch must be either ECE/CSE/ME/ECSE/CE/BT/EEE. Use
toString () to format the details of Student. Read data from console and create 2 student objects
and print the data of each student.
3. Create a class Address with instance variables city, state, and country of String type. create a
parameterized constructor and a toString (). Create a class Employee with instance variable id
of type int, name type String, and address of type Address. Create a parameterized constructor
and a toString (). And create 2 objects for the class Employee and print the details of each
object in main () of different class.
4. Predict the output of the following and explain your output
package p1;
public class Vehicle {
void run(){
System.out.println("The vehicle runs");
}
}
public class Car extends Vehicle{
void run(int x){
System.out.println("The Car runs at speed of 10 KM per hour.");
} }

public class Demo{


public static void main(String[] args) {
Vehicle a = new Car();
a.run();
Car l = new Car();
l.run();
l.run(10);
}}

You might also like