CSCI 1301 - Lab 15

Clément Aubert

March 1, 2018

Part I - Practicing if and switch

Initialize a day string variable, a myVar int variable and a initial char variable. During this part, change and display on the screen the values of those variables to test that your statements behave as they are supposed to.

From switch to if-else

  1. Write a switch statement that sets a flag to true if the value of day if "Mon.", "Tue.", "Wed.", "Thu." or "Fri.", and to false otherwise.
  2. Rewrite the previous statement as an if-else statement.

From if-else to switch

  1. Write a if-else statement that doubles the value of myVar if myVar is 3, 5 or 7.
  2. Can you rewrite the previous statement as a switch statement?

Deciding

  1. Write a statement that doubles the value of myVar and sets initial to ‘M’ if day is equal to "Sat". What is the appropriate kind of statement to do this?
  2. Write a statement that displays “Hello” on the screen if the value of initial is 'E' or 'e', “Bonjour” if the value of initial is 'F' or 'f', “Guten Tag” if the value of inital is D or d. What is the appropriate kind of statement to do this?

Complex Conditions

  1. Write a statement that doubles the value of myVar if day is "Sun.", triples the value of myVar if day is not "Sun." and initial is 'a', sets myVar to 0 otherwise.
  2. Write a statement that sets myVar to t if initial is an upper-case letter, and to f otherwise. You can either use the IsUpper method (https://msdn.microsoft.com/en-us/library/9s91f3by(v=vs.110).aspx), or look at the part II of the previous lab to understand how to test if a character is an upper-case letter.

Part II - Wireless Service Provider Problem

Description

An wireless service provider has three different subscription packages for its customers.

We want to design and implement a class for this wireless service provider.

Design

Design a class named WSP that calculates a customer’s monthly bill. It should contains:

  1. Attributes for both the letter of the package the customer has purchased (A, B, or C) and the amount of data (in GB) that the customer has used.
  2. Accessors and mutators for all attributes.
  3. A no-arg constructor that defaults to package A and no GB used.
  4. A constructor that sets all fields using its parameters.
  5. A method that calculates a customer’s total charges for the package they have chosen.
  6. A method that calculates and displays the amount of money Package A customers would have saved if they had purchased Package B or Package C, and the amount of money Package B customers would save if they purchased Package C.

Write the UML diagram for this class.

Implementation

Work on the WSP class and on a test program in parallel: implement the steps a., b. and c., and then write a small test program. Make sure you can compile your program, and that it behaves as expected before continuing. Write the second constructor, and test it by creating an object using it. Continue with e., test the method, and finally write f. To test this last method, you should create numerous objects, and call the method with them.

Try to use a switch statement for this last method.