Problem 1.1

Write a program that prompts the user to input the length and breadth of a rectangle and then print the rectangle’s area?

Problem 1.2 (Programming Exercises (Chapter 3, Exercise 3 pp-165))

The manager of a football stadium wants you to write a program that calculates the total ticket sales after each game. There are four types of tickets-box, sideline, premium, and general admission. After each game, the data is stored in a file in the following form:

ticketPrice      numberOfTicketSold

…….

Sample data are shown below:

250 5750

100 28000

50 35750

25 18750

The first line indicates that the box ticket price is \$250 and 5750 tickets were sold at that price. Please type above information into a text file and write a program to read those data and output the number of tickets sold and the total sale amount on the screen.

Problem 1.3

Write a program that converts date formats from American Format: “September 4, 2013” to International Format; – such as “2013-September-4”.

Hint: you may use several string methods, including:

• str.indexOf(c): given a string str and a character c, this finds the position (starting at 0) of the first instance of c in str.
• str.substring(p): given a string str and a position p, this method returns a new string starting at position p and going until the end of the string.

You can solve this problem in the follow way. You should first look for everything that comes before the first space. This will be the month. Save this in a String variable, and then use substring to find everything that comes after this point -the remainder of the string. Working from this remainder, you can search for the comma (using indexOf) to find the piece that has the date. Once you have this, everything after the comma is the year. You can then using string concatenation (with the + operator) to tie the year, month and date together like “2008-January-30”.

Problem 1.4

Write a program that prompts the user to input an integer between 0 and 35. If the number is less than or equal to 9, the program should output the number; otherwise, it should output A for 10, B for 11, C for 12,…, Z for 35. (Hint: use the case operator (char)(number+55)).