SlideShare a Scribd company logo
1 of 3
Download to read offline
Java Programe Q.1-4
2. Rational Numbers (15 points) In mathematics, a rational number is any number that can be
expressed as the quotient or fraction p/q of two integers, a numerator p and a non-zero
denominator q. Since q may be equal to 1 , every integer is a rational number. -- Wikipedia 1
Write a Java class for rational numbers. The class should have 1. two fields of type int, one for
the numerator and the other for the denominator. 2. a constructor with two parameters, for the
numerator and denominator, respectively. 3. four methods called add, subtract, multiply, and
divide, respectively; Each method takes another rational number as the parameter, does the
calculation using this and the parameter rational number, and returns the result rational. 4. a
simplify method that simplifies this rational number. Each simplified rational number should
satisfy the following three requirements: a. Common factors between the numerator and the
denominator should be cancelled out; For example, 12/30 should become 2/5 after simplification.
b. The denominator should always be positive, while the numerator could be positive, negative,
or zero; c. The denominator should always be 1 when the rational number is an integer. 5. a
toString method which returns the string representation of this in the form
numerator/denominator. Notes: - You may assume the following when completing the class: 1)
The constructor will never be used to instantiate a rational number with denominator equal to 0;2
) The parameters of add, subtract, multiply, and divide will never be null; 3 ) The parameter of
divide will never be equal to 0 . - You may define additional methods when you see fit. - Tests in
RationalTest.java should all pass after you've completed the class. What to do: In Rational.java
[Task 2] Add the missing fields to class Rational. [Task 3] Complete the constructor and the
methods add, subtract, multiply, divide, simplify, and toString.
A complex number is a number that can be expressed in the form a+bi, where a and b are real
numbers and i is the imaginary unit, which satisfies the equation i2=1. In this expression, a is the
real part and b is the imaginary part of the complex number. -- Wikipedia Write a Java class for
complex numbers, but with both the real and the imaginary parts of type Rational. The class
should have 1. two fields of type Rational, one for the real part and the other for the imaginary
part. 2. a constructor with two parameters, one for the real part and the other for the imaginary
part. 3. four methods called add, subtract, multiply, and divide, respectively; Each method takes
another complex number as the parameter, does the calculation using this and the parameter, and
returns the result complex. 4. a simplify method that simplifies the real and imaginary parts of
this. 2 5. a toString method which returns the string representation of this in the form (real,
imaginary). Notes: - You may assume the following when completing the class: 1) The
parameters of the constructor are never null; 2) The parameters of add, subtract, multiply, and
divide will never be null; 3) The parameter of divide will never be equal to 0+0i or 00i. - You
may define additional methods when you see fit. - Tests in ComplexTest.java should all pass
after you've completed the class. What to do: In Complex.java [Task 4] Add the missing fields to
class Complex. [Task 5] Complete the constructor as well as the methods add, subtract, multiply,
divide, and asString.
4. XYRectangle(20 points) A point P in a Cartesian coordinate system can be denoted using its
x-coordinate and y-coordinate as (xp,yp), and an xy-rectangle, i.e., a rectangle with its four sides
in parallel or overlapping with the x - and y-axes, can be represented using its top-left vertex Pt
and bottom-right vertex Pbr as Ptl,Pbr. For example, xy rectangle R1 in Figure 1 (in solid line)
can be represented as P1,P2, while xy-rectangle R2 (in dotted line) can be represented as P3,P4.
Given class Point as defined in XYRectangle.java, please complete class XY Rectangle so that
each XY Rectangle object represents a valid xy-rectangle and supports the following operations:
Figure 1. Two xy-rectangles. 1. A constructor that takes two points as arguments and initializes
the newly created xyrectangle in such a way that the line segment between the two points forms
a diagonal of the rectangle; You may assume that the line passing both argument points always
intersects with both the x and the y axis. 2. A method toString that returns a String representation
of the xy-rectangle in the form Ptt,Pbr, where a point P with coordinates Px and Py is denoted as
(Px,Py). For example, given an xy-rectangle with the top-left and bottom-right vertexes at
positions (2,3) and (4,1), invoking toString on the xy-rectangle will return " <(2,3),(4,1)> ". 3. A
method area that takes no argument and returns the area of the xy-rectangle. 4. A method
rotateClockwise that takes no argument and rotates the current xy-rectangle clockwise by 90
degrees around its top-left vertex; For example, xy-rectangle R1 in Figure 1 will be at the
position of R2 after the method is invoked on R1. 5. A method move that takes two arguments
deltaX and deltaY and moves the xy-rectangle horizontally by deltaX and vertically by deltaY. 6.
A method contains that takes a point P as the argument and returns true if and only if the point is
within or on the border of the xy-rectangle. 7. A method contains that takes an xy-rectangle R as
the argument and returns true if and only if every point contained in R is also contained in the
current xy-rectangle. 8. A method overlapsWith that takes an xy-rectangle R as the argument and
returns true if and only if at least one point is contained in both R and this xy-rectangle. Note: 3 -
You may assume that the reference-typed parameters of the constructor or methods are never
null. - You may define additional methods when you see fit. - Tests in XYRectangleTest.java
should all pass after you've completed the class. What to do: In XYRectangle.java [Task 6]
Complete the constructor as well as the other methods in class XYRectangle.
Given an integer value X, you need to return the base-7 representation of X as a string. In a base-
7 representation, each digit is between 0 and 6 , both inclusive, and the value of a digit is based
on its position in the representation. For example, given a base-7 representation
r1=(dnd3d2d1d0)7(0di6,0in), the decimal value of r1 is calculated as
dn7n++d373+d272+d171+d070. What to do: In Base7.java [Task 1] Complete method
convertToBase7 in class Base7 so that the method will take an int value as the argument and
return the argument's String representation based on 7 . For example, when the input value is 100
, the method should return a string "202". Notes: - You may not add new methods to class Base7.
- You may right-click on class Base7Test and select "Run 'Base7Test"' to execute the tests we
prepared for class Base7. If any test fails, your implementation is buggy. Note, however, that
since the provided tests only check a small number of input/output pairs, passing all those tests
does not mean your implementation is correct.

