0% found this document useful (0 votes)
54 views

CSCI207 Lab3

This document outlines two programming problems. The first problem involves creating an Employee class with instance variables for name, last name, and monthly salary. It requires writing methods to set/get these variables, validating the salary is positive, and testing the class. The second problem involves reading student name and grade data from a file selected by the user, calculating averages, and writing results to a new file in a specific format. It suggests adding error handling for invalid file formats or empty files.

Uploaded by

Ali Rida Siblani
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

CSCI207 Lab3

This document outlines two programming problems. The first problem involves creating an Employee class with instance variables for name, last name, and monthly salary. It requires writing methods to set/get these variables, validating the salary is positive, and testing the class. The second problem involves reading student name and grade data from a file selected by the user, calculating averages, and writing results to a new file in a specific format. It suggests adding error handling for invalid file formats or empty files.

Uploaded by

Ali Rida Siblani
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

In the name of God

USAL
CSCI207 – Lab3 Fall 2022

Problem 1: (Classes)
Objectives:
In this lab, you will practice:
1. Creating a class declaration.
2. Declaring instance variables.
3. Declaring a constructor.
4. Declaring set and get methods.
5. Writing a test application to demonstrate the capabilities of another
class.
6. Create a UML for your class.

Description of the Problem


Using only programming techniques explained in chapter 9 (Classes
and objects):
• Create a class called Employee that includes three pieces of information as
instance variables—a first name (type String), a last name (type String) and a
monthly salary (type double).
• Your class should have a constructor that initializes the three instance
variables.
• Encapsulate the data fields to the class so can be invoked by methods only
• create a static method to show the numbers of the Employee created
• Provide a set and a get method for each instance variable.
• If the monthly salary is not positive, set it to 0.0.
• Create and show the UML of the Employee class.
• Write a test application named EmployeeTest that demonstrates class
Employee’s capabilities.
• Create two Employee objects and display the yearly salary for each Employee.
Then give each Employee a 10% raise and display each Employee’s yearly salary
again.
• Create a method that receives an array of Employeess and print the same
results above according to the size of the array.

Problem-Solving Tips
1. Class Employee should declare three instance variables.
2. The constructor must declare three parameters, one for each instance variable. The
value for the salary should be validated to ensure it is not negative.
3. Declare a public set and get method for each instance variable. The set methods
should not return values and should each specify a parameter of a type that matches
the corresponding instance variable (String for first name and last name, double for the
salary). The get methods should receive no parameters and should specify a return type
that matches the corresponding instance variable.
4. When you call the constructor from the test class, you must pass it three arguments
that match the parameters declared by the constructor.
5. Giving each employee a raise will require a call to the get method for the salary to
obtain the current salary and a call to the set method for the salary to specify the new
salary.
6. A salary is a dollar amount, so you should output the salary using the %.2f specifier to
provide two digits of precision.
Problem 2:
Create a program that do the following tasks:
1- Let the user select a file using the java file chooser.
2- Read from the select file all lines.
3- At each line you need to get the name and 4 integers from
string with a “-“ between each integer ex: “Ali_Ali-18-20-12-
15”
4- For each line calculate the averge of each student and write
the data to another files called “grades.txt” as follows:
“Ali_Ali: 15/20 passed “
5- Close files
6- You can do your checks for the format of the file or if exists
or if no lines found to show the error message to user

Please don’t forget to add your name in the name of the


submitted file.
GOOD LUCK

You might also like