Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1: a) (5 marks) Describe the top-down testing and bottom-up testing approaches to the testing of a program, clearly explaining the differences between the

Question 1:

a) (5 marks) Describe the top-down testing and bottom-up testing approaches to the testing of a program, clearly explaining the differences between the two.

b) (5 marks) Consider a Java program in which the variables $1 and s2 can refer to strings of characters. Write Java statements to do the following:

(i) output to the screen the string which is larger in length;

(ii) output to the screen the last two characters in string $1;

(iii) output to the screen the two strings $1 and s2 in alphabetical order; (iv) output to the screen whether one string is a substring of the other string;

(v) output to the screen whether the string s2 contains a digit.

c) (5 marks) Java method which takes a string parameter and checks whether or not the string contains two or more occurrences of any character. The method will return true if there is at least one character which appears more than once in the string, otherwise it returns false.

Write a Java statement to show how you would call this method.

d) (5 marks) Java method to read in three integer numbers from the user in random order, arrange the numbers in ascending order and then write them out on the screen. For example, if the input is

45 17 29

then the output should be

17 29 45

Do not use arrays.

Question 2:

a) (6 marks) Suppose that a Country class has the following already available:

1. a name String and population (a long integer),

2. a default constructor,

3. a constructor which is given the country's name as a String and its population as a long (integer),

4. a method set(...) for setting the name and population of a country,

accessor methods for accessing the name and population of a country,

6. an isMorePopulousThan(...) method which compares the argument Country to the calling Country and returns true if the calling Country has a bigger population than the argument Country, otherwise it returns false.

Give Java code for a client program that does the following. It will create a Country object using the default constructor. It will then get the name and population of a country from the user and set the Country object to the input values. The program will then get the name and population of another country from the user, and create a second Country object using the non-default constructor. Finally it should display whether or not the first country has a bigger population than the second one (by using the isMorePopulousThan() method to compare them).

b) (6 marks) Give Java code for the Country class described above in Question 3 a).

c) (4 marks) Give Java code for readCountryDetails() and writeCountryDetails() methods for the Country class. The readCountryDetails() method is to allow input of all the information about a country from the keyboard. The writeCountryDetails() method is to allow output of the information to the screen.

d) (4 marks) Give Java code (which is meant to be part of a client program) which uses your Country class to do the following. Get an integer n from the user. Loop around getting details of n countries from the user. At the end the program should output the country (of those n) with the highest population.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions