0% found this document useful (0 votes)
3 views

Object Oriented Programming Tutorial 1

The document is a tutorial on Object-Oriented Programming using C++ and Java, detailing various programming tasks. It includes instructions for creating applications that find the maximum of a series of integers, implement classes such as Account, Date, Invoice, SavingsAccount, and Book, each with specific methods and properties. The tutorial emphasizes the use of constructors, methods, and instance variables to manage data effectively.

Uploaded by

67tr46xq7m
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Object Oriented Programming Tutorial 1

The document is a tutorial on Object-Oriented Programming using C++ and Java, detailing various programming tasks. It includes instructions for creating applications that find the maximum of a series of integers, implement classes such as Account, Date, Invoice, SavingsAccount, and Book, each with specific methods and properties. The tutorial emphasizes the use of constructors, methods, and instance variables to manage data effectively.

Uploaded by

67tr46xq7m
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

OBJECT ORIENTED PROGRAMMING TUTORIAL 1

C++ and Java Programming Languages

1. The process of finding the largest value (i.e., the maximum of a group of values) is used
frequently in computer applications. For example, a program that determines the winner of a
sales contest would input the number of units sold by each sales person. The sales person who
sells the most units wins the contest. Write an application that inputs a series of 10 integers and
determines and prints the largest integer. Your program should use at least the following three
variables:
a. counter: A counter to count to 10 (i.e., to keep track of how many numbers have been
input and to determine when all 10 numbers have been processed).
b. number: The integer most recently input by the user.
c. largest: The largest number found so far.

2. Write an application that uses looping to print the following table of values:

3. Create a class Account with the following:


- A member variable named balance of double type.
- A constructor with parameter (before balance initialization, it verifies that the balance is a
positive value.
- A method called credit() called when a deposit is made in the account.
- A method called debit() called when a withdrawal is made in the account. Ensure that the
debit amount does not exceed the Account’s balance. If it does, the balance should be left
unchanged and the method should print a message indicating - Debit amount exceeded
account balance.
- A method getBalance() that returns the account balance.

SWE2A 1/2
4. Create a class called Date that includes three pieces of information as instance variables—a
month (type int), a day (type int) and a year (type int). Your class should have a constructor that
initializes the three instance variables and assumes that the values provided are correct. Provide
a set and a get method for each instance variable. Provide a method displayDate that displays
the month, day and year separated by forward slashes (/ i.e. DD/MM/YYYY).

5. Create a class called Invoice that a hardware store might use to represent an invoice for an item
sold at the store. An Invoice should include four pieces of information as instance variables‐a
part number(type String),a part description(type String),a quantity of the item being purchased
(type int) and a price per item (type double). Your class should have a constructor that
initializes the four instance variables. Provide a set and a get method for each instance variable.
In addition, provide a method named getInvoice Amount that calculates the invoice amount
(i.e., multiplies the quantity by the price per item), then returns the amount as a double value. If
the quantity is not positive, it should be set to 0. If the price per item is not positive, it should be
set to 0.0.

6. Create class SavingsAccount. Use a static variable annualInterestRate to store the annual
interest rate for all account holders. Each object of the class contains a private instance variable
savingsBalance indicating the amount the saver currently has ondeposit. Provide method
calculateMonthlyInterest to calculate the monthly interest by multiplying the savingsBalance by
annualInterestRate divided by 12 this interest should be added to savingsBalance. Provide a
static method modifyInterestRate that sets the annualInterestRate to a new value. Write a
program to test class SavingsAccount. Instantiate two savingsAccount objects, saver1 and
saver2, with balances of 200.000 XAF and 300.000 XAF, respectively. Set annualInterestRate
to 4%, then calculate the monthly interest and print the new balances for both savers. Then set
the annualInterestRate to 5%, calculate the next month’s interest and print the new balances for
both savers.

7. Create a class called Book to represent a book. A Book should include four pieces of
information as instance variables‐a book name, an ISBN number, an author name and a
publisher. Your class should have a constructor that initializes the four instance variables. In
addition, provide a method named getBookInfo that returns the description of the book as a
String (the description should include all the information about the book). You should use this
keyword in member methods and constructor. Write a test application named BookTest to
create an array of object for 20 elements for class Book.

SWE2A 2/2

You might also like