Sie sind auf Seite 1von 4

8.

Metropolis or city
Let three variables be given containing information for a city:
boolean isCapitalCity;
int numberOfCitizens;
double taxPerCitizen;
with the following meaning:
 i sCapitalCity is true if and only if the city is a capital city.
numberOfCitizens is the number of citizens in this city.
taxPerCitizen is the average tax per month a citizen of the city pays.
We define a city to be a Metropolis ,if it is either a capital city with more than 100
000 citizens or a normal city with more than 200 000 citizens and an average
income of 720 000 000 per year.
Return a boolean expression – true if the city is a metropolis.

6. Mathematical Expression
Find the answer for the expression: f(n)=sqr((n-1))+1 for a given n. Use both
recursive and iterative approach

Exercise 5.2: Sorting


1. Merge Sort
Combine 3 sorted lists into 1 sorted list and remove the duplicate elements in the
resultant array.
2. Student Rank
Find the marks for a rank from a series of marks.
3. Roll number from Rank
Find the roll numbers for a rank from a given series of roll numbers and marks.
4. Sorting Fruits
Finding the total quantity of each kind of fruit(represented by an integer number)
sold from an ordered list containing fruits and the quantity sold.
5. Word Length
Accept a sentence ad display the number of occurrences of words of different
lengths
7. Purchase List
I have a list of items on my purchase list. I then get an updated copy of the
purchase list after some revisions have been done by my room mate. I need to
find out what got added, updated and deleted and print the result appropriately.
8. Shorter and Taller Students
In a class of n students, find the taller half of students and arrange them in the
ascending order of their height and the shorter half in the descending order of
their height.
9. Employee Hierarchy
Find the person and list of his subordinates from a list of employee id and
manager id pairs represented in a two dimensional array.
10. Employee Hierarchy - Extension
Find the person and list of his subordinates from a list of employee id and
manager id pairs. Print the hierarchy with names of the employees. Also validate
the entries for a cyclic relation.

