SlideShare a Scribd company logo
Object Oriented Programming in Java [Lesson 1; Lesson 2]
1 of 3
Object Oriented Programming Assignment 2
Author: Kasun Ranga Wijeweera
Email: krw19870829@gmail.com
Date: 2018 April 7
1) Suppose you have to develop an information system for a food city. Points are added to the
customer depending on the purchases made. The customers are grouped based on the number
of points.
a) Create a class called Customer that includes attributes: id, name, points, group, and avg
with data types: “int”, “String”, “double”, “String”, and “double” respectively.
b) Include a constructor with parameters: id and name.
c) Include another constructor to assign default values to the attributes.
d) Include a method called addPoints that is used to add a given amount to the value of the
attribute points.
e) Include a method called upgradePoints that is used to increase the value of the attribute
points by a given percentage.
f) Include a method called removePoints that is used to reduce a given amount from the
value of the attribute points. If the resultant value is negative then the value of the
attribute should be set into zero.
g) Include a method called computeGroup that assigns a value to the attribute group based
on the value of the attribute points as given in the following table.
points group
points < 100 Silver
100 ≤ points < 500 Gold
500 < points ≤ 2000 Platinum
2000 < points Diamond
h) Include a method called display to display the values of all the attributes of a Customer
object.
i) Include a static method called displayAvg to display the value of the attribute avg.
Object Oriented Programming in Java [Lesson 1; Lesson 2]
2 of 3
j) The attribute avg should be assigned the average value of points of each customer.
Include a static method called calAvg to calculate the value of the attribute avg.
k) Include a static method called getBest that returns the value of the attribute id of the
customer with maximum number of points.
l) Create the driver class called Test that includes the “main” method.
m) Create an array that holds five Customer objects. Assign the objects given in the
following table to each array element using the parameterized constructor.
id 1543 6561 6954 3485 8546
name Nimal Saman Kasun Nayana Kalpa
n) Use the method addPoints to add following points respectively to each Customer object
created above.
129 785 3258 59 1652
o) Add extra 1000 points to the third customer using the method addPoints.
p) Increase the points of the second customer by 2% using the method upgradePoints.
q) Include a method called display to the class Test that displays all the attributes of each
customer. Each set of attributes should be separated by a sequence of dots. The part of
output for the first customer is given below.
……………………………
Customer: 1
ID: 1543
Name: Nimal
Points: 129.0
Group: null
Average: 0.0
r) Invoke the method display of the class Test.
s) Compute the average of points using the method calAvg.
t) Compute the group of each customer using the method computeGroup. You should use
a loop.
Object Oriented Programming in Java [Lesson 1; Lesson 2]
3 of 3
u) Again invoke the method display of the class Test.
v) Display the value of the attribute id of the customer with highest number of points using
the method getBest.
w) Invoke the method displayAvg using each Customer, c[0], c[1], c[2], c[3], and c[4] as
references.
x) Create a reference variable called cust of type Customer.
y) Assign fifth Customer object to the reference variable cust. You should use the object
you have already created.
z) Reduce 2000 points from the fifth customer using the method removePoints. You should
invoke the method using the reference variable cust.
aa) Invoke the method display of the class Customer using the array element c[4] to display
the values of attributes of the fifth customer.
bb) Update the group of the fifth customer invoking the method computeGroup.
cc) Invoke the method calAvg again to find the new average of points.
dd) Create a Customer object with default values to its attributes by using the appropriate
constructor. The object should be assigned to the reference variable cust.
ee) Copy the values of the attributes of the fourth customer to the corresponding attributes of
the object pointed by the reference variable cust.
ff) Create another reference variable called cust1 of type Customer.
gg) Assign the object pointed by the reference variable cust to cust1 as well.
hh) Delete the object pointed by the reference variable cust.
ii) Execute the statement cust1.id to verify the deletion of the object.

More Related Content

Similar to Object Oriented Programming Assignment 2

Object Oriented Programming Assignment 4
Object Oriented Programming Assignment 4Object Oriented Programming Assignment 4
Object Oriented Programming Assignment 4
Kasun Ranga Wijeweera
 
Object Oriented Programming Assignment 3
Object Oriented Programming Assignment 3Object Oriented Programming Assignment 3
Object Oriented Programming Assignment 3
Kasun Ranga Wijeweera
 
