Faculty of Computer Science and Information Technology SSK 3101 (Computer Programming II) Semester I 2020/2021 Lab 2 (Individual) Learning Objective
Faculty of Computer Science and Information Technology SSK 3101 (Computer Programming II) Semester I 2020/2021 Lab 2 (Individual) Learning Objective
Faculty of Computer Science and Information Technology SSK 3101 (Computer Programming II) Semester I 2020/2021 Lab 2 (Individual) Learning Objective
Lab 2 (Individual)
Learning Objective:
Construct a Simple Object-Oriented Program (P4)
Instructions:
1. Find solution to each problem and get help from your lecturer whenever you
encounter any problem.
2. Demonstrate your source program and the output to your lecturer.
3. Submit UML diagram for each problem after the lab session.
4. Submitted by 2/11/2020 at 5pm
Questions:
Draw the UML diagram for the class then implement the class. Write a test program
that creates a Stock object with the stock symbol ORCL, the name Oracle
Corporation, and the previous closing price of 34.5. Set a new current price to 34.35
and display the price-change percentage.
Draw the UML diagram for the class then implement the class. Write appropriate
mutator/setter methods that store values in these fields and accessor /getter
methods that get the values in these fields. Once you have written the class, write
a test program that creates an array of three Employee objects to hold the
following data:
The program should store this data in three objects and then display the data for
each employee on the screen as listed in Figure 1.
2. Smart Beauty Shop needs a Fat Gram Calculator that calculates the percentage of
calories from fat, given a food item, the total of calories and fat grams in a food item.
The number of calories from fat cannot be greater than the total of calories in the
food item. If the program determines that the number of calories from fat is greater
than the number of calories in the food item, it should display an error message
indicating that the input is invalid.
Fat contains 9 calories per gram. The calculator should display the percentage of
the calories that come from fat. The percentage of calories from fat can be
calculated as follows:
Calories from fat = grams of fat * 9
Percentage of calories from fat = (calories from fat / total calories) * 100
If the calories from fat are less than 30% of the total calories of the food, it should
also display a message indicating the food is low fat.
The number of calories from fat cannot be greater than the total of calories in the
food item. If the program determines that the number of calories from fat is greater
than the number of calories in the food item, it should display an error message
indicating that the input is invalid.
Draw the UML diagram for the class then implement the class and write an
application that creates a food object. Your class should have the following:
a. Give an appropriate name for your class
b. Define appropriate data member and their data type
c. Constructor with and without arguments
d. Setter method and getter method
e. Other appropriate methods.
f. Test your application with food items below: