Program 1:**Name it: A bicycle.**Requirements:Construct a class named bicycle and take a trip around your house,Instructions:Based on the description above create the following Java files.An interface...

1 answer below »




Program 1:**Name it: A bicycle.**Requirements:
Construct a class named bicycle and take a trip around your house,

Instructions:

  • Based on the description above create the following Java files.

  • An interface named bicycle as described in the section:

  • Add a new method for the interface bicycle: ring the bell with a parameter indicating how many time.

  • Pick a bicycle brand and create a new class of bicycles for that brand, as described in the sectionsWhat is an interface?andWhat is a Class?

  • For the new method implementation, write in the console "Clang! Clang!..." for how many times the parameter indicates.

  • Create another class, with a main method, in which you will take a trip aroound your house, changing your bicycle attributes, starting and ending from a complete stop, and ringing the bell once at start and twice at the end. Use as inspiration the method in

  • Your trip must have at least 5 different parts in which you change your bicycle state and print its state (starting and ending from a rest state).

  • Make sure the program runs, screenshot the output without showing the username/ or change the username to reemghousheh




Program 2:name it: **A mountain bicycle**





Instructions:



  • continue the previous program:" a bicycle"

  • Asubclasss of you bicycle class for a mountain bicycle, as described in the section:Classes

  • Your brand comes with a water bottle (both the generic and mountain type). Add a new field that will keep the percentage of water remaining in the bottle (1 full, 0 emptty, 0.5 half empty), as described in the section:Declaring member variables.The water bottle is emptty by default.

  • Declare a method to completely fill the water bottle. Declare a method to completely drink the water. No parameters needed. See:Defining methods.

  • Declare a method that will specify how much to fill the water bottle, as a percentage. If the bottle has already that quantity, do nothing. The method must have the same name as above. A parameter is needed.

  • Declare a method that will specify how much to drink from the water as a percentage. The method must have the same name as above. A parameter is needed.

  • Create a new constructor that will specify the initial cadence, gear and water level. See:Providing Constructors for Your Classes

  • Create another class, with a main method, in which you will take a trip aroound your house in your mountain bicycle, changing your bicycle attributes, starting and ending from a complete stop, and ringing the bell twice at start and once at the end. You must start with 3/4 filled water bottle, and dring some water once.

  • Your trip must have at least 5 different parts in which you change your bicycle state and print its state (starting and ending from a rest state).

  • make sure the program runs, share the 5 java files, and send a screenshot of the execution of the program without showing the /username or change the username to reemghousheh




Program 3: name it: **Figures**




nstructions:



  • Based on the description above, create a new program containing:





Program 4:name it: **Figures and Bicycles**




Requirements:
Construct a class named bicycle and take a trip around your house,









Instructions:



  • Based on the description above create the following Java files.

  • Modify the Figures program as described:

    • In constructors, use for parameters the same names as the fields, and use this to access the fields.

    • Make all fields private. Create getter methods to return the values of the fields. Update the main method as needed.

    • For point and rectangle classes create a class variable to keep how many objects were instantiated. Create a gettter to return the number. In the main method show the value after each new element is created.



  • Modify the Bicycle program as described:


    • In constructors, use for parameters the same names as the fields, and use this to access the fields.

    • Make all fields private. Create getter methods to return the values of the fields. Update the main method as needed.

    • For the generic and mountain bicycle classes create a class variable to keep how many objects were instantiated. Create a gettter to return the number. In the main method show the value after each new element is created.

    • Submit the java files

    • screenshot the execution of the program without showing the /username





Program 5: Name it: **Deck of Cards**




Requirements:
Start creating a program that will play Poker with the computer,









Instructions:



  • Create an enum type for the suits keeping a name, a short name, color and a rank (clubs, c, black, 4), (diamonds, d, red, 3), (hearts, h, red, 2) and (spades, s, black, 1). Use a boolean for color.

  • Create an enum type for the values keeping a short name, a long name and a rank, like (2, 2, 13), (3, 3, 12), ...(10, 10, 5), (J, jack, 4), (Q, queen, 3), (K, king, 2), (A, ace, 1)

  • Create a card class that will keep the suit and value of the card. It is an immutable class, not allowing its values to change.


    • Two fields, one for suit and one for value of the above enum types. They must be private and final.

    • One constructor specifying the suit and value

    • Getters for each field

    • A toString method that will return the card in the format: SHORT_NAME_FOR_VALUE SHORT_NAME_FOR_SUIT, e.g. As is an ace of spades. 2d is a two of diamonds.

    • Create a method isBetter that will compare the current card is another provided card and return true if it is better (two identical cards are not better). A card is better if the rank of the suir is bettter. If they have tthe suir, than the rank of the value. The best rank is 1.

    • Create a deck of cards class keeping a private array of 52 cards. Implement the following:

      • A constructor creating the deck in a predefined order.

      • A shuffle method that will randomly rearrange the deck.

      • A toString method that will print the entire deck, separating the cards by space.



    • Create a hand class that will keep 5 cards.

      • A constructor creating the hand based on an array of cards received.

      • A toString metthod tthat will print the hand.



    • Modify the deck of cards to deal a hand:


      • Create a method dealHand that will return the next hand (you must keep an index of the next card to deal). Returns null if no more hands to deal.

      • Create a Game class with a main method that will:

        • Start the program output with a printed line containing the name of the program and the author (e.g. Hello Java by Mihai Boicu).

        • Create a deck - print it

        • Shuffle the deck - print it

        • Deal a hand - print it

        • Deal a second hand - print it

        • Dear a third hand - print it




        • Add reemghousheh as the author of each class.

        • Be sure you include comments (JavaDoc and inline) as required.







