Define a class to model linear equation of variables x and y

Assignment Help JAVA Programming
Reference no: EM13974093

This assignemnt is super easy if you know java. You will need is to add any fields that are required for the class to work properly and fill in definitions for the given methods. Just follow the instructions provided in the attached file. I can email you the test file afterwards.

Files to submit

SlopeInterceptLE.java

Define a class to model a linear equation of variables x and y in slope intercept form. A skeleton for this file is provided in the project pack.

SlopeInterceptLETests.java

Provides tests of the correctness of the above class.

3.1 Good old Em ex plus Bee

A linear equation is in slope intercept form if it is written

y=mx+b

where m and b are constants that do not change while x and y are variables that do change.

Define a class which models a linear equation in slope intercept form. A template is provided for you in the fileSlopeInterceptLE.java. You will need to add any fields that are required for the class to work properly and fill in definitions for the below methods.

3.2 Class Structure of SlopeInterceptLE

// A class to model linear equations of two variable (x and y) in
// slope intercept form.

public class SlopeInterceptLE {

// Public constructor that accepts values for the slope m and
// intercept b, defaults the value of x to 0.0 and sets y
// appropriately.

publicSlopeInterceptLE(double m, double b);

// Public constructor that accepts values for the slope m and
// intercept b and initial value of x and sets y appropriately.

publicSlopeInterceptLE(double m, double b, double x);

// Return the numeric value of the equation which is the numeric
// quantity that should be on both left and right sides of the equal
// sign.

public double value();

// Return the current value of x

public double getX();

// Return the current value of y

public double getY();

// Set the value of x and change y accordingly to preserve the
// equation.

public void setX(double x);

// Set the value of $y$ and change $x$ accordingly to preserve the
// equation.

public void setY(double y);

// Return a =String= version of the general form of the equation.
// The pretty version's general format should be as follows.
// y = M.MM * x + B.BB
// M.MM is the slope with 2 digits of accuracy and B.BB is the
// intercept with two digits of accuracy. Look for a method of the
// String class to assist with formatting.
// Examples:
// y = 1.23 * x + 122.41
// y = -1.23 * x + -122.41

public String toString();

}

3.3 Implementation Notes

The method

public String toString()

should return a String version of the general form of the equation. This string's general format should be

y = M.MM * x + B.BB

where M.MM is replaced with the value of m with 2 decimal digits of accuracy and similarly for B.BB being replaced by b. For example, if m=1.23,b=122.408, the appropriate string to produce is

y = 1.23 * x + 122.41

If m=-1.23,b=-122.408, the appropriate string to produce is

y = -1.23 * x + -122.41

This task is significantly easier if you examine the String.format() method and learn a few things about format strings for producing nice looking output. Format strings are used with System.out.printf() which is derived from the C language printf function. There are several places to learn about them.

3.4 Sample Session

Welcome to DrJava. Working directory is /...

>SlopeInterceptLEsi = new SlopeInterceptLE(1.0,2.0)
>si
y = 1.00 * x + 2.00
>si.toString()
y = 1.00 * x + 2.00
>si.getX()
0.0
>si.getY()
2.0
>si.value()
2.0
>si.setX(4)
>si.value()
6.0
>si.getY()
6.0
>si
y = 1.00 * x + 2.00
>si.toString()
y = 1.00 * x + 2.00
>si = new SlopeInterceptLE(0.25, 10.25, 1.0);
>si.getX()
1.0
>si.getY()
10.5
>si
y = 0.25 * x + 10.25
>si.setY(4.5)
>si.getY()
4.5
>si.getX()
-23.0
>si
y = 0.25 * x + 10.25
>si.value()
4.5
>si = new SlopeInterceptLE(-0.25, -10.25, -1.0);
>si.toString()
y = -0.25 * x + -10.25
>si = new SlopeInterceptLE(0.67512, -1.999, -1.0);
>si.toString()
y = 0.68 * x + -2.00

Reference no: EM13974093

Questions Cloud

Describe digital forensics and process management. : Consider that Data Security and Policy Assurance methods are important to the overall success of IT and Corporate data security.
What do the major career interest inventories test for : Often, one of the first tasks in career counseling is determining client interests. Instead of simply asking clients what kind of work they are interested in, career interest inventories can be hundreds of questions long. What do the major career ..
What should the order size be every time that an order : The annual demand is 250 sheets. What should the order size be every time that an order is placed to minimize total annual cost?
What is the annual ordering cost : If annual demand is 24,000 units, orders are placed every 0.5 months, and the cost to place an order is $50, what is the annual ordering cost?
Define a class to model linear equation of variables x and y : Define a class to model a linear equation of variables x and y in slope intercept form. A skeleton for this file is provided in the project pack.
Education expenses-interest on higher education : Federal Tax Question Lionel is an unmarried law student at State University Law School, a qualified educational institution. This year Lionel borrowed $24,000 from Counti Bank and paid interest of $1,440. Lionel used the loan proceeds to pay his l..
How many units of inventory must their storage area : How many units of inventory must their storage area be able to hold?
Social cognition and research design : Blended Learning: Social Cognition & Research Design- "Priming" happens when a thought, image, emotion, memory, etc. becomes salient in the mind due to some internal or external stimulus. Spreading activation triggers related concepts in the mind ..
Determine some of the privacy problems related to biometrics : Which method(s) of biometrics that would not meet with undue resistance from potential users would you recommend to a manager to replace password-based access controls?

Reviews

Write a Review

JAVA Programming Questions & Answers

  Provide a regular expression that shows the set of strings

Provide a regular expression that shows the set of strings over {a, b} thatcontain at least one b if its length is at least four.

  Concept of operator overloading

This lab is to introduce students to the concept of operator overloading as member functions of a class. This will be done in the context of creating a class that will perform four basic mathematical operations on complex numbers

  Write methods to retrieve information about a note

calculate the frequency, use the formula 440 x 2^(n/12) where n is the note number - implement a class that will be used to hold information about a musical note.

  Write java statements to create a collection of integers

Write Java statements to create a collection of integers, and to initialize each element of the collection to -1. Then, using for each statement to print the value of each element.

  It inherits the functionality of super class

It inherits the functionality of super class Package and contains an additional data member representing an additional fee per ounce charged for overnight-delivery service.

  Exceptions-memory management and concurrency

This question asks you to compare properties of exceptions in C++ and Java.

  Create two separate java codes resulting in the same output

I need to create two separate Java codes resulting in the same output (one using Apache Commons library and one using the standard Java methods). The program should count all people with the same last name and then change the last name to Doe.

  Write a program that allows a user to enter a line of text

write a program that allows a user to enter a line of text counts number of words and number of vowels in the sentence

  What is object-oriented programming

What is object-oriented programming? What are the differences between a class and an object

  Evaluate the rtas resource requirements

Design and implement a set of classes and interfaces and use them to evaluate the RTA's resource requirements.

  Swing gui java application running with eclipse on windows x

To test the program just start MoneyMain to see if you click the icons for the detail screens and click Report to view the two reports.

  Write thejava code for a program

Write theJava code for a program that reads the weight of a piece of luggage and print the proper message, depending on the weight, as per the table below.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd