SlideShare a Scribd company logo
Exercises #1
        Print(or photocopy) the whole document and write your answers on the succeeding pages. (Handwritten only)


Name: _____________________________Schedule:_______________Points:___________

1.A Reference Class

         Create a class called Invoice that a hardware store might use to represent an invoice
for an item sold at the store. An Invoice should include four pieces of information as instance
variables – a part number(String), a part description(String), a quantity of the item being
purchased(int) and a price per item(double). Your class should have a constructor that
initializes the four instance variables. Provide mutator and accessor methods for each instance
variable. In addition, provide a method named getInvoiceAmount that calculates the invoice
amount(multiply the quantity by the price per item), then returns the amount as a double
value. If the quantity is not positive, it should be set to 0. If the price per item is not positive,
it should be set to 0.0. Draw the UML diagram for the class.

1.B Main Class

        Write a test application named InvoiceTest that demonstrates class Invoice’s
capabilities.

2.A Reference Class
        Create a class named Employee that includes three pieces of information as instance
variables – a first name(String), a last name(String) and a monthly salary(double). Your class
should have a constructor that initializes the three instance variables. Provide a set and get
method for each instance variable. Draw the UML diagram for the class.

2.B Main Class
        Write a test application named EmployeeTest that demonstrates class Employee’s
capabilities. Create two Employee objects and display each object’s salary. Then give each
Employee a 10% raise and display each Employee’s yearly salary again.

3.A
(The Rectangle class) Design a class named Rectangle to represent a rectangle. The class
contains:

          Two double data fields named width and height that specify the width and height of
           the rectangle. The default values are 1 for both width and height.
          A string data field named color that specifies the color of a rectangle.
           Hypothetically, assume that all rectangles have the same color. The default color is
           white.
          A no-arg constructor that creates a default rectangle.
          A constructor that creates a rectangle with the specified width and height.
          The accessor and mutator methods for all three data fields.
          A method named getArea() that returns the area of this rectangle.
          A method named getPerimeter() that returns the perimeter.

3.B
Draw the UML diagram for the class. Write a test program that creates two Rectangle
objects. Assign width 4 and height 40 to the first object and width 3.5 and height 35.9 to the
second object. Assign color red to all Rectangle objects. Display the properties of both
objects and find their areas and perimeters.
4.A
(The Fan class) Design a class named Fan to represent a fan. The class contains:

         Three constants named SLOW, MEDIUM, and FAST with values 1, 2, and 3 to denote the
          fan speed.
         An int data field named speed that specifies the speed of the fan (default SLOW).
         A boolean data field named on that specifies whether the fan is on (default false).
         A double data field named radius that specifies the radius of the fan (default 5).
         A string data field named color that specifies the color of the fan (default blue).
         A no-arg constructor that creates a default fan.
         The accessor and mutator methods for all four data fields.
         A method named toString() that returns a string description for the fan. If the fan is
          on, the method returns the fan speed, color, and radius in one combined string. If the
          fan is not on, the method returns fan color and radius along with the string "fan is
          off" in one combined string.

4.B

Draw the UML diagram for the class. Implement the class. Write a test program that creates
two Fan objects. Assign maximum speed, radius 10, color yellow, and turn it on to the first
object. Assign medium speed, radius 5, color blue, and turn it off to the second object.
Display the objects by invoking their toString method.

5.A
 Create a class called BirthDay that includes three pieces of information as data members –
month (type int), day (type month), and a year (type int). Your class should have a constructor
that initializes the three data members. Provide mutators and accessors for each data member.
Provide a method displayBirthDay that displays the month, day and years separated by
slashes (Example: 12/12/85). Provide another method named toString that will display the
date in words. (Example: twelfth day of December, year one thousand nine hundred
eighty five). Draw the UML diagram for the class.

5.B
Write a test application named BirthDayTest that demonstrates class BirthDay’s Application.


                                           Note: This is worth 250 points. (To be passed on Wednesday)

More Related Content

What's hot

R Programming: Introduction to Matrices
R Programming: Introduction to MatricesR Programming: Introduction to Matrices
R Programming: Introduction to Matrices
Rsquared Academy
 
02 Arrays And Memory Mapping
02 Arrays And Memory Mapping02 Arrays And Memory Mapping
02 Arrays And Memory Mapping
Qundeel
 
One dimensional arrays
One dimensional arraysOne dimensional arrays
One dimensional arrays
Satyam Soni
 
Array data structure
Array data structureArray data structure
Array data structure
maamir farooq
 
Ashish garg research paper 660_CamReady
Ashish garg research paper 660_CamReadyAshish garg research paper 660_CamReady
Ashish garg research paper 660_CamReady
Ashish Garg
 
Lecture4 oopj
Lecture4 oopjLecture4 oopj
Lecture4 oopj
Dhairya Joshi
 
Prolog upload
Prolog uploadProlog upload
Prolog upload
mitesh gajjar
 
Array
ArrayArray
Data Structure Midterm Lesson Arrays
Data Structure Midterm Lesson ArraysData Structure Midterm Lesson Arrays
Data Structure Midterm Lesson Arrays
Maulen Bale
 
02 c++ Array Pointer
02 c++ Array Pointer02 c++ Array Pointer
02 c++ Array Pointer
Tareq Hasan
 
Write a function called float dotproduct (links to an external site.)(float a...
Write a function called float dotproduct (links to an external site.)(float a...Write a function called float dotproduct (links to an external site.)(float a...
Write a function called float dotproduct (links to an external site.)(float a...
JenniferBall48
 
Scalable machine learning
Scalable machine learningScalable machine learning
Scalable machine learning
Tien-Yang (Aiden) Wu
 
R Data Visualization Tutorial: Bar Plots
R Data Visualization Tutorial: Bar PlotsR Data Visualization Tutorial: Bar Plots
R Data Visualization Tutorial: Bar Plots
Rsquared Academy
 
Object Oriented Programming - 5.1. Array
Object Oriented Programming - 5.1. ArrayObject Oriented Programming - 5.1. Array
Object Oriented Programming - 5.1. Array
AndiNurkholis1
 
Identification des systémes dynamiques
Identification des systémes dynamiquesIdentification des systémes dynamiques
Identification des systémes dynamiques
Ayoub Moufid
 
Arrays in c_language
Arrays in c_language Arrays in c_language
Arrays in c_language
Infinity Tech Solutions
 
ARRAY
ARRAYARRAY
ARRAY
ayush raj
 
Presentation on array
Presentation on array Presentation on array
Presentation on array
topu93
 
Arrays
ArraysArrays
Java part 2
Java part  2Java part  2

What's hot (20)

R Programming: Introduction to Matrices
R Programming: Introduction to MatricesR Programming: Introduction to Matrices
R Programming: Introduction to Matrices
 
02 Arrays And Memory Mapping
02 Arrays And Memory Mapping02 Arrays And Memory Mapping
02 Arrays And Memory Mapping
 
One dimensional arrays
One dimensional arraysOne dimensional arrays
One dimensional arrays
 
Array data structure
Array data structureArray data structure
Array data structure
 
Ashish garg research paper 660_CamReady
Ashish garg research paper 660_CamReadyAshish garg research paper 660_CamReady
Ashish garg research paper 660_CamReady
 
Lecture4 oopj
Lecture4 oopjLecture4 oopj
Lecture4 oopj
 
Prolog upload
Prolog uploadProlog upload
Prolog upload
 
Array
ArrayArray
Array
 
Data Structure Midterm Lesson Arrays
Data Structure Midterm Lesson ArraysData Structure Midterm Lesson Arrays
Data Structure Midterm Lesson Arrays
 
02 c++ Array Pointer
02 c++ Array Pointer02 c++ Array Pointer
02 c++ Array Pointer
 
Write a function called float dotproduct (links to an external site.)(float a...
Write a function called float dotproduct (links to an external site.)(float a...Write a function called float dotproduct (links to an external site.)(float a...
Write a function called float dotproduct (links to an external site.)(float a...
 
Scalable machine learning
Scalable machine learningScalable machine learning
Scalable machine learning
 
R Data Visualization Tutorial: Bar Plots
R Data Visualization Tutorial: Bar PlotsR Data Visualization Tutorial: Bar Plots
R Data Visualization Tutorial: Bar Plots
 
Object Oriented Programming - 5.1. Array
Object Oriented Programming - 5.1. ArrayObject Oriented Programming - 5.1. Array
Object Oriented Programming - 5.1. Array
 
Identification des systémes dynamiques
Identification des systémes dynamiquesIdentification des systémes dynamiques
Identification des systémes dynamiques
 
Arrays in c_language
Arrays in c_language Arrays in c_language
Arrays in c_language
 
ARRAY
ARRAYARRAY
ARRAY
 
Presentation on array
Presentation on array Presentation on array
Presentation on array
 
Arrays
ArraysArrays
Arrays
 
Java part 2
Java part  2Java part  2
Java part 2
 

Similar to Assignment in java

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
 
JAVA practical Exam Questions (1).docx
JAVA practical Exam Questions (1).docxJAVA practical Exam Questions (1).docx
JAVA practical Exam Questions (1).docx
Lucky Ally
 
Java execise
Java execiseJava execise
Java execise
Keneth miles
 
This lab must be finished in the lab period. Write a class named Fan .docx
 This lab must be finished in the lab period. Write a class named Fan .docx This lab must be finished in the lab period. Write a class named Fan .docx
This lab must be finished in the lab period. Write a class named Fan .docx
Komlin1
 
C programming session 04
C programming session 04C programming session 04
C programming session 04
Dushmanta Nath
 
OOP Assignment 03.pdf
OOP Assignment 03.pdfOOP Assignment 03.pdf
OOP Assignment 03.pdf
ARSLANMEHMOOD47
 
Background This course is all about data visualization. However, we.docx
Background This course is all about data visualization. However, we.docxBackground This course is all about data visualization. However, we.docx
Background This course is all about data visualization. However, we.docx
rosemaryralphs52525
 
Arrays
ArraysArrays
© 2014 Laureate Education, Inc. Page 1 of 4 Retail Trans.docx
© 2014 Laureate Education, Inc.   Page 1 of 4 Retail Trans.docx© 2014 Laureate Education, Inc.   Page 1 of 4 Retail Trans.docx
© 2014 Laureate Education, Inc. Page 1 of 4 Retail Trans.docx
LynellBull52
 
Exercise1[5points]Create the following classe
Exercise1[5points]Create the following classeExercise1[5points]Create the following classe
Exercise1[5points]Create the following classe
mecklenburgstrelitzh
 
Task 1
Task 1Task 1
Lab6: I/O and Arrays
Lab6: I/O and ArraysLab6: I/O and Arrays
Lab6: I/O and Arrays
enidcruz
 
Develop a system flowchart and then write a menu-driven C++ program .pdf
Develop a system flowchart and then write a menu-driven C++ program .pdfDevelop a system flowchart and then write a menu-driven C++ program .pdf
Develop a system flowchart and then write a menu-driven C++ program .pdf
leventhalbrad49439
 
Lab7: More Arrays, Strings, Vectors, and Pointers
Lab7: More Arrays, Strings, Vectors, and PointersLab7: More Arrays, Strings, Vectors, and Pointers
Lab7: More Arrays, Strings, Vectors, and Pointers
enidcruz
 
Functions, Strings ,Storage classes in C
 Functions, Strings ,Storage classes in C Functions, Strings ,Storage classes in C
Functions, Strings ,Storage classes in C
arshpreetkaur07
 
Hub102 - JS - Lesson3
Hub102 - JS - Lesson3Hub102 - JS - Lesson3
Hub102 - JS - Lesson3
Tiểu Hổ
 
Sharbani bhattacharya VB Structures
Sharbani bhattacharya VB StructuresSharbani bhattacharya VB Structures
Sharbani bhattacharya VB Structures
Sharbani Bhattacharya
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
Golden Julie Jesus
 
C programming session 05
C programming session 05C programming session 05
C programming session 05
Vivek Singh
 
Array sheet
Array sheet Array sheet
Array sheet
Mahmoud Abuelmagd
 

Similar to Assignment in java (20)

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
 
JAVA practical Exam Questions (1).docx
JAVA practical Exam Questions (1).docxJAVA practical Exam Questions (1).docx
JAVA practical Exam Questions (1).docx
 
Java execise
Java execiseJava execise
Java execise
 
This lab must be finished in the lab period. Write a class named Fan .docx
 This lab must be finished in the lab period. Write a class named Fan .docx This lab must be finished in the lab period. Write a class named Fan .docx
This lab must be finished in the lab period. Write a class named Fan .docx
 
C programming session 04
C programming session 04C programming session 04
C programming session 04
 
OOP Assignment 03.pdf
OOP Assignment 03.pdfOOP Assignment 03.pdf
OOP Assignment 03.pdf
 
Background This course is all about data visualization. However, we.docx
Background This course is all about data visualization. However, we.docxBackground This course is all about data visualization. However, we.docx
Background This course is all about data visualization. However, we.docx
 
Arrays
ArraysArrays
Arrays
 
© 2014 Laureate Education, Inc. Page 1 of 4 Retail Trans.docx
© 2014 Laureate Education, Inc.   Page 1 of 4 Retail Trans.docx© 2014 Laureate Education, Inc.   Page 1 of 4 Retail Trans.docx
© 2014 Laureate Education, Inc. Page 1 of 4 Retail Trans.docx
 
Exercise1[5points]Create the following classe
Exercise1[5points]Create the following classeExercise1[5points]Create the following classe
Exercise1[5points]Create the following classe
 
Task 1
Task 1Task 1
Task 1
 
Lab6: I/O and Arrays
Lab6: I/O and ArraysLab6: I/O and Arrays
Lab6: I/O and Arrays
 
Develop a system flowchart and then write a menu-driven C++ program .pdf
Develop a system flowchart and then write a menu-driven C++ program .pdfDevelop a system flowchart and then write a menu-driven C++ program .pdf
Develop a system flowchart and then write a menu-driven C++ program .pdf
 
Lab7: More Arrays, Strings, Vectors, and Pointers
Lab7: More Arrays, Strings, Vectors, and PointersLab7: More Arrays, Strings, Vectors, and Pointers
Lab7: More Arrays, Strings, Vectors, and Pointers
 
Functions, Strings ,Storage classes in C
 Functions, Strings ,Storage classes in C Functions, Strings ,Storage classes in C
Functions, Strings ,Storage classes in C
 
Hub102 - JS - Lesson3
Hub102 - JS - Lesson3Hub102 - JS - Lesson3
Hub102 - JS - Lesson3
 
Sharbani bhattacharya VB Structures
Sharbani bhattacharya VB StructuresSharbani bhattacharya VB Structures
Sharbani bhattacharya VB Structures
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
 
C programming session 05
C programming session 05C programming session 05
C programming session 05
 
Array sheet
Array sheet Array sheet
Array sheet
 

Recently uploaded

The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
Kavitha Krishnan
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
PECB
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 

Recently uploaded (20)

The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
ISO/IEC 27001, ISO/IEC 42001, and GDPR: Best Practices for Implementation and...
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 

Assignment in java

  • 1. Exercises #1 Print(or photocopy) the whole document and write your answers on the succeeding pages. (Handwritten only) Name: _____________________________Schedule:_______________Points:___________ 1.A Reference Class Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four pieces of information as instance variables – a part number(String), a part description(String), a quantity of the item being purchased(int) and a price per item(double). Your class should have a constructor that initializes the four instance variables. Provide mutator and accessor methods for each instance variable. In addition, provide a method named getInvoiceAmount that calculates the invoice amount(multiply the quantity by the price per item), then returns the amount as a double value. If the quantity is not positive, it should be set to 0. If the price per item is not positive, it should be set to 0.0. Draw the UML diagram for the class. 1.B Main Class Write a test application named InvoiceTest that demonstrates class Invoice’s capabilities. 2.A Reference Class Create a class named Employee that includes three pieces of information as instance variables – a first name(String), a last name(String) and a monthly salary(double). Your class should have a constructor that initializes the three instance variables. Provide a set and get method for each instance variable. Draw the UML diagram for the class. 2.B Main Class Write a test application named EmployeeTest that demonstrates class Employee’s capabilities. Create two Employee objects and display each object’s salary. Then give each Employee a 10% raise and display each Employee’s yearly salary again. 3.A (The Rectangle class) Design a class named Rectangle to represent a rectangle. The class contains:  Two double data fields named width and height that specify the width and height of the rectangle. The default values are 1 for both width and height.  A string data field named color that specifies the color of a rectangle. Hypothetically, assume that all rectangles have the same color. The default color is white.  A no-arg constructor that creates a default rectangle.  A constructor that creates a rectangle with the specified width and height.  The accessor and mutator methods for all three data fields.  A method named getArea() that returns the area of this rectangle.  A method named getPerimeter() that returns the perimeter. 3.B Draw the UML diagram for the class. Write a test program that creates two Rectangle objects. Assign width 4 and height 40 to the first object and width 3.5 and height 35.9 to the second object. Assign color red to all Rectangle objects. Display the properties of both objects and find their areas and perimeters.
  • 2. 4.A (The Fan class) Design a class named Fan to represent a fan. The class contains:  Three constants named SLOW, MEDIUM, and FAST with values 1, 2, and 3 to denote the fan speed.  An int data field named speed that specifies the speed of the fan (default SLOW).  A boolean data field named on that specifies whether the fan is on (default false).  A double data field named radius that specifies the radius of the fan (default 5).  A string data field named color that specifies the color of the fan (default blue).  A no-arg constructor that creates a default fan.  The accessor and mutator methods for all four data fields.  A method named toString() that returns a string description for the fan. If the fan is on, the method returns the fan speed, color, and radius in one combined string. If the fan is not on, the method returns fan color and radius along with the string "fan is off" in one combined string. 4.B Draw the UML diagram for the class. Implement the class. Write a test program that creates two Fan objects. Assign maximum speed, radius 10, color yellow, and turn it on to the first object. Assign medium speed, radius 5, color blue, and turn it off to the second object. Display the objects by invoking their toString method. 5.A Create a class called BirthDay that includes three pieces of information as data members – month (type int), day (type month), and a year (type int). Your class should have a constructor that initializes the three data members. Provide mutators and accessors for each data member. Provide a method displayBirthDay that displays the month, day and years separated by slashes (Example: 12/12/85). Provide another method named toString that will display the date in words. (Example: twelfth day of December, year one thousand nine hundred eighty five). Draw the UML diagram for the class. 5.B Write a test application named BirthDayTest that demonstrates class BirthDay’s Application. Note: This is worth 250 points. (To be passed on Wednesday)