Java Assignment
Java Assignment
1. Create an abstract class OutdoorGame inside the package ‘sports’. Inherit it for Football and Cricket. Create
another package ‘sportsstar’. Inside which create two class Footballer and Cricketer. Each class shows individual
income based on the rating ( where rating is assigned based on different bowling or bating avg or total goal done
or saved by different sports persons) of its different star sports person.
2. Write an interface Matrix which provides user interfaces for getting and setting a value from the specified
position of the matrix, getting the length and width of the matrix. Create a class TwoDArray of integers which
implements the Matrix and display the row sum and column sum before and after changing value at any
position. Take all the inputs from user.
3. Write a program to override a function check (int x) which takes a number and checks if the number is a odd or
even no and another version check if the number is prime or not. Dispatch these methods dynamically. Both sub
classes will implements an interface testInt to test if the input is a valid integer or not. Take the inputs from user.
4. Create a class Name which implements an interface utilString for extracting first name, middle name and
surname from a given name String by user and print the name in reverse order.
5. Write a program, which run two threads simultaneously each threads prints ‘[Hello World] : threadName’. Make
sure no race condition arises and main thread finishes last.
6. Write a Class StrEdit which displays the character from a string as specified a number if the number is valid
inside package ‘utilstr’. It shows IndexOutOfBoundsException if the specified number is greater than the length
of the string. It also provides method to checkPalindrome which returns true if the String is palindrome and
returns false if it is not.
7. Create four small Java classes; a Driver class that has the main method, a regular java abstract class named
Vehicle, then two classes named Car and Truck, respectively that inherit the Vehicle class. Your application
needs the following methods-
1. start(), 2. stop(), 3. turn(), 4. getSpeed(), 5. setSpeed(), 6. increaseSpeed(), 7. decreaseSpeed(), 8.
openTrunk(), 9. closeTrunk(), 10. openTailgate(), 11. closeTailgate()
In the Car class you must limit the speed to a top speed is 200 km/hr per hour where in Trunk top speed limit is
100 km/hr. The abstract class Vehicle only contains the generic methods, start, stop, getSpeed, etc. The Car
class contains the trunk methods and the Truck class contains the tailgate methods. Both Car and Trunk class
implements the interface ‘SafeDrive’ which contains interfaces for checking and generating warring for crossing
on road speed limit ( 100 km/hr for Car and 75 km/hr for Truck), if the Trunk/Tailgate is open at the time of start
etc.
8. Write classes for implementing two threads Writer and Reader, which access a shared integer x. Thread Writer
indefinitely write the value of x by increasing it and Reader indefinitely read the value of x by printing its value
on the console, i.e threads run in an infinite loop. Make sure Writer must not increase the value of x till Reader