More Related Content

Similar to Java Programe Q.1-4 2. Rational Numbers (15 points) In mathematic.pdf

Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]Palak Sanghani
 
Calculus Application Problem #3 Name _________________________.docx
Calculus Application Problem #3 Name _________________________.docxCalculus Application Problem #3 Name _________________________.docx
Calculus Application Problem #3 Name _________________________.docxhumphrieskalyn
 
C++ Programming Homework Help
C++ Programming Homework HelpC++ Programming Homework Help
C++ Programming Homework HelpC++ Homework Help
 
I can statements 7th grade cc math - ns
I can statements   7th grade cc math - nsI can statements   7th grade cc math - ns
I can statements 7th grade cc math - nsking42
 
CE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdfCE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdfUmarMustafa13
 
5HBC: How to Graph Implicit Relations Intro Packet!
5HBC: How to Graph Implicit Relations Intro Packet!5HBC: How to Graph Implicit Relations Intro Packet!
5HBC: How to Graph Implicit Relations Intro Packet!A Jorge Garcia
 
Dsp manual completed2
Dsp manual completed2Dsp manual completed2
Dsp manual completed2bilawalali74
 
Arrays with Numpy, Computer Graphics
Arrays with Numpy, Computer GraphicsArrays with Numpy, Computer Graphics
Arrays with Numpy, Computer GraphicsPrabu U
 
A New Deterministic RSA-Factoring Algorithm
A New Deterministic RSA-Factoring AlgorithmA New Deterministic RSA-Factoring Algorithm
A New Deterministic RSA-Factoring AlgorithmJim Jimenez
 
Plane-and-Solid-Geometry. introduction to proving
Plane-and-Solid-Geometry. introduction to provingPlane-and-Solid-Geometry. introduction to proving
Plane-and-Solid-Geometry. introduction to provingReyRoluna1
 
REPRESENTATION OF FUNCTIONS.pptx
REPRESENTATION OF FUNCTIONS.pptxREPRESENTATION OF FUNCTIONS.pptx
REPRESENTATION OF FUNCTIONS.pptxGiezerAgamata1
 

Similar to Java Programe Q.1-4 2. Rational Numbers (15 points) In mathematic.pdf (20)

working with python
working with pythonworking with python
working with python
 
Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]Lec 8 03_sept [compatibility mode]
Lec 8 03_sept [compatibility mode]
 
Calculus Application Problem #3 Name _________________________.docx
Calculus Application Problem #3 Name _________________________.docxCalculus Application Problem #3 Name _________________________.docx
Calculus Application Problem #3 Name _________________________.docx
 
C++ Programming Homework Help
C++ Programming Homework HelpC++ Programming Homework Help
C++ Programming Homework Help
 
I can statements 7th grade cc math - ns
I can statements   7th grade cc math - nsI can statements   7th grade cc math - ns
I can statements 7th grade cc math - ns
 
Functional object
Functional objectFunctional object
Functional object
 
CE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdfCE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdf
 
5HBC: How to Graph Implicit Relations Intro Packet!
5HBC: How to Graph Implicit Relations Intro Packet!5HBC: How to Graph Implicit Relations Intro Packet!
5HBC: How to Graph Implicit Relations Intro Packet!
 
BP106RMT.pdf
BP106RMT.pdfBP106RMT.pdf
BP106RMT.pdf
 
MATLABgraphPlotting.pptx
MATLABgraphPlotting.pptxMATLABgraphPlotting.pptx
MATLABgraphPlotting.pptx
 
Dsp manual completed2
Dsp manual completed2Dsp manual completed2
Dsp manual completed2
 
Algebra booklet
Algebra bookletAlgebra booklet
Algebra booklet
 
Arrays with Numpy, Computer Graphics
Arrays with Numpy, Computer GraphicsArrays with Numpy, Computer Graphics
Arrays with Numpy, Computer Graphics
 
Advance algebra
Advance algebraAdvance algebra
Advance algebra
 
Fst ch2 notes
Fst ch2 notesFst ch2 notes
Fst ch2 notes
 
1 1 number theory
1 1 number theory1 1 number theory
1 1 number theory
 
A New Deterministic RSA-Factoring Algorithm
A New Deterministic RSA-Factoring AlgorithmA New Deterministic RSA-Factoring Algorithm
A New Deterministic RSA-Factoring Algorithm
 
Plane-and-Solid-Geometry. introduction to proving
Plane-and-Solid-Geometry. introduction to provingPlane-and-Solid-Geometry. introduction to proving
Plane-and-Solid-Geometry. introduction to proving
 
REPRESENTATION OF FUNCTIONS.pptx
REPRESENTATION OF FUNCTIONS.pptxREPRESENTATION OF FUNCTIONS.pptx
REPRESENTATION OF FUNCTIONS.pptx
 
A02
A02A02
A02
 

More from fantasiatheoutofthef

Introduction Pervasive computing demands the all-encompassing exploi.pdf
Introduction Pervasive computing demands the all-encompassing exploi.pdfIntroduction Pervasive computing demands the all-encompassing exploi.pdf
Introduction Pervasive computing demands the all-encompassing exploi.pdffantasiatheoutofthef
 
International projects are on the rise, so the need for project mana.pdf
International projects are on the rise, so the need for project mana.pdfInternational projects are on the rise, so the need for project mana.pdf
International projects are on the rise, so the need for project mana.pdffantasiatheoutofthef
 
Instructions On July 1, a petty cash fund was established for $100. .pdf
Instructions On July 1, a petty cash fund was established for $100. .pdfInstructions On July 1, a petty cash fund was established for $100. .pdf
Instructions On July 1, a petty cash fund was established for $100. .pdffantasiatheoutofthef
 
Just C, D, E 7-1 Hoare partition correctness The version of PART.pdf
Just C, D, E 7-1 Hoare partition correctness The version of PART.pdfJust C, D, E 7-1 Hoare partition correctness The version of PART.pdf
Just C, D, E 7-1 Hoare partition correctness The version of PART.pdffantasiatheoutofthef
 
Integral ICreate a Python function for I-Importancedef monteca.pdf
Integral ICreate a Python function for I-Importancedef monteca.pdfIntegral ICreate a Python function for I-Importancedef monteca.pdf
Integral ICreate a Python function for I-Importancedef monteca.pdffantasiatheoutofthef
 
IntroductionThe capstone project is a �structured walkthrough� pen.pdf
IntroductionThe capstone project is a �structured walkthrough� pen.pdfIntroductionThe capstone project is a �structured walkthrough� pen.pdf
IntroductionThe capstone project is a �structured walkthrough� pen.pdffantasiatheoutofthef
 
Industry Solution Descartes for Ocean Carriers Customer Success Stor.pdf
Industry Solution Descartes for Ocean Carriers Customer Success Stor.pdfIndustry Solution Descartes for Ocean Carriers Customer Success Stor.pdf
Industry Solution Descartes for Ocean Carriers Customer Success Stor.pdffantasiatheoutofthef
 
Jefferson City has several capital projects that the mayor wants to .pdf
Jefferson City has several capital projects that the mayor wants to .pdfJefferson City has several capital projects that the mayor wants to .pdf
Jefferson City has several capital projects that the mayor wants to .pdffantasiatheoutofthef
 
Instructions Create an Android app according to the requirements below.pdf
Instructions Create an Android app according to the requirements below.pdfInstructions Create an Android app according to the requirements below.pdf
Instructions Create an Android app according to the requirements below.pdffantasiatheoutofthef
 
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdfJAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdffantasiatheoutofthef
 
In this case study, we will explore the exercise of power in leaders.pdf
In this case study, we will explore the exercise of power in leaders.pdfIn this case study, we will explore the exercise of power in leaders.pdf
In this case study, we will explore the exercise of power in leaders.pdffantasiatheoutofthef
 
James Santelli was staying at a motel owned by Abu Rahmatullah for s.pdf
James Santelli was staying at a motel owned by Abu Rahmatullah for s.pdfJames Santelli was staying at a motel owned by Abu Rahmatullah for s.pdf
James Santelli was staying at a motel owned by Abu Rahmatullah for s.pdffantasiatheoutofthef
 
Ive already completed the Java assignment below, but it doesnt wor.pdf
Ive already completed the Java assignment below, but it doesnt wor.pdfIve already completed the Java assignment below, but it doesnt wor.pdf
Ive already completed the Java assignment below, but it doesnt wor.pdffantasiatheoutofthef
 
In this assignment you will implement insert() method for a singly l.pdf
In this assignment you will implement insert() method for a singly l.pdfIn this assignment you will implement insert() method for a singly l.pdf
In this assignment you will implement insert() method for a singly l.pdffantasiatheoutofthef
 
Introduction Pervasive computing demands the all-encompassing exploita.pdf
Introduction Pervasive computing demands the all-encompassing exploita.pdfIntroduction Pervasive computing demands the all-encompassing exploita.pdf
Introduction Pervasive computing demands the all-encompassing exploita.pdffantasiatheoutofthef
 
Introduction (1 Mark)Body (7 Marks)1-Definition of Technolog.pdf
Introduction (1 Mark)Body (7 Marks)1-Definition of Technolog.pdfIntroduction (1 Mark)Body (7 Marks)1-Definition of Technolog.pdf
Introduction (1 Mark)Body (7 Marks)1-Definition of Technolog.pdffantasiatheoutofthef
 
Integral IEstimator for Iwhere f(x) = 20 - x^2 and p(x) ~ U[a,.pdf
Integral IEstimator for Iwhere f(x) = 20 - x^2 and p(x) ~ U[a,.pdfIntegral IEstimator for Iwhere f(x) = 20 - x^2 and p(x) ~ U[a,.pdf
Integral IEstimator for Iwhere f(x) = 20 - x^2 and p(x) ~ U[a,.pdffantasiatheoutofthef
 
Indicate and provide a brief explanation for whether the following i.pdf
Indicate and provide a brief explanation for whether the following i.pdfIndicate and provide a brief explanation for whether the following i.pdf
Indicate and provide a brief explanation for whether the following i.pdffantasiatheoutofthef
 
Lindsay was leaving a local department store when an armed security .pdf
Lindsay was leaving a local department store when an armed security .pdfLindsay was leaving a local department store when an armed security .pdf
Lindsay was leaving a local department store when an armed security .pdffantasiatheoutofthef
 
Learning Team � Ethical Challenges Worksheet Your team of internat.pdf
Learning Team � Ethical Challenges Worksheet Your team of internat.pdfLearning Team � Ethical Challenges Worksheet Your team of internat.pdf
Learning Team � Ethical Challenges Worksheet Your team of internat.pdffantasiatheoutofthef
 

More from fantasiatheoutofthef (20)

Introduction Pervasive computing demands the all-encompassing exploi.pdf
Introduction Pervasive computing demands the all-encompassing exploi.pdfIntroduction Pervasive computing demands the all-encompassing exploi.pdf
Introduction Pervasive computing demands the all-encompassing exploi.pdf
 
International projects are on the rise, so the need for project mana.pdf
International projects are on the rise, so the need for project mana.pdfInternational projects are on the rise, so the need for project mana.pdf
International projects are on the rise, so the need for project mana.pdf
 
Instructions On July 1, a petty cash fund was established for $100. .pdf
Instructions On July 1, a petty cash fund was established for $100. .pdfInstructions On July 1, a petty cash fund was established for $100. .pdf
Instructions On July 1, a petty cash fund was established for $100. .pdf
 
Just C, D, E 7-1 Hoare partition correctness The version of PART.pdf
Just C, D, E 7-1 Hoare partition correctness The version of PART.pdfJust C, D, E 7-1 Hoare partition correctness The version of PART.pdf
Just C, D, E 7-1 Hoare partition correctness The version of PART.pdf
 
Integral ICreate a Python function for I-Importancedef monteca.pdf
Integral ICreate a Python function for I-Importancedef monteca.pdfIntegral ICreate a Python function for I-Importancedef monteca.pdf
Integral ICreate a Python function for I-Importancedef monteca.pdf
 
IntroductionThe capstone project is a �structured walkthrough� pen.pdf
IntroductionThe capstone project is a �structured walkthrough� pen.pdfIntroductionThe capstone project is a �structured walkthrough� pen.pdf
IntroductionThe capstone project is a �structured walkthrough� pen.pdf
 
Industry Solution Descartes for Ocean Carriers Customer Success Stor.pdf
Industry Solution Descartes for Ocean Carriers Customer Success Stor.pdfIndustry Solution Descartes for Ocean Carriers Customer Success Stor.pdf
Industry Solution Descartes for Ocean Carriers Customer Success Stor.pdf
 
Jefferson City has several capital projects that the mayor wants to .pdf
Jefferson City has several capital projects that the mayor wants to .pdfJefferson City has several capital projects that the mayor wants to .pdf
Jefferson City has several capital projects that the mayor wants to .pdf
 
Instructions Create an Android app according to the requirements below.pdf
Instructions Create an Android app according to the requirements below.pdfInstructions Create an Android app according to the requirements below.pdf
Instructions Create an Android app according to the requirements below.pdf
 
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdfJAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
 
In this case study, we will explore the exercise of power in leaders.pdf
In this case study, we will explore the exercise of power in leaders.pdfIn this case study, we will explore the exercise of power in leaders.pdf
In this case study, we will explore the exercise of power in leaders.pdf
 
James Santelli was staying at a motel owned by Abu Rahmatullah for s.pdf
James Santelli was staying at a motel owned by Abu Rahmatullah for s.pdfJames Santelli was staying at a motel owned by Abu Rahmatullah for s.pdf
James Santelli was staying at a motel owned by Abu Rahmatullah for s.pdf
 
Ive already completed the Java assignment below, but it doesnt wor.pdf
Ive already completed the Java assignment below, but it doesnt wor.pdfIve already completed the Java assignment below, but it doesnt wor.pdf
Ive already completed the Java assignment below, but it doesnt wor.pdf
 
In this assignment you will implement insert() method for a singly l.pdf
In this assignment you will implement insert() method for a singly l.pdfIn this assignment you will implement insert() method for a singly l.pdf
In this assignment you will implement insert() method for a singly l.pdf
 
Introduction Pervasive computing demands the all-encompassing exploita.pdf
Introduction Pervasive computing demands the all-encompassing exploita.pdfIntroduction Pervasive computing demands the all-encompassing exploita.pdf
Introduction Pervasive computing demands the all-encompassing exploita.pdf
 
Introduction (1 Mark)Body (7 Marks)1-Definition of Technolog.pdf
Introduction (1 Mark)Body (7 Marks)1-Definition of Technolog.pdfIntroduction (1 Mark)Body (7 Marks)1-Definition of Technolog.pdf
Introduction (1 Mark)Body (7 Marks)1-Definition of Technolog.pdf
 
Integral IEstimator for Iwhere f(x) = 20 - x^2 and p(x) ~ U[a,.pdf
Integral IEstimator for Iwhere f(x) = 20 - x^2 and p(x) ~ U[a,.pdfIntegral IEstimator for Iwhere f(x) = 20 - x^2 and p(x) ~ U[a,.pdf
Integral IEstimator for Iwhere f(x) = 20 - x^2 and p(x) ~ U[a,.pdf
 
Indicate and provide a brief explanation for whether the following i.pdf
Indicate and provide a brief explanation for whether the following i.pdfIndicate and provide a brief explanation for whether the following i.pdf
Indicate and provide a brief explanation for whether the following i.pdf
 
Lindsay was leaving a local department store when an armed security .pdf
Lindsay was leaving a local department store when an armed security .pdfLindsay was leaving a local department store when an armed security .pdf
Lindsay was leaving a local department store when an armed security .pdf
 
Learning Team � Ethical Challenges Worksheet Your team of internat.pdf
Learning Team � Ethical Challenges Worksheet Your team of internat.pdfLearning Team � Ethical Challenges Worksheet Your team of internat.pdf
Learning Team � Ethical Challenges Worksheet Your team of internat.pdf
 

Recently uploaded

AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........LeaCamillePacle
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 

Recently uploaded (20)

AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"Rapple "Scholarly Communications and the Sustainable Development Goals"
Rapple "Scholarly Communications and the Sustainable Development Goals"
 

Java Programe Q.1-4 2. Rational Numbers (15 points) In mathematic.pdf

  • 1. Java Programe Q.1-4 2. Rational Numbers (15 points) In mathematics, a rational number is any number that can be expressed as the quotient or fraction p/q of two integers, a numerator p and a non-zero denominator q. Since q may be equal to 1 , every integer is a rational number. -- Wikipedia 1 Write a Java class for rational numbers. The class should have 1. two fields of type int, one for the numerator and the other for the denominator. 2. a constructor with two parameters, for the numerator and denominator, respectively. 3. four methods called add, subtract, multiply, and divide, respectively; Each method takes another rational number as the parameter, does the calculation using this and the parameter rational number, and returns the result rational. 4. a simplify method that simplifies this rational number. Each simplified rational number should satisfy the following three requirements: a. Common factors between the numerator and the denominator should be cancelled out; For example, 12/30 should become 2/5 after simplification. b. The denominator should always be positive, while the numerator could be positive, negative, or zero; c. The denominator should always be 1 when the rational number is an integer. 5. a toString method which returns the string representation of this in the form numerator/denominator. Notes: - You may assume the following when completing the class: 1) The constructor will never be used to instantiate a rational number with denominator equal to 0;2 ) The parameters of add, subtract, multiply, and divide will never be null; 3 ) The parameter of divide will never be equal to 0 . - You may define additional methods when you see fit. - Tests in RationalTest.java should all pass after you've completed the class. What to do: In Rational.java [Task 2] Add the missing fields to class Rational. [Task 3] Complete the constructor and the methods add, subtract, multiply, divide, simplify, and toString. A complex number is a number that can be expressed in the form a+bi, where a and b are real numbers and i is the imaginary unit, which satisfies the equation i2=1. In this expression, a is the real part and b is the imaginary part of the complex number. -- Wikipedia Write a Java class for complex numbers, but with both the real and the imaginary parts of type Rational. The class should have 1. two fields of type Rational, one for the real part and the other for the imaginary part. 2. a constructor with two parameters, one for the real part and the other for the imaginary part. 3. four methods called add, subtract, multiply, and divide, respectively; Each method takes
  • 2. another complex number as the parameter, does the calculation using this and the parameter, and returns the result complex. 4. a simplify method that simplifies the real and imaginary parts of this. 2 5. a toString method which returns the string representation of this in the form (real, imaginary). Notes: - You may assume the following when completing the class: 1) The parameters of the constructor are never null; 2) The parameters of add, subtract, multiply, and divide will never be null; 3) The parameter of divide will never be equal to 0+0i or 00i. - You may define additional methods when you see fit. - Tests in ComplexTest.java should all pass after you've completed the class. What to do: In Complex.java [Task 4] Add the missing fields to class Complex. [Task 5] Complete the constructor as well as the methods add, subtract, multiply, divide, and asString. 4. XYRectangle(20 points) A point P in a Cartesian coordinate system can be denoted using its x-coordinate and y-coordinate as (xp,yp), and an xy-rectangle, i.e., a rectangle with its four sides in parallel or overlapping with the x - and y-axes, can be represented using its top-left vertex Pt and bottom-right vertex Pbr as Ptl,Pbr. For example, xy rectangle R1 in Figure 1 (in solid line) can be represented as P1,P2, while xy-rectangle R2 (in dotted line) can be represented as P3,P4. Given class Point as defined in XYRectangle.java, please complete class XY Rectangle so that each XY Rectangle object represents a valid xy-rectangle and supports the following operations: Figure 1. Two xy-rectangles. 1. A constructor that takes two points as arguments and initializes the newly created xyrectangle in such a way that the line segment between the two points forms a diagonal of the rectangle; You may assume that the line passing both argument points always intersects with both the x and the y axis. 2. A method toString that returns a String representation of the xy-rectangle in the form Ptt,Pbr, where a point P with coordinates Px and Py is denoted as (Px,Py). For example, given an xy-rectangle with the top-left and bottom-right vertexes at positions (2,3) and (4,1), invoking toString on the xy-rectangle will return " <(2,3),(4,1)> ". 3. A method area that takes no argument and returns the area of the xy-rectangle. 4. A method rotateClockwise that takes no argument and rotates the current xy-rectangle clockwise by 90 degrees around its top-left vertex; For example, xy-rectangle R1 in Figure 1 will be at the position of R2 after the method is invoked on R1. 5. A method move that takes two arguments deltaX and deltaY and moves the xy-rectangle horizontally by deltaX and vertically by deltaY. 6. A method contains that takes a point P as the argument and returns true if and only if the point is within or on the border of the xy-rectangle. 7. A method contains that takes an xy-rectangle R as the argument and returns true if and only if every point contained in R is also contained in the current xy-rectangle. 8. A method overlapsWith that takes an xy-rectangle R as the argument and returns true if and only if at least one point is contained in both R and this xy-rectangle. Note: 3 - You may assume that the reference-typed parameters of the constructor or methods are never
  • 3. null. - You may define additional methods when you see fit. - Tests in XYRectangleTest.java should all pass after you've completed the class. What to do: In XYRectangle.java [Task 6] Complete the constructor as well as the other methods in class XYRectangle. Given an integer value X, you need to return the base-7 representation of X as a string. In a base- 7 representation, each digit is between 0 and 6 , both inclusive, and the value of a digit is based on its position in the representation. For example, given a base-7 representation r1=(dnd3d2d1d0)7(0di6,0in), the decimal value of r1 is calculated as dn7n++d373+d272+d171+d070. What to do: In Base7.java [Task 1] Complete method convertToBase7 in class Base7 so that the method will take an int value as the argument and return the argument's String representation based on 7 . For example, when the input value is 100 , the method should return a string "202". Notes: - You may not add new methods to class Base7. - You may right-click on class Base7Test and select "Run 'Base7Test"' to execute the tests we prepared for class Base7. If any test fails, your implementation is buggy. Note, however, that since the provided tests only check a small number of input/output pairs, passing all those tests does not mean your implementation is correct.