Sunteți pe pagina 1din 3

1.

) Write a program Case that: Checks that two arguments have been provided, and prints an error message if not Uses the first parameter to determine if text should be converted to upper or lo wer case Converts the text in the second parameter accordingly, and prints it to screen 2.) Write a class called Author which contains: Three private instance variables: name (String), email (String), and gender (cha r of either 'm' or 'f'); One constructor to initialize the name, email and gender with the given values; Four public getters/setters: getName(), getEmail(), setEmail(), and getGender(); Also write a test program called TestAuthor to test the constructor and public m ethods. Try changing the email of an author. Write a class Book which contains: Four private instance variables: name (String), author (of the class Author you have just created, assume that each book has one and only one author), price (double), and qtyInSto ck (int); Two constructors: public Book (String name, Author author, double price) {...} public Book (String name, Author author, double price, int qty InStock) {...} Also write a test program called TestBook to test the constructor and public met hods in the class Book.Try to print the name and email of the author from a Book instance. Introduce new methods called getA uthorName(), getAuthorEmail(), getAuthorGender() in the Book class to return the name, email and gender of the author of the book.

3.) 1. Make a class named Rectangle. It should have the following private fields which represent the position and size of a rectangle in 2D: An double named xPos An double named yPos An double named width An double named height It should have the following public methods: A default constructor that initializes xPos and yPos to zero and width and heigh t to one. A constructor that takes two double parameters which specify values for width an d height (in that order). A constructor that takes four double parameters which specify values for xPos, y Pos, width and height (in that order). void setPos(double x, double y) double getXPos() double getYPos() double getWidth() double getHeight()

double getArea() should return width*height Add a main method (public static void main(String [] args)), that Creates the A default Rectangle object. 4.) Make an abstract class named Shape to represent the concept of a shape. This class should be in a file named Shape.java. It should have the following private fields which represent the position of the shape in 2D: A double named xPos A double named yPos It should have the following public methods: A default constructor that initializes xPos and yPos to zero A constructor that takes two double parameters which specify values for xPos and yPos void setPos(double x, double y) double getXPos() double getYPos() These methods say that all shapes can do this, and this is the standard way of do ing it. It should also have the following abstract public methods: double getArea() void printShape() These abstract methods say that all shapes can do this, but there isnt a general w ay of doing it. Use inheritance to specialize Shape into Rectangle, this class should be in a fi le named Rectangle.java. This will require two private double fields to store the width and height. The f ollowing constructors should be provided: Rectangle() The default constructor, sets width = 1 and height = 1. Rectangle(double width, double height) Rectangle(double x, double y, double width, double height) This will need explic itly invoke the super-class constructor, super(x, y); You will also need to override/implement the following methods (all as per last weeks assignment): double getArea() void printShape() Create a class named TestShapes, in a file named TestShapes.java, with a main meth od that: Creates the following objects: A default Rectangle 5.) Design and implement a Java program that will do the following operations to this string Welcome! This is ICS102 Course: Convert all alphabets to capital letters and print out the result; Convert all alphabets to lower-case letters and print out the result; and Print out the length of the string. Print out the index of the word Course. 6.) Generate password for a student by taking middle letter from the first, midd le and last name of the student. The obtained letters should be concatenated along wit

h age which is multiplied by 100. 7.) A course which is described as follows: ABC 123 : Course Description. Design a Java program that will split then print the 3 components of the following cou rse description "ICS 102 : Introduction to Computing I" as shown below: Course Name: ICS Course Number: 102 Course Description: Introduction to Computing I 8.) Write a Java program that removes the 1st three occurrences of the character m (capital or small) from Im a JaVa PrOgRaMmEr string. Print the resulting string to the screen.

S-ar putea să vă placă și