Ee java lab assignment 2
Ee java lab assignment 2Ee java lab assignment 2
Ee java lab assignment 2
Kuntal Bhowmick
 
Ee java lab assignment 2
Ee java lab assignment 2Ee java lab assignment 2
Ee java lab assignment 2
Kuntal Bhowmick
 
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx
gilbertkpeters11344
 
M.tech oops through_c++_labmanual1 (1)
M.tech oops through_c++_labmanual1 (1)M.tech oops through_c++_labmanual1 (1)
M.tech oops through_c++_labmanual1 (1)yuvanalagadapati
 
Java 102
Java 102Java 102
Java 102
Manuela Grindei
 
exercises_for_live_coding_Java_advanced-2.pdf
exercises_for_live_coding_Java_advanced-2.pdfexercises_for_live_coding_Java_advanced-2.pdf
exercises_for_live_coding_Java_advanced-2.pdf
enodani2008
 
MVC Design Pattern in JavaScript by ADMEC Multimedia Institute
MVC Design Pattern in JavaScript by ADMEC Multimedia InstituteMVC Design Pattern in JavaScript by ADMEC Multimedia Institute
MVC Design Pattern in JavaScript by ADMEC Multimedia Institute
Ravi Bhadauria
 
Object Oriented Programming Assignment 1
Object Oriented Programming Assignment 1Object Oriented Programming Assignment 1
Object Oriented Programming Assignment 1
Kasun Ranga Wijeweera
 
Lecture 2 - Classes, Fields, Parameters, Methods and Constructors
Lecture 2 - Classes, Fields, Parameters, Methods and ConstructorsLecture 2 - Classes, Fields, Parameters, Methods and Constructors
Lecture 2 - Classes, Fields, Parameters, Methods and Constructors
Syed Afaq Shah MACS CP
 
Program Specifications in c++ Develop an inventory management system f.docx
Program Specifications in c++ Develop an inventory management system f.docxProgram Specifications in c++ Develop an inventory management system f.docx
Program Specifications in c++ Develop an inventory management system f.docx
sharold2
 
Program Specifications in c++ Develop an inventory management syste.docx
Program Specifications in c++    Develop an inventory management syste.docxProgram Specifications in c++    Develop an inventory management syste.docx
Program Specifications in c++ Develop an inventory management syste.docx
sharold2
 
Lab exam question_paper
Lab exam question_paperLab exam question_paper
Lab exam question_paper
Kuntal Bhowmick
 
Chapter 8Exercise1.Design an application that accept.docx
Chapter 8Exercise1.Design an application that accept.docxChapter 8Exercise1.Design an application that accept.docx
Chapter 8Exercise1.Design an application that accept.docx
tiffanyd4
 
Lab exam question_paper
Lab exam question_paperLab exam question_paper
Lab exam question_paper
Kuntal Bhowmick
 
Exercise1[5points]Create the following classe
Exercise1[5points]Create the following classeExercise1[5points]Create the following classe
Exercise1[5points]Create the following classe
mecklenburgstrelitzh
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
C++ Homework Help
 
Assignment Java Programming 2
Assignment Java Programming 2Assignment Java Programming 2
Assignment Java Programming 2
Kaela Johnson
 

Similar to Object Oriented Programming Assignment 2 (20)

Object Oriented Programming Assignment 4
Object Oriented Programming Assignment 4Object Oriented Programming Assignment 4
Object Oriented Programming Assignment 4
 
Object Oriented Programming Assignment 3
Object Oriented Programming Assignment 3Object Oriented Programming Assignment 3
Object Oriented Programming Assignment 3
 
Ex
ExEx
Ex
 
Ee java lab assignment 2
Ee java lab assignment 2Ee java lab assignment 2
Ee java lab assignment 2
 
Ee java lab assignment 2
Ee java lab assignment 2Ee java lab assignment 2
Ee java lab assignment 2
 
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx
33.docxSTEP 1 Understand the UML Diagram Analyze and under.docx
 
M.tech oops through_c++_labmanual1 (1)
M.tech oops through_c++_labmanual1 (1)M.tech oops through_c++_labmanual1 (1)
M.tech oops through_c++_labmanual1 (1)
 
Java 102
Java 102Java 102
Java 102
 
exercises_for_live_coding_Java_advanced-2.pdf
exercises_for_live_coding_Java_advanced-2.pdfexercises_for_live_coding_Java_advanced-2.pdf
exercises_for_live_coding_Java_advanced-2.pdf
 
MVC Design Pattern in JavaScript by ADMEC Multimedia Institute
MVC Design Pattern in JavaScript by ADMEC Multimedia InstituteMVC Design Pattern in JavaScript by ADMEC Multimedia Institute
MVC Design Pattern in JavaScript by ADMEC Multimedia Institute
 
Object Oriented Programming Assignment 1
Object Oriented Programming Assignment 1Object Oriented Programming Assignment 1
Object Oriented Programming Assignment 1
 
Lecture 2 - Classes, Fields, Parameters, Methods and Constructors
Lecture 2 - Classes, Fields, Parameters, Methods and ConstructorsLecture 2 - Classes, Fields, Parameters, Methods and Constructors
Lecture 2 - Classes, Fields, Parameters, Methods and Constructors
 
Program Specifications in c++ Develop an inventory management system f.docx
Program Specifications in c++ Develop an inventory management system f.docxProgram Specifications in c++ Develop an inventory management system f.docx
Program Specifications in c++ Develop an inventory management system f.docx
 
Program Specifications in c++ Develop an inventory management syste.docx
Program Specifications in c++    Develop an inventory management syste.docxProgram Specifications in c++    Develop an inventory management syste.docx
Program Specifications in c++ Develop an inventory management syste.docx
 
Lab exam question_paper
Lab exam question_paperLab exam question_paper
Lab exam question_paper
 
Chapter 8Exercise1.Design an application that accept.docx
Chapter 8Exercise1.Design an application that accept.docxChapter 8Exercise1.Design an application that accept.docx
Chapter 8Exercise1.Design an application that accept.docx
 
Lab exam question_paper
Lab exam question_paperLab exam question_paper
Lab exam question_paper
 
Exercise1[5points]Create the following classe
Exercise1[5points]Create the following classeExercise1[5points]Create the following classe
Exercise1[5points]Create the following classe
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
Assignment Java Programming 2
Assignment Java Programming 2Assignment Java Programming 2
Assignment Java Programming 2
 

More from Kasun Ranga Wijeweera

Decorator Design Pattern in C#
Decorator Design Pattern in C#Decorator Design Pattern in C#
Decorator Design Pattern in C#
Kasun Ranga Wijeweera
 
Singleton Design Pattern in C#
Singleton Design Pattern in C#Singleton Design Pattern in C#
Singleton Design Pattern in C#
Kasun Ranga Wijeweera
 
Introduction to Design Patterns
Introduction to Design PatternsIntroduction to Design Patterns
Introduction to Design Patterns
Kasun Ranga Wijeweera
 
Algorithms for Convex Partitioning of a Polygon
Algorithms for Convex Partitioning of a PolygonAlgorithms for Convex Partitioning of a Polygon
Algorithms for Convex Partitioning of a Polygon
Kasun Ranga Wijeweera
 
Geometric Transformations II
Geometric Transformations IIGeometric Transformations II
Geometric Transformations II
Kasun Ranga Wijeweera
 
Geometric Transformations I
Geometric Transformations IGeometric Transformations I
Geometric Transformations I
Kasun Ranga Wijeweera
 
Introduction to Polygons
Introduction to PolygonsIntroduction to Polygons
Introduction to Polygons
Kasun Ranga Wijeweera
 
Bresenham Line Drawing Algorithm
Bresenham Line Drawing AlgorithmBresenham Line Drawing Algorithm
Bresenham Line Drawing Algorithm
Kasun Ranga Wijeweera
 
Digital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing AlgorithmDigital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing Algorithm
Kasun Ranga Wijeweera
 
Loops in Visual Basic: Exercises
Loops in Visual Basic: ExercisesLoops in Visual Basic: Exercises
Loops in Visual Basic: Exercises
Kasun Ranga Wijeweera
 
Conditional Logic: Exercises
Conditional Logic: ExercisesConditional Logic: Exercises
Conditional Logic: Exercises
Kasun Ranga Wijeweera
 
Getting Started with Visual Basic Programming
Getting Started with Visual Basic ProgrammingGetting Started with Visual Basic Programming
Getting Started with Visual Basic Programming
Kasun Ranga Wijeweera
 
CheckBoxes and RadioButtons
CheckBoxes and RadioButtonsCheckBoxes and RadioButtons
CheckBoxes and RadioButtons
Kasun Ranga Wijeweera
 
Variables in Visual Basic Programming
Variables in Visual Basic ProgrammingVariables in Visual Basic Programming
Variables in Visual Basic Programming
Kasun Ranga Wijeweera
 
Loops in Visual Basic Programming
Loops in Visual Basic ProgrammingLoops in Visual Basic Programming
Loops in Visual Basic Programming
Kasun Ranga Wijeweera
 
Conditional Logic in Visual Basic Programming
Conditional Logic in Visual Basic ProgrammingConditional Logic in Visual Basic Programming
Conditional Logic in Visual Basic Programming
Kasun Ranga Wijeweera
 
Assignment for Variables
Assignment for VariablesAssignment for Variables
Assignment for Variables
Kasun Ranga Wijeweera
 
Assignment for Factory Method Design Pattern in C# [ANSWERS]
Assignment for Factory Method Design Pattern in C# [ANSWERS]Assignment for Factory Method Design Pattern in C# [ANSWERS]
Assignment for Factory Method Design Pattern in C# [ANSWERS]
Kasun Ranga Wijeweera
 
Assignment for Events
Assignment for EventsAssignment for Events
Assignment for Events
Kasun Ranga Wijeweera
 
Mastering Arrays Assignment
Mastering Arrays AssignmentMastering Arrays Assignment
Mastering Arrays Assignment
Kasun Ranga Wijeweera
 

More from Kasun Ranga Wijeweera (20)

Decorator Design Pattern in C#
Decorator Design Pattern in C#Decorator Design Pattern in C#
Decorator Design Pattern in C#
 
Singleton Design Pattern in C#
Singleton Design Pattern in C#Singleton Design Pattern in C#
Singleton Design Pattern in C#
 
Introduction to Design Patterns
Introduction to Design PatternsIntroduction to Design Patterns
Introduction to Design Patterns
 
Algorithms for Convex Partitioning of a Polygon
Algorithms for Convex Partitioning of a PolygonAlgorithms for Convex Partitioning of a Polygon
Algorithms for Convex Partitioning of a Polygon
 
Geometric Transformations II
Geometric Transformations IIGeometric Transformations II
Geometric Transformations II
 
Geometric Transformations I
Geometric Transformations IGeometric Transformations I
Geometric Transformations I
 
Introduction to Polygons
Introduction to PolygonsIntroduction to Polygons
Introduction to Polygons
 
Bresenham Line Drawing Algorithm
Bresenham Line Drawing AlgorithmBresenham Line Drawing Algorithm
Bresenham Line Drawing Algorithm
 
Digital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing AlgorithmDigital Differential Analyzer Line Drawing Algorithm
Digital Differential Analyzer Line Drawing Algorithm
 
Loops in Visual Basic: Exercises
Loops in Visual Basic: ExercisesLoops in Visual Basic: Exercises
Loops in Visual Basic: Exercises
 
Conditional Logic: Exercises
Conditional Logic: ExercisesConditional Logic: Exercises
Conditional Logic: Exercises
 
Getting Started with Visual Basic Programming
Getting Started with Visual Basic ProgrammingGetting Started with Visual Basic Programming
Getting Started with Visual Basic Programming
 
CheckBoxes and RadioButtons
CheckBoxes and RadioButtonsCheckBoxes and RadioButtons
CheckBoxes and RadioButtons
 
Variables in Visual Basic Programming
Variables in Visual Basic ProgrammingVariables in Visual Basic Programming
Variables in Visual Basic Programming
 
Loops in Visual Basic Programming
Loops in Visual Basic ProgrammingLoops in Visual Basic Programming
Loops in Visual Basic Programming
 
Conditional Logic in Visual Basic Programming
Conditional Logic in Visual Basic ProgrammingConditional Logic in Visual Basic Programming
Conditional Logic in Visual Basic Programming
 
Assignment for Variables
Assignment for VariablesAssignment for Variables
Assignment for Variables
 
Assignment for Factory Method Design Pattern in C# [ANSWERS]
Assignment for Factory Method Design Pattern in C# [ANSWERS]Assignment for Factory Method Design Pattern in C# [ANSWERS]
Assignment for Factory Method Design Pattern in C# [ANSWERS]
 
Assignment for Events
Assignment for EventsAssignment for Events
Assignment for Events
 
