0% found this document useful (0 votes)
10 views3 pages

EXERCISESGRADE_12

The document outlines a series of programming exercises focused on basic algorithms and Java implementations. It includes tasks such as creating a simple calculator, performing linear searches and bubble sorts, calculating profits with input validation, and handling user input with specific constraints. Additionally, it covers algorithms for totaling numbers, finding maximum and minimum values in an array, and implementing error handling in user inputs.

Uploaded by

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

EXERCISESGRADE_12

The document outlines a series of programming exercises focused on basic algorithms and Java implementations. It includes tasks such as creating a simple calculator, performing linear searches and bubble sorts, calculating profits with input validation, and handling user input with specific constraints. Additionally, it covers algorithms for totaling numbers, finding maximum and minimum values in an array, and implementing error handling in user inputs.

Uploaded by

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

EXERCISES

1. Write a pseudocode for a simple calculator that continuously


prompts the user to choose a mathematical operation (addition,
subtraction, multiplication, or division), inputs two values, performs
the chosen operation, and outputs the result.

2. A linear search and a bubble sort are standard methods of solution.


Twenty random numbers are already stored in the array Values
[1:20].

a. Write a Java program to input a number, MyNumber, and use a


linear search to test if that number is stored in the array. If the
number is found in the array, the position in the array is output. If
the number is not found in the array, “Not found” is output.

b. Write a Java program to sort the array Values [1:20]


into ascending order using a bubble sort.

3. An algorithm has been written in pseudocode to calculate the profit


when an item is sold. Values for cost price and selling price are input,
the profit is calculated (selling price – cost price) and output. The
input of zero for either value stops the algorithm.

a. Implement the program above in Java and Test it with some numbers
to see its correctness.
b. This algorithm needs to be improved with a range check. Write
pseudocode to reject the input of values less than zero for variables
Cost and sell.

4. This pseudocode algorithm is intended to allow, at random, between


1 and 20 values to be entered and totalled. The total and average of
the entered values are output at the end of the algorithm.

a. Implement it in Java.
b. Alter the program on a to make sure that all the numbers entered
are between 1 and 500 inclusive. If any numbers fall outside
these limits, a replacement value is requested and entered.

5. Write the Java program to perform this task: accept the input of
a whole number from 1 to 4 inclusive and use a CASE
statement to: a. output the number (1 to 4 inclusive) that was
entered
b. output the word “ERROR” if a 1 to 4 inclusive number was
not entered.

6. Totalling and counting are standard methods of solution. Numbers


are input. The number 9999.9 is the last number to be input and is
ignored.
a. Write a Java program to total the numbers input and to output the
total. You do not need to validate the input.

b. Update the program on a to count and output the number of input


values that are greater than 100. You do not need to validate the
input.

7. An algorithm has been written in pseudocode to find and display the


maximum and minimum values in an array of 20 positive numbers.
The array List[ ] starts at index 1.

a. Implement this algorithm in Java. Initialize the Array List by your


random numbers.

You might also like