Free University of Bolzano/Bozen
Faculty of Computer Science - Bachelor in Applied Computer Science
Bachelor in Production Engineering
Introduction to Programming - A.A. 2006/2007

Exercise 2

Method Invocation

Note: You can consult the Java API documentation for specific information about classes and methods that are predefined in Java.


Exercise 2A (this is a repetition of Exercise 1 of last week's assignment)

Download the file Exercise2A.java and save it. Run the BlueJ development environment, open Exercise2A.java and compile it. The program contains errors. Fix all the errors in order to obtain a correct program. When you're done, run the program.

Solution


Exercise 2B

Write a Java program that reads a string from the keyboard, translates it to all uppercase letters and outputs it on the display. If, for instance, the string "HeLLo" is given, the output will be "HELLO". Use the dialog window of the JOptionPane class to read the input. To print the output to the output terminal use println.

Solution


Exercise 2C

Write a Java program that reads a string from the keyboard, and outputs the string twice in a row, first all uppercase and next all lowercase. If, for instance, the string "Ciao" is given, the output will be "CIAOciao". Display a window with the JOptionPane class to read the input. Just print the output to the output terminal using println.

Solution


Exercise 2D

Rewrite the Java program given as the solution to exercise 2C using as few variables as possibile. Use just one variable to hold the input string.

Solution


Exercise 2E

Write a Java program that reads a string from the keyboard, and outputs the string such that the first half is all lowercase and the second half is all uppercase. If, for instance, the string "HelloWorld" is given, the output will be "HELLOworld". Display a window with the JOptionPane class to read the input. Just print the output to the output terminal using println.

Solution


Exercise 2F

Write a Java program that prompts for the first name and then for the last name of a person. The program should then output the complete name spelled backwards, using a space as separator between first name and last name. Use the class StringBuffer to process the complete name. Again, use JOptionPane to read both inputs, then use println to print the output to the output terminal.

Solution