Program 6: name it: **Rational numbers**



Requirements:
Create a representation of rational numbers as fractions of integers.









instructions:



  • Based on the description above create the following Java files.

  • The program creates a representation for rational numbers as fractions of int-s having the format: n/d where n and d are of type int and d is not zero.

  • An interface named rational number having the following methods:

    • get numerator - no parameters, return n

    • get denominator - no parameters, return d

    • get value - compute the value as a double (n/d)

    • add - another rational - returns a rational

    • add - a double - retturns a double

    • subtract - two forms as add above

    • multiply - two forms as above

    • divide - two forms as above

    • simplify - returns another rational, equal with the original, but with n and d simplified and d>0

    • opposite - returns the opposite number

    • reciprocal - return the reciprocal number



  • Add a new class RationalAsFraction implementing the above interface

    • stores two fields: n and d

    • has a static method to compute the greatest common divisor (gcd)



  • Add a test class TestRational


    • Define the rationals r1..r4 and initialize them with 1/2, -3/9, 10/12 and 1

    • Compute sum=r1+r2 and diff=r4-r3

    • Simplify both results

    • Check if they are equal, using equals and comparing their numerators and denominators. What do you observe?

    • Print all the rational numbers and partial results

    • submit the 3 java files

    • screenshot the execution of the program without showing the /username or change the username to reemghousheh





program 7:name it: **Simplified Rational**



Requirements:
Create a representation of simplified rational numbers continuing the previous activity.









Instructions:



  • Based on the description above create the following Java files.

  • The program extends the representation for rational numbers as fractions with simplified rational numbers

  • A new interface named simplified rational number extending the rational number interface

    • Provide a default implementation of the simplify method - returning itself



  • Add a new class simplified rational as fraction implementing the above interface

    • Overwrite the implementation of methods that have a simplified implementation (simplify is already done by the interface?)



  • Implement equals and hashCode for both classes

    • For hashCode xor (^) the hash code of simplified nominator and denominator.



  • Add a test class TestSimplifiedRational


    • Define the simplified rationals r1..r4 and initialize them with 1/2, -3/9, 10/12 and 1

    • Compute sum=r1+r2 and diff=r4-r3

    • Simplify both results

    • Check if they are equal, using equals and comparing their numerators and denominators. What do you observe?

    • Print all the rational numbers and partial results.



    • Submit:




      • The Java source code files - 5 (.java)

      • One or more pictures (as JPG) or one PDF file with the pictures showing the execution of the program without shwoing the /username or change the username to reemghousheh






Program 8:name it: **Comparable data**




Requirements:
Create a representation of simplified rational numbers continuing the previous activity.









Instructions:



  • Based on the description above modify/create the following Java files.

  • The program extends the representation for rational numbers as fractions as described

  • For the rational number interface, extend the Comparable

  • For the rational number as fraction class implement compare to method

  • For the simplified rational number as fraction - think if you can have a simplified representation or not.

    • minator.



  • Add a test class TestSimplifiedRational


    • Define the simplified rationals r1..r4 and initialize them with 1/2, -3/9, 10/12 and 1

    • Compute sum=r1+r2 and diff=r4-r3

    • Simplify both results

    • Check if they are equal, using equals and comparing their numerators and denominators. What do you observe?

    • Compare r1 with r2, r3 and r4.

    • Print all the rational numbers and partial results.



    • Submit:




      • The Java source code files - 5 (.java)

      • One or more pictures (as JPG) or one PDF file with the pictures showing the execution of the program without showing the /username































































Answered Same DayOct 13, 2022

Answer To: Program 1:**Name it: A bicycle.**Requirements:Construct a class named bicycle and take a trip around...

Aditi answered on Oct 14 2022
54 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here