Java share some basic exercises

Inheritance practice
 
 1. Define class Phone, requirements are as follows:
  It contains a null parameter, full-argument constructor and the member variables
   Brand brand (String type)
        Generate all the member variables set / get method
        The method defined: void playMusic (String s)
 2. The definition of classes IPhone, requirements are as follows:
  Phone derived class
   Constructors include: full and empty argument constructor argument constructor method
   Override methods:
   void playMusic (String s), requirements: Output print "XXX phones are playing a song: s"
   PS: XXX is the Phone class brand attribute value, s is the incoming parameters
 3. Define the test class TestDemo, the main method implements the following features:
  IPhone object is created and initialized a phone, a phone call playMusic (String s) method, passing the parameter "Chrysanthemum Flower Bed"
  Print out the following statement:
   Huawei phones are playing a song: Chrysanthemum Flower Bed
 
Collection exercise

First, the known number of storage arrays QQ number, QQ number up to . 11 bit , shortest . 5 bit String [] strs = { "12345 ", "67891", "12347809933", "98765432102", "67891", " 12347809933 "} .

Inside the array of all qq numbers are stored in the LinkedList in , the list to delete duplicate elements , will list all the elements are iterative and Enhanced for printed loop.

 

Collection set of exercises

A, generating 10 th 1-100 random numbers and placed in an array, the array is greater than equal to 10 numbers into a list set, and printed to the console.

Object-Oriented

1. Define the phone category Phone

        Behavior: call (call), text messaging (sendMessage)

    2. Define Interface IPlay

        Behavior: playing games (play)

    3. Define the old phone class (OldPhone) class inherits phone

        Behavior: inherit the behavior of the parent class

    4. Define a new phone class (NewPhone) inherited phone class implements an interface IPlay

        Behavior: Behavior inherit the parent class, override the method to play the game

    The defined test class (the Test), creates an object and call the method, the following operating results:        

        Old cell phone

        Old phones to send information

        New cell phone

        The new phones to send information

        New cell phone to play games

Map collection

There are two arrays, the first array reads: [Heilongjiang Province , Zhejiang , Jiangxi , Guangdong , Fujian Province ] , a second array is: [Harbin , Hangzhou , Nanchang , Guangzhou , Fuzhou ] , the first array elements as the key, the second array element as the value stored in the Map collection. Heilongjiang Province as { = Harbin Zhejiang = Hangzhou , ...}

 

Byte write data output stream

Description :

Receiving a user input from the console cycle student information, the input format: school - student names

Student information will be saved to D disc following stu.txt file, a student information occupy a row of data.

When the user enters end stop input.

answer

Procedure :

1.  Use Scanner class for keyboard input data

2. Create a byte input stream object associated object

3. Using student data endless loop stop receiving user input

4. The student receives user-entered data

5.  if the content of the input is determined End , a loop is terminated, stop input. Otherwise write data to a file.

 

Guess you like

Origin www.cnblogs.com/cjhome/p/11402715.html