Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C# by babu ( 13 years ago )
OOP Exercise Set 4


Data types and expressions
Flow control
Methods

1. Create a washing machine class with methods as switchOn, acceptClothes,
   acceptDetergent, switchOff. acceptClothes accepts the noofClothes as argument &
   returns the noofClothes
2. Create a calculator class which will have methods add, multiply, divide & subtract
3. Create a Car class with methods changeGear, applybrake, increaseSpeed
4. Create a class called Student which has the following methods:
      i.Average: which would accept marks of 3 examinations & return whether the
           student has passed or failed depending on whether he has scored an average
           above 50 or not.
     ii.Inputname: which would accept the name of the student & returns the name.
5. Create a Bank class with methods deposit & withdraw. The deposit method would accept
   attributes amount & balance & returns the new balance which is the sum of amount &
   balance. Similarly, the withdraw method would accept the attributes amount & balance &
   returns the new balance ‘balance – amount’ if balance > = amount or return 0 otherwise.
6. Create an Employee class which has methods netSalary which would accept salary & tax
   as arguments & returns the netSalary which is tax deducted from the salary. Also it has a
   method grade which would accept the grade of the employee & return grade.
7. Student has following attributes: Student ID, Name, CourseID, Sex and Phone Number.
   Add a behavior to modify the phone number and display the updated details.
8. Create Employee has following attributes: Emp ID, Name, Designation, Project ID and
   Phone Number. An employee gets allocated to a new project. Add a behavior to modify
   the projectID. And display the updated employee details.
9. Create Product has following attributes: Product ID, Name, Category ID and unit price.
   Add a behavior to modify the price and display the updated Product details.
10. Create Vehicle has following attributes: Vehicle No., Model, Manufacturer and Color. Add
    a behavior to change the color and display the updated Vehicle details.
11. Create a class to define Point. Write a behavior to find the distance between the point
    from the origin (0, 0).
12. Create paycheck with check number, name, date, and amount properties. Develop a
    function to produce a paycheck given the following information: check number, name,
    date, hours worked, wage, and percent tax reported. The amount of the check is
    calculated by multiplying the hours worked by the wage less any taxes.
13. Define a class TaxCalculator with annualIncome, InvestedAmount and PanNumber as
    properties. Define a behavior to calculate tax for the PanNumber.
14. Define a class Associate with empId, name, role, businessUnit, HROwner. Add
    behaviors to change businessUnit, change the HROwner, to change the role.
 
Constructors: Use of this
1. Create a class Tree with the field height. The default constructor should print “Planting a
   seedling”. Another constructor should take an integer as argument and should initialize
   the height. It should also print “Creating a new Tree that is h feet tall” where h is the
   height initialized in this constructor. Create a class with a default constructor that prints a
   message. Add another constructor that takes a String argument and prints it along with
   your message. Using this, call the second constructor inside the first.
2. Create Rectangle which provides information on length and breadth. Create two
   parameterized constructors. First constructor has only one parameter which initializes
   length and breadth with same value. Second constructor has 2 parameters which
   initializes length and breadth with different values. Use this to initialize values for
   attributes in second constructor
Extra Exercises
1. The electrical resistance R of a cylindrical wire with length l (in meter) and diameter d (in
                                                                    2
meter) can be computed from the area A of its diameter (meter ) and the resistivity Ρ of the
material (rho, meter times Ohm). The formula: R = Ρ( l / A )
Create an Electrical Wire class to solve this.
You must have methods to compute the electrical resistance of a wire with length l m and a
diameter of d in meter
Resistivity for copper (Ρ = 1,78*10 ) and for silicon (Ρ = 2300)
Add a method to compute the potential difference.Ohm's law states the current (i) is proportional
to the potential difference (V).As a formula: V = R * i.
What is the potential difference of the wire if 25 Ampere current pass through it?
-8
2. Implement a Java-method with three local int variables a, b, and c that sorts these three values
in ascending order by comparing and exchanging their values. At the end of the program a <= b
<= c must hold.
3. The maximum points you can get in the written exam to my lecture is 120. At 60 points you
have passed the exam (grade 4.0). For every additional 5 points the next better grade. Because
of jurisdictional problems, the grade 4.3 does not exist (it is 4.7 instead). The following table
shows the mapping between points and their grades:
grade points
5.0 0 - 49.5
4.7 50 - 59.5
4.0 60 - 64.5
3.7 65 - 69.5
3.3 70 - 74.5
3.0 75 - 79.5
 
2.7 80 - 84.5
2.3 85 - 89.5
2.0 90 - 94.5
1.7 95 - 99.5
1.3 100 - 104.5
1.0 105 - 120
Implement a Java-function that returns the grade for the points reached in the exam and prints
out the grade for all points from 0 to 120 (in steps of 0.5).
4a. Write a Java-function to print first n squares.
4b. It should print all the squares except that of prime numbers.
5. Implement a Java-method that prints out the day of the week for a given day (1...31), month
(1...12) and year.
The day of the week of dates between March 1900 and February 2100 can be calculated as
follows: First, you have to calculate the total number of days from 1900/1/1 to the given date (see
below, for details). Secondly, you divide this number by 7 with integer remainder: this now is the
day of the week, with 0 as Sunday, 1 as Monday, etc.
To calculate the total number of days you have to implement the following steps:
     Subtract 1900 from the given year and multiply the result by 365
     Add the missing leaps years by adding (year - 1900) / 4.
     If the year itself is a leap year and the month is January or February, you have to subtract
         1 from the previous result.
     Now add the all days of the year up to the given one to the result (in case of february
         always 28, because the additional day for a leap year already have been added).
Here some dates with the day of the week for testing your Java program:
     Easter Sunday: 1916/3/23, 2007/4/8, 2010/4/4
     Ash Wednesday: 2006/3/1, 2007/2/21, 2010/2/17

 

Revise this Paste

Parent: 25489
Children: 61950 85890 85896
Your Name: Code Language: