Blog

Coursehelp
April 16, 2019
QUESTION : No Comments

(Solved) : Work Educational Software Company Developing Suite Simple Physics Simulations Code Pendulu Q30131121 . . .

You work for an educational software company that is developing a suite of simple Physics simulations. The code in pendulum.zip is the beginning of a suite intended to permit the creation of a series of different types of pendulum simulation. You previously identified a code smell (trivial layer) in the AbstractEarthPendulum class, but figured it was mostly harmless. Now your team wants to be able to dynamically set which planet a pendulum is on during an interactive simulation, and to allow different kinds of gravity models that are impossible to represent with a single constant (e.g., latitude models) 1. Run the main/test routine to see the expected behavior of the code. 2. Apply the refactoring approach Collapse Hierarchy to reduce the hierarchy levels by one Ensure that the main/test routine still works as expected. Make a copy of all the code in a folder called RefactoringStepl 3. Next, use the Strategy design pattern (shown below) to replace the field g with a reference to a strategy object (as outlined below). This will allow different kinds of gravity models to be associated with a Pendulum instance dynamically. Context interface Strategy ConcreteStrategyA ConcreteStrategyB te0 Name the strategy interface GravityModel, with a single method public double getGravitationalField Assume that objects implementing GravityModel will be initialized with all state required to produce the gravitational field value under their specific model, and that this occurs before being assigned to a pendulum. In other words, the pendulums will just use the model assigned to it via the GravityModel interface. Adjust the pendulum constructors so that a GravityModel is assigned on initialization, and add a new method that will allow the GravityModel to be changed dynamically Define one concrete strategy called GravityConstant. This class simply receives a constant value for g in its constructor. 4. Run the main/test routine to ensure that the functionality hasnt changed. Copy all the code into a folder called RefactoringStep2

AbstractEarthPendulum:

AbstractPendulumPendulumRunner:

RegularPendulum:

SimplePendulum:

You work for an educational software company that is developing a suite of simple Physics simulations. The code in pendulum.zip is the beginning of a suite intended to permit the creation of a series of different types of pendulum simulation. You previously identified a code smell (trivial layer”) in the AbstractEarthPendulum class, but figured it was mostly harmless. Now your team wants to be able to dynamically set which planet a pendulum is on during an interactive simulation, and to allow different kinds of gravity models that are impossible to represent with a single constant (e.g., latitude models) 1. Run the main/test routine to see the expected behavior of the code. 2. Apply the refactoring approach “Collapse Hierarchy” to reduce the hierarchy levels by one Ensure that the main/test routine still works as expected. Make a copy of all the code in a folder called “RefactoringStepl” 3. Next, use the Strategy design pattern (shown below) to replace the field g with a reference to a strategy object (as outlined below). This will allow different kinds of gravity models to be associated with a Pendulum instance dynamically. Context interface Strategy ConcreteStrategyA ConcreteStrategyB te0 Name the strategy interface GravityModel, with a single method public double getGravitationalField Assume that objects implementing GravityModel will be initialized with all state required to produce the gravitational field value under their specific model, and that this occurs before being assigned to a pendulum. In other words, the pendulums will just use the model assigned to it via the GravityModel interface. Adjust the pendulum constructors so that a GravityModel is assigned on initialization, and add a new method that will allow the GravityModel to be changed dynamically Define one concrete strategy called GravityConstant. This class simply receives a constant value for g in its constructor. 4. Run the main/test routine to ensure that the functionality hasn’t changed. Copy all the code into a folder called “RefactoringStep2” Show transcribed image text

Expert Answer


. . .

OR
OR

Have a Comment on this Question?

Questions viewed by other students


  • QUESTION : (Solved) : Code Must C Assignment Lab Next Week Use Malloc Function Allocate Space Store String Inste Q32768991 . . .

    CODE MUST BE IN C
    For the assignment and the lab next week use malloc function toallocate space (to store the string)
    instead of creating fixed size character array. malloc functionallows user to allocate memory (instead of
    compiler doing it by default) and this gives more control to theuser and efficient allocation of the
    memory space.
    Example
    int *ptr
    ptr=malloc(sizeof(int)*10);

    In the example above integer pointer ptr is allocated a space of 10blocks this is same as creating as array
    int ptr[10] but here malloc function is used which allows the userto decide how much memory is
    required.

    Another example
    char* string;
    string = malloc(sizeof(char) * 15); //has room for 15characters
    Not even declaring the array is required, everything must bepointers.
    Implement following functions for the pre-lab.

    Description:
    Implement following functions for the prelab assignment. These willbe on the lab!
    int main(): Declares a new string (char pointer),then calls getString and prints the string with
    the size out and frees the malloced memory from the string.
    int getString(char *): This function takes in anuninitialized string, prompts the user for the size
    of the string (error checking to make sure size is between 1-20),and then prompts and scans in
    the actual string from the user and converts it to upper case.Returns the size of the string, and
    the string should be valid when the function terminates (hint: ifthe user enters in a string length
    less than the size but not empty, adjust the size. UsinggetSafeString from hw2 might be a good
    idea).
    int checkString(char*, int): Takes in the stringand the size, and checks to see if the string is
    valid. Valid string should contain only alphabetical characters ‘A’through ‘Z’, not including the null
    terminator. Return 1 if string is valid, otherwise 0 if string isinvalid. (hint: try using the acsii values
    instead of checking for specific characters)

    Sample output:
    Enter the size of the string: 109
    Please enter again: -1
    Please enter again: 7
    Please enter the string: 0
    Please enter a valid string: stringstringstring
    The string entered is longer than the allowed size
    Please enter a valid string: 89994
    Please enter a valid string: 5tring5
    Please enter a valid string: String
    You entered: STRING which is size 6
    ./a.out
    Enter the size of the string: 0
    Please enter again: 18
    Please enter the string: &#^I$@OI$
    Please enter a valid string: baseball bat
    Please enter a valid string: baseball
    You entered: BASEBALL which is size 8

    Note:
    1. Don’t use any global variables, though a global constant for themaxsize of string (20) is ok.
    2. Use only pointer notation and pointer arithmetic to implementthe assignment.
    3. Use the relevant library function, especially from ctype.h
    Library function you’ll need to free the string at the end:
    https://www.tutorialspoint.com/c_standard_library/c_function_free.htm
    Remember that the string is passed by reference to the function:changing its contents in the function
    changes it in main as well, including mallocing space for it.
    Ascii table: http://www.asciitable.com/

    Expert Answer


    . . .


    view full answer
  • QUESTION : (Solved) : Code Must Java Programming Assume Gallon Paint Covers 350 Square Feet Wall Space Create Ap Q30914697 . . .

    Code must be in Java Programming

    Assume that a gallon of paint covers about 350 squarefeet of wall space. Create an application with a main()method that prompts the user for the length, width, and height of arectangular room. Pass these three values to a method that does thefollowing:

    Calculates the wall area for a room

    Passes the calculated wall area to another method thatcalculates and returns the number of gallons of paint needed

    Displays the number of gallons needed

    Computes the price based on a paint price of $32 pergallon, assuming that the painter can buy any fraction ofa gallon of paint at the same price as a whole gallon

    Returns the price to the main() method

    The main() method displays the final price. For example:

    You will need 2.0 gallonsThe price to paint the room is $64.0

    Expert Answer


    . . .


    view full answer
  • QUESTION : (Solved) : Code Must C Week 6 Lab Exercise Lab Ll Start Work Inheritance C Step 1 Clone Git Reposito Q34834228 . . .

    //CODE MUST BE IN C++

    Week 6 Lab Exercise
    ===================

    In this lab, you’ll start to work with inheritance in C++.

    ## Step 1: Clone the git repository for this lab

    We’re going to use git and GitHub Classroom again for this lab.Just like you did for the previous lab exercises, use git clone todownload your repository onto your development machine using theclone URL from your repo on GitHub:
    “`
    git clone REPO_URL
    “`

    ## Step 2: Implement a generic `Shape` class

    We’re going to work with shapes in this lab exercise. We’llcreate several classes to represent different shapes, some of themusing inheritance. The first class we’ll write is one to representa generic shape with a name and a color.

    Create two new files, `shape.hpp` and `shape.cpp`, and in them,define a `Shape` class. Here’s the start of a class definition youshould use:

    “`c++
    class Shape {
    private:
    std::string name;
    s td::string color;
    public:

    };
    “`

    You class should also have constructors, accessors, andmutators, as appropriate. In addition, your class should have an`area()` method for computing the shape’s area. For this generic`Shape` class, the `area()` method can simply return 0, since wearen’t actually defining the shape itself.

    In addition to your files `shape.hpp` and `shape.cpp`, create anew file `application.cpp`. In this file, write a simple `main()`function that instantiates some `Shape` objects and prints outtheir information. In addition, write a `Makefile` to specifycompilation of your program. Make sure you compile your `Shape`class into an object file first, separately from the compilation ofyour application, and then use that object file when you’recompiling your application.

    Once you have this all working, commit your `shape.hpp`,`shape.cpp`, `application.cpp`, and `Makefile` into your gitrepository, and push them back to your remote repo on GitHub.

    ## Step 3: Implement `Rectangle` and `Circle` classes

    Create new files `rectangle.hpp`, `rectangle.cpp`, `circle.hpp`,and `circle.cpp`, and in them, implement a `Rectangle` class and a`Circle` class. Both of these classes should be derived from your`Shape` class. The `Rectangle` class should have a `width` and a`height`, and the `Circle` class should have a `radius`. Here arethe beginnings of definitions for these classes:

    “`c++
    class Rectangle : public Shape {
    private:
    float width;
    float height;
    public:

    };

    class Circle : public Shape {
    private:
    float radius;
    public:

    };
    “`

    Both of these classes should have constructors, accessors, andmutators, as needed, and each one should override the `Shape`class’s `area()` method to compute areas that are appropriate forrectangles and circles.

    Add some code to your application to instantiate and print outsome `Rectangle` and `Circle` objects, and add rules to your`Makefile` to compile each of your new classes into separate objectfiles, which you should then use when compiling yourapplication.

    Once you have this all working, add your new files to your gitrepository, commit all of your changes, and push them to yourremote repo on GitHub.

    ## Step 4: Implement a Square class

    Now, create new files `square.hpp` and `square.cpp`, and inthem, implement a `Square` class that derives from your `Rectangle`class. Your `Square` class *should not* contain any new datamembers, nor may you change any members of the `Rectangle` class to`protected` or `public` access. Instead, you should figure out howto implement a public interface for your `Square` class byappropriately using the `width` and `height` of your Rectangleclass via its public interface (i.e. via the `Rectangle` class’sconstructors, accessors, and mutators). Specifically, the publicinterface to your `Square` class should use the public interface ofyour `Rectangle` class while enforcing the constraint that asquare’s width and height are equal.

    Here’s the start of a definition for your `Square` class, withno new data members:

    “`c++
    class Square : public Rectangle {
    public:

    };
    “`

    Once your `Square` class is written, add some lines to yourapplication to instantiate and print out some `Square` objects, andadd a `Makefile` rule to compile your class into an object filethat’s used in the compilation of your application. Make sure toadd your new files to your git repo, commit all of your changes,and push them to your remote repo on GitHub.

    Expert Answer


    . . .


    view full answer
  • QUESTION : (Solved) : Code Needs Php Format Need Adderphp Home Page Answer Submitted Goes Adder2php Continue Pro Q32083100 . . .

    This code needs to be in php format. I need Adder.php to be thehome page but when the answer is submitted it goes to Adder2.phpand then will continue to the process from Adder2.php. Below is thecode and below that is how it should look.

    Adder.php

    ____________________________________________________________

    <html>

    <head>

    <title>Math Adder</title>

    </head>

    <body>

    <h3> Addition Quizer </h3>

    <form action=”Adder2.php” method=”get”>

    <?php

    $n1 = rand(0,9);

    $n2 = rand(0,9);

    ?>

    <?php echo ($n1) ?> + <?php echo ($n2) ?> =

    <input type “text” name=”answer” size=”3″>

    <input type=”hidden” name=”n1″ value= “<?php echo ($n1);?>” >

    <input type=”hidden” name=”n2″ value= “<?php echo ($n2);?>” >

    <p><input type=”submit” value=”Submit”/></p>

    </form>

    </body>

    </html>

    _____________________________________________________

    <html>

    <head>

    <title>Math Adder 2</title>

    </head>

    <body>

    <h3> Addition Quizer </h3>

    <?php $n1 = (int)$_GET[‘n1’];

    echo $n1;

    ?>

    <br>

    <form action=”Adder2.php” method=”get”>

    <?php

    $n1 = rand(0,9);

    $n2 = rand(0,9);

    ?>

    <?php echo ($n1) ?> + <?php echo ($n2) ?> =

    <input type “text” name=”answer” size=”3″>

    <input type=”hidden” name=”n1″ value= “<?php echo ($n1);?>” >

    <input type=”hidden” name=”n2″ value= “<?php echo ($n2);?>” >

    <p><input type=”submit” value=”Submit”/></p>

    </form>

    </body>

    </html>

    Adder.php Addition Quizzer Is that right? Adder2.php Addition Quizzer 1+9-0 ??.. Sorry, the answer is 10. Okay, now try again... 3+4- Is that right?

    Adder.php Addition Quizzer Is that right? Adder2.php Addition Quizzer 1+9-0 ??.. Sorry, the answer is 10. Okay, now try again… 3+4- Is that right? Show transcribed image text

    Expert Answer


    . . .


    view full answer