Exercise 6: Arrays
1. Grade calculation
Write a program to store the marks in 4 subjects(English, Science, Maths,
Social, Arts) of 5 students. The program should have two functions to
To calculate the average marks for each subject
To calculate the total marks for each student.
Assume arrays of marks for each student in the predefined subject order(e.g {
<marks for English>, <marks for Science>,<marks for Maths>,<marks for
Social>,<marks for Arts>}
2. Stack Implementation – Chocolate box problem
You have a set chocolates of different makes (KitKat,Cadbury, Toblerone).
There is one box where all the chocolates need to be placed. Only one
chocolate can be placed inside the box at one instance and only one can be
retrieved at any instance. The chocolate which is placed last will be at the top
of the box while the chocolate which is place first will be at the bottom of the
box.
Write a program to insert a set of chocolates in the order in which is it
received (random) into a box (that can hold 10 chocolates) and retrieve
specific chocolates from the box.
3. Find second largest number
Write a program to find the second largest number in an array of unsorted
numbers. If there is no second largest number, return -1
4. Insert Strings
Write a program to insert Strings to an array of size 10. If the string is already
present in the array, return a message saying “<String>, already exist”. After
the 10th element, for any insert action, return a message “No more Strings
can be stored”.
5. Find occurrence of an integer
Write a program to find the count of a particular value in a array of integers.
6. Replace a string
Write a program to replace a particular string if it is there in an array of
strings.
7. Concatenate a string
Write a program to concatenate an array of string into a single string and
return the string.
8. Introduce a delimiter
Write a program to insert a delimter (e.g “$”) on every 3 rd position in an array
of strings.
9. Replace strings
Write a program to replace an array of alphabets (A – J) in upper case with
corresponding lower case alphabets.

Exercise 7: Common Problems


1. Favorite tasks
Write a program to store the names of favourite tasks (say ‘painting’, ‘reading’,
‘writing’…..) and return the string “My favourite tasks are <task1>, <task2>,
<task3>,…..and <task 4> .” (tasks listed in ascending order).
2. Array addition
Write a program to accept two arrays of alphabets and combine the arrays as per
the input flag – “merge”, “append”, “common”
If “merge” is given, create the result array with {<1st element in 1st
array>, <1st element in second array>,<2nd element in first array>,<2nd element in
second array>…….,<last element in first array>,<last element in last array>}
If “append” is given, the result array appending second array to the end of first
array
If “common” is given, the result array should only have elements common in both
arrays.
3. Batch grade
Write a program to calculate the exam pass percentage of a batch consisting
of 4 students (each having 5 marks entered in order) based on the following
rule.
Weigtage of mark1, mark2 is 25%
Weightage of mark3, mark4 is 20%
Weightage of mark5 is 10%
Maximum marks is 100 for each subject.
Batch grade is A if, batch percentage is above 80% and B if between 40%
and 80% and C if less than 40%
If a student didn’t appear for an exam(that is marks = 0), then his other marks
should not be considered for the batch grade calculation
4. Batch strength distribution
Write a program to accept an array of count of participants in batches and a
reference count so that the if any batch has additional participants, the extra
participants are distributed among those batches with a lower value(so as to
make the other close to the reference value). A return message with
defiecent(-) /surplus(+) participant count should be returned
e.g Input can be { 10, 45, 50, 15, 20} and value 30. The result array can be
{30, 30,30,30,20} and the -10 is returned.
5. Coins required
Write a program to accept an array of count of coins of denomination 10,25
and 50 respectively and an amount(in paise). The program will find the least
number of coins required to satisfy this amount and return the array.
Eg. Accept {5,10,5}, 300 will return {0,2,5}
6. Items procurement
Write a program to accept three arrays, Product Type(“Cosmetic”,
“Household”, “Medicinal” ), product quantity and product price and return the
total amount required for procurement. Cosmetic items have a tax of 12%, for
Household 4% and no tax for medicinal goods.
7. Room allocation
Write a program to accept three arrays – Room numbers, room capacity and
an array of size 3 representing number of gents,ladies and familes(which
consists of a male and a female). The program should return an array of
unallocated room numbers
The room number is a 3 digit number(e.g 123) and “1” represents the floor
number. The program should ensure to allocate the rooms in lower floors first.
Unless a family, a male and female should not be allocated to a room.
9. Shopping List
Write a program to accept item list from 3 users and prepare an array with
items and total count (store it as string instead of integer). The result array
can have the format
{<item1 name>, <item1 count>,<item2 name>,<item2 count>,<item3 name>,
<item4 count>….}

Tarzan online book store

Tarzan book store decided to go online to increase its’ revenues and provide its’ customers a way to
buy books through internet.

Tarzan maintains the list of books along with quantity. Administrator should be able to add books to
the inventory. Administrator will add books with book name, author name, category (Java, Philosophy,
Fiction, OS, self help etc.), price and quantity.

Anybody can log on to the website to browse through the books available in tarzan.com. It should have
a facility to search books by category or author name or book name and it should accept wild
characters also. Out of stock status needs to be displayed based on the quantity.

If anybody decides to buy a book online, he needs to give a customer id to do online transaction. If new
customer, he needs to register with tarzan.com by giving his personal details that are name, age, sex,
address and contact number.

Customer should have a facility to buy more than one book at one click. Customer can either choose to
buy a book or add it in his “my books” list. If he chooses to buy book/books, tarzan.com needs to get
the mode of payment (credit/debit card) and collect the card details. If customer chooses to add
book/books to “my books”, the list of selected book need to be added to his “my books” list.

Next time, when customer logs in, there should be an option to view “my books”. From there, option is
needed to buy the book. Also, customer needs to have an option to see his previously ordered books
with buy date.
Before starting coding of the above application in, please complete the following and get it reviewed.

Identify the entities/classes


Identify the attributes and methods
Identify the relationship between claases

Das könnte Ihnen auch gefallen