Mastering Arrays Assignment
Mastering Arrays AssignmentMastering Arrays Assignment
Mastering Arrays Assignment
 

Recently uploaded

Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
KrzysztofKkol1
 
Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024
Sharepoint Designs
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
Software Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdfSoftware Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdf
MayankTawar1
 
Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
varshanayak241
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 

Recently uploaded (20)

Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
 
Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024Explore Modern SharePoint Templates for 2024
Explore Modern SharePoint Templates for 2024
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Software Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdfSoftware Testing Exam imp Ques Notes.pdf
Software Testing Exam imp Ques Notes.pdf
 
Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 

Object Oriented Programming Assignment 2

  • 1. Object Oriented Programming in Java [Lesson 1; Lesson 2] 1 of 3 Object Oriented Programming Assignment 2 Author: Kasun Ranga Wijeweera Email: krw19870829@gmail.com Date: 2018 April 7 1) Suppose you have to develop an information system for a food city. Points are added to the customer depending on the purchases made. The customers are grouped based on the number of points. a) Create a class called Customer that includes attributes: id, name, points, group, and avg with data types: “int”, “String”, “double”, “String”, and “double” respectively. b) Include a constructor with parameters: id and name. c) Include another constructor to assign default values to the attributes. d) Include a method called addPoints that is used to add a given amount to the value of the attribute points. e) Include a method called upgradePoints that is used to increase the value of the attribute points by a given percentage. f) Include a method called removePoints that is used to reduce a given amount from the value of the attribute points. If the resultant value is negative then the value of the attribute should be set into zero. g) Include a method called computeGroup that assigns a value to the attribute group based on the value of the attribute points as given in the following table. points group points < 100 Silver 100 ≤ points < 500 Gold 500 < points ≤ 2000 Platinum 2000 < points Diamond h) Include a method called display to display the values of all the attributes of a Customer object. i) Include a static method called displayAvg to display the value of the attribute avg.
  • 2. Object Oriented Programming in Java [Lesson 1; Lesson 2] 2 of 3 j) The attribute avg should be assigned the average value of points of each customer. Include a static method called calAvg to calculate the value of the attribute avg. k) Include a static method called getBest that returns the value of the attribute id of the customer with maximum number of points. l) Create the driver class called Test that includes the “main” method. m) Create an array that holds five Customer objects. Assign the objects given in the following table to each array element using the parameterized constructor. id 1543 6561 6954 3485 8546 name Nimal Saman Kasun Nayana Kalpa n) Use the method addPoints to add following points respectively to each Customer object created above. 129 785 3258 59 1652 o) Add extra 1000 points to the third customer using the method addPoints. p) Increase the points of the second customer by 2% using the method upgradePoints. q) Include a method called display to the class Test that displays all the attributes of each customer. Each set of attributes should be separated by a sequence of dots. The part of output for the first customer is given below. …………………………… Customer: 1 ID: 1543 Name: Nimal Points: 129.0 Group: null Average: 0.0 r) Invoke the method display of the class Test. s) Compute the average of points using the method calAvg. t) Compute the group of each customer using the method computeGroup. You should use a loop.
  • 3. Object Oriented Programming in Java [Lesson 1; Lesson 2] 3 of 3 u) Again invoke the method display of the class Test. v) Display the value of the attribute id of the customer with highest number of points using the method getBest. w) Invoke the method displayAvg using each Customer, c[0], c[1], c[2], c[3], and c[4] as references. x) Create a reference variable called cust of type Customer. y) Assign fifth Customer object to the reference variable cust. You should use the object you have already created. z) Reduce 2000 points from the fifth customer using the method removePoints. You should invoke the method using the reference variable cust. aa) Invoke the method display of the class Customer using the array element c[4] to display the values of attributes of the fifth customer. bb) Update the group of the fifth customer invoking the method computeGroup. cc) Invoke the method calAvg again to find the new average of points. dd) Create a Customer object with default values to its attributes by using the appropriate constructor. The object should be assigned to the reference variable cust. ee) Copy the values of the attributes of the fourth customer to the corresponding attributes of the object pointed by the reference variable cust. ff) Create another reference variable called cust1 of type Customer. gg) Assign the object pointed by the reference variable cust to cust1 as well. hh) Delete the object pointed by the reference variable cust. ii) Execute the statement cust1.id to verify the deletion of the object.