Vous êtes sur la page 1sur 3

Java Assignment 1.

Write a program to create a class called calculator that uses


arithmetic operators and also bitwise operators (&, |and ^). Initialize the variables to any acceptable value of your choice, and demonstrate the usage of these operators. 2. Write a java program using either a while loop or a do-while loop to print the entire set of three-digit Armstrong numbers. An Armstrong number is one that satisfied the following condition: a3+b3+c3=abc. As example, 13+53+33=153. 3. A long sentence terminated by a new line character is considered as input (need not take user input) to a java program. This sentence may contain alphabets, digits, and special characters. Write a java program that counts the number of alphabets, digits, blank spaces, and other characters in this input sentence, and then outputs them as shown below: Example: Input: Output them (: , *, ; etc) in a suitable manner! Output: Alphabets Digits Blanks Tabs Others : : : : : 30 0 7 0 9

4. Write a program to find the minimum number of currency notes required make up a specific amount that is considered (need not take user input) as input (assume that currency notes of denominations 1000, 500, 100, 50, 20, 10, 5, 2 and 1 rupees are available). 5. Write a java program that has two classes, Employee and Wage Calculator. Employee has the following details about the employee: name, employee code, hours worked and wage per hour. WageCalculator creates instances of the Employee class, gets the details of the employee to calculate the wages and prints it to the standard output. Use the constructor of the Employee

class to assign values to the different variables. 6. Write a java program that has the classes Area and User. Area has overloaded static methods by the name area() that can be used to calculate the area of a circle, triangle and cylinder. User uses the methods of Area to calculate the area of different geometric figures and prints it to the standard output. 7. Create two class called Instructor and Course. Instructor has the name of instructor, ID of instructor and discipline. Course has course number and course name. Write methods that will enable you to store and retrieve data. Create a structure called CourseInstructor. It should have two data members, viz., course number and ID of instructor. Write methods to store and retrieve data. Write a main method that creates objects of the three classes and sets data in all these objects. The program should be able to find and print the name of an instructor who teaches a course, given the course number. 8. Write a java program that has a class Bike with wheels, seat, speedometer, indicator, frontBrake, backBreak and presentGear as attributes. It also has a method called increaseGea()r that changes the gears from 4 through 1. The Bike class also has a method called indicateTurn() that changes the value of the variable accordingly. A RacingBike sub-class is created from the class Bike. It overrides the increaseGear method to change the gears from 1 through 5, and the decreaseGear method is overriden to change the gears from 5 through 1. A Driver (another class) dreives the Bike and the racingBike one after the other. 9. Write a java program that has a class called Login. This class has user name and their corresponding password,storing in String Arrays (declared private). It also has a boolean variable, accessPermitted,whose default value is FALSE. There is a method called passwordChecker() that checks for the password,entered against the user name. if the password entered is right, then it prints Authentication Verified. User allowed access to the standard output and changes the value of accessPermitted to TRUE. If the password enterd is wrong ,then an exception called TressPassing is thrown. TressPassing is the user defined exception. The class User is instanciate the Login class, and

invokes the passwordChecker() method to validate the password to gain the access to SecretData. The data in SecretData class can be accessed only when accessPermitted of Login is TRUE, otherwise a HackerAllert exception is thrown. HackerAllert is also a user defined exception. Both TressPassing and HackerAlert exceptions have information that can be used to give information to User, when they are caught. 10. Write a java program that reverses a given string. If the original string and the reverse string are the same, then it throws a Palindrome exception, which is a user defined exception.

Vous aimerez peut-être aussi