Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Writing Classes Exercises

  1. #1
    Junior Member
    Join Date
    May 2014
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Writing Classes Exercises

    Hello guys,

    I hop you are all well,

    guys I need help in this exercises. Could any one help me with and understand it?

    Write the Java programs according to the following specifications

    Part 1.1 Develop an interface Colourful to the following specifications:
    It includes one public method assignMyColour( String colour). When this method is
    implemented, it should set the colour of its object by the given value as its argument.

    Part 1.2 Develop a public class Point to the following specifications:
    1) The class has two private instance variables: int x and y.
    2) The class has a multi-argument constructor that sets the values of its instance
    variables to the given values.
    3) The class has a zero-argument constructor that sets the values of its instance variables
    to their default values. It should invoke the multi-argument constructor.
    4) The class has the getter and setter methods for the instance variables.

    Part 1.3 Develop a public abstract class Shape to the following specifications:
    1) The class implements the Colourful interface.
    2) The class has one private instance variable: Point p1.
    3) The class has a one-argument constructor that creates and sets the value of its
    instance variable to the given value of p1.
    4) The class has to override the Objectís toString() method in order to return a string with
    representation of the Point instance variables as:
    (x, y)
    5) Implement any methods that are needed.

    Part 1.4 Develop a public class Oval to the following specifications:
    1) The class inherits the Shape class.
    2) The class has the following private instance variables: width and height as an integer,
    myColour as string, counterO as an integer which keeps one copy for all instantiated
    objects of oval and counts their numbers.
    3) The class has a multi-argument constructor that creates and sets the values of its
    instance variables to the given values. It should invoke its super-class constructor.
    Oval (Point p, int width, int height, String colourName)
    4) The class has the getter and the setter methods for the private instance variables width,
    height, counterO.
    5) The class has to override the Objectís toString() method in order to return a string
    representation of the Oval instance variables as:
    The oval in (10 , 10) its width is 80 its height is 90 its colour is Red
    6) Implement any methods that are needed.

    Part 1.5 Develop a public class Rectangle to the following specifications:
    1) The class inherits the Shape class.
    2) The class has the following private instance variables: Point p2, myColour as string,
    counterR as an integer which keeps one copy for all instantiated objects of rectangle and
    counts their numbers.
    M257 TMA Spring 13-14 Page 4
    3) The class has a multi-argument constructor that creates and sets the values of its
    instance variables to the given values. It should invoke its super-class constructor.
    Rectangle (Point p1, Point p2, String colourName)
    4) The class has the getter and the setter methods for the private instance variable
    counterR.
    5) The class has to override the Objectís toString() method in order to return a string
    representation of the Rectangle instance variables as:
    The Rectangle starts at (0 , 0) and ends at (100 , 100) its colour is green
    7) Implement any methods that are needed.

    Part 1.6 Develop a public class MyShapes to the following specifications:
    1) The class has one private instance variable HashMap<String, Shape> myShapes,
    which represents the collection of shapes from class Shape and its subclasses.
    2) The class has a zero-argument constructor that creates its instance variable
    myShapes.
    3) The class has the method void addOval( String type, Oval oval). It creates the key of
    the Oval object by concatenating its type by its counter, and then it adds the Oval object
    into the myShapes collection.
    4) The class has the method void addRectangle( String type, Rectangle rectangle). It
    creates the key of the Rectangle object by concatenating its type by its counter, and then
    it adds the Rectangle object into the myShapes collection.
    5) The class has the method String showShapes(), which returns a string representation
    for all shapes in the collection or a message ďThere are no shapes in the collectionĒ if
    the collection is empty.
    6) Implement any methods that are needed.

    Part 1.7 Develop a public class TestMain to the following specifications:
    1) The class has a static main method.
    2) The class instantiate the MyShapes class.
    3) The class has to fill myShapes instance object by reading the values from the TXT file
    ("C:/Spring13-14Shapes.txt"), which is provided in the TMA folder.
    4) It should check whether the type of the shape is Oval or Rectangle and then it should use
    the corresponding methods that are needed to add the objects into the myShapes object.
    5) The data includes the following
    For Oval: the type of the object followed by the Point P1ís coordinates width, height and
    colour.
    For Rectangle: the type of the object followed by Points P1 and P2 coordinates, and its
    colour.
    6) Finally, it should display on the screen the shapes in myShapes and the number of
    Rectangle and Oval objects.
    7) Implement any methods that are needed.


    Thank you all,


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,434
    Thanks
    49
    Thanked 2,216 Times in 2,189 Posts

    Default Re: Writing Classes Exercises

    What have you tried?

    Do you have any specific questions?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    May 2014
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Writing Classes Exercises

    this exercise, one part is related to the previous one.
    I have answered the first three parts, and the rest are not clear for me.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,434
    Thanks
    49
    Thanked 2,216 Times in 2,189 Posts

    Default Re: Writing Classes Exercises

    the rest are not clear
    Do you have any specific questions about "the rest"?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Need some exercises to practice ?
    By Nerc in forum Java Theory & Questions
    Replies: 1
    Last Post: May 1st, 2014, 07:58 AM
  2. Replies: 1
    Last Post: April 6th, 2014, 02:49 AM
  3. Programming exercises
    By leo.trim in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 19th, 2013, 05:12 PM
  4. Arrays exercises and tasks
    By 1click in forum Java Code Snippets and Tutorials
    Replies: 3
    Last Post: October 20th, 2013, 05:29 PM
  5. Exercises - CRITICAL HELP NEEDED
    By Maximillian in forum Java Theory & Questions
    Replies: 5
    Last Post: November 17th, 2009, 04:55 PM