The fourth week Lessons Learned & Experimental REPORT

  1. Write a rectangle representing a class named Rectangle. Attributes which includes a wide width, height, and color of high color, width and height are double-type, and the color is of type String. Requirements class has:

(1) using the constructor completes the initial assignment of each attribute

(2) using the get ... () and set ... () in the form of complete access and modify the properties of

(3) calculate the area of ​​providing getArea () method and the calculated circumference getLength () method

public class Rectangle {
private double height;
private double width;
private String color;
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public Rectangle(double width,double height,String color){
this.setColor(color);
this.setHeight(height);
this.setWidth(width);
}
public void getArea(){
double area=0;
area=this.height*this.width;
System.out.println("矩形的面积为"+area);
}
public String toString () { 
String recStr = "height of the rectangle:" + the this .getHeight () + "Width:" + the this .getWidth ()
 + "Color:" + the this .getColor ();
 return recStr; 
} 
/ * * 
* test function 
* @param args
 * / 
public  static  void main (String [] args) { 
the Rectangle REC = new new the Rectangle (. 3,. 4, "red" ); 
rec.getArea (); 
System.out.println (REC. toString ()); 
} 
}
  1. Unique identification (a combination of characters and numbers 11 lengths) bank account records Account have an account, user name, date of opening the account password, the current balance (six-digit number that can be used at the beginning 0). Bank of when to open a new account, the bank provides an identifier, the initial account password 123456, customers provide your name, customers can open an account when a deposit for an initial account amount, without providing an initial balance of zero. Definition of the class and ask the class provides the following methods: deposits, withdrawals, change your password, you can query separately identifies an account, name, date of opening, the current balance and other information.
    import java.util.Date;
    import java.util.Scanner;
    public class Bank{
    private String id;
    private String name;
    private Date createTime;
    private String mima;
    private int balance;
    public amount(Sring id,String name,int balance){
    }
    super();
    this.id=id;
    this.name=name;
    this.balance=balance;
    this.createTime=new Date();
    this.mima=123456;
    }
        public void deposit(int amount){
    this.balance+=amount;
    }
    public void withdraw(int amount){
    this.balance-=amount;
    }
    public Date getCreateTime()
    {
    return createTime;
    }
    public void setCreateTime(Date createTime){
    this.createTime=createTime;
    }
    public void changemima(){
    Scanner sc=new Scanner(System.in);
    System.out.println(请输入新的密码:);
    MIMA String =sc.nextString ();
     the this .mima = new new MIMA; 
    } 
    public  static  void main (String [] args) { 
    Bank A = new new Bank (1234567890, Luxi, 1000 ); 
    a.deposit ( 100 ); 
    a.withdraw ( 150 ); 
    a.changemima (); 
    a.createTime (); 
    System.out.println (account account: + a.etld ()): 
    System.out.println (account name: + a.getName ()); 
    System.out.println (account date: + a.getCreateTime ()); 
    System.out.println (account balance: + a.getAmount ()): 
    } 
    }

    Summary: This week learning the String class object and this keyword, main methods. The content is easy to understand and grasp the good. This week's test was a bit difficult, more lines of code first, then more complex, like a long time on the algorithm.

Guess you like

Origin www.cnblogs.com/zcl666/p/11548199.html