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

Lab06 - Class and Object

This document outlines conventions for naming projects, packages, classes, and files for a series of programming labs involving object-oriented concepts like classes, objects, and arrays in Java. It also provides examples of classes to create for the labs, including classes for fractions, complex numbers, points, polynomials, and candidates with methods for arithmetic operations, input/output, sorting, and calculating averages.

Uploaded by

Hồ Nam
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Lab06 - Class and Object

This document outlines conventions for naming projects, packages, classes, and files for a series of programming labs involving object-oriented concepts like classes, objects, and arrays in Java. It also provides examples of classes to create for the labs, including classes for fractions, complex numbers, points, polynomials, and candidates with methods for arithmetic operations, input/output, sorting, and calculating averages.

Uploaded by

Hồ Nam
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

LAB 6: CLASS AND OBJECT

Mã Môn học/Course No.: CMU-CS 303


Tên Môn học/Course Name: Fundamentals Of Computing 1
Năm học/Academic Year: 2019-2020
Học kỳ/Semester: II
Khoa hay Viện/Faculty International School
Name:

Project naming convention


 Create a project named: Lab06_ClassAndObject_ID
 With ID stands for student’s identify
 Ex: If your student’s ID is 9600278, so your project name will be:
Lab06_ClassAndObject_9600278
 Pay attention to “_” (underscore)
Package naming convention: Each project has one or many packages.
 Each package has a specific name
 Each Lab has one package name. Remember to name the packages as follow:
labNo_ID
 With No is a number of each lab, ID stands for student’s identify
 Ex: lab01_9600278, lab02_9600278
 Remember to use lowercase l
Class naming convention (Files): Each package has one or many classes
 Each class has a specific name
 Remember to name the classes (classname) as follow:
LabNo_ID and TestLabNo_ID
 With No is a number of each lab, ID stands for student’s identify
 Ex: Lab01_9600278, TestLab01_9600278, Lab02_9600278,
TestLab02_9600278
 Remember to capitalize each word L, T and L
1. Create a class called Fraction to perform arithmetic operations with fractional
numbers.
Write a program to test this class:
Use integer values to represent the attributes of the class – the numerator and the
denominator.
Create public methods to perform the following:
a. Input two fractions. The result is normalized.
b. Add two fractions. The result is normalized.
c. Subtract two fractions. The result is normalized.
d. Multiply two fractions. The result is normalized.
e. Divide two fractions. The result is normalized.
f. Display a fraction as follows: (A/B). A is the numerator, B is the denominator
g. Display a fraction on the screen as a decimal number.
2. Create a class called Complex to perform arithmetic operations with complex
numbers.
Write a program to test this class
Complex’s form: <the real> + <the imaginary>*i
Represent both the real and the imaginary parts using values of type float.
Create public methods to perform the following:
a. Input two complexes
b. Add two complexes
c. Subtract two complexes
d. Multiply two complexes
e. Divide two complexes
f. Display a complex value as follows: (A+iB), where A is the real part and B is the
imaginary.
Example: Given two complexes: X = a +ib and Y = c +id
Z = X + Y = (a +ib) + (c +id) = (a +c) + i(b +d)
Z = X - Y = (a +ib) - (c +id) = (a -c) + i(b - d)
Z = X * Y = (a +ib) * (c +id) = ac + iad +ibc +i2 bd = (ac + bd) + i(ad + bc)
Z = X / Y = (a +ib) / (c +id) = [(a + ib) * (c - id)] / [(c + id) * (c - id)]
= [(ac - bd) + i(bc - ad)] / (c2 - d2 )
3. Using the Fraction class of exercise 1. create the class ArrayOfFractions which
provides methods to:
a. Input 10 fractions.
b. Find the two fractions which have the greatest sum.
c. Sort the fractions in ascending order.
4. Creating a class called Point that has two fields: the abscissa and the ordinate. The
Point class should include methods that:
a. Constructor to initialize the fields with zero.
b. Input a point.
c. Output a point with form (A;B). A is the abscissa and B is the ordinate.
d. Compute the distance between two points
e. Compute the area of a triangle (defined by 3 points).
5. Use the Point class of exercise 4 to create the class ArrayOfPoints which provides
methods to:
a. Input 10 points
b. Find the largest distance between two points in 10 points.
c. Find a triangle that has largest circumference in 10 points.
6. Create a class called Polynomial that provide methods or fields that:
a. Represent:
- The order of the polynomial
- The coefficients (stored in an array)
b. Input one polynomial
c. Output the polynomial as follows: anxn + an-1 xn-1 + … + a2x2 + a1x + a0 . n is the
order of polynomial, an, an-1,…, a1, a0 are coefficients of polynomial.
d. Add two polynomials.
e. Subtract two polynomials.
f. Compute the value of polynomial when x is given.
7. Create a Candidate class that includes fields:
a. codeID,
b. name,
c. day of birth,
d. test mark 1,
e. test mark 2
f. test mark.
Write methods that compute:
Input the codeID, the name, the year of birth, the test mark 1, the test mark 2 and the
test mark for a student.
Compute the average mark as follow:
(((the test mark 1 + the test mark 2)/2) + (the test mark *2))/3
Ranks students as follows:
Average mark Rank
8-10 Good
7 - <8 Fairly good
5 - <7 Average
<5 Fail
8. Use the Candidate class of exercise 4 to create TestCandidate to execute functions
as follow:
a. Input 10 candidates
b. How many the students pass?.
c. Output the students pass on the screen.

You might also like