The fourth week of work pay

The fourth weekly summary reports and test
fourth week study concluded
1. Understand the modified static requirements
2. Learn the definition of property, how to construct call a function, method of use and
title 3. bank accounts so hard ah, understood for a long time barely write the code, the code is displayed correctly, but can not run, so the second did not run shot

Experiment two Java Simple object
purpose of the experiment
is defined master class, familiar with the role attribute, constructors, methods, and control with the class as a type declaration variables and methods return values;
difference understood classes and objects, control using the constructor familiar reference methods and properties of the object instance by name;
understand static modification on pay class, class member variables and class methods.

Test report
1. Write a class called Rectangle rectangle representing. 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) 提供计算面积的getArea()方法和计算周长的getLength()方法
package test2;
class Rectangle {
private double height;
private double width;
private String color;
public Rectangle(){
}
public Rectangle(double width,double height,String color){
this.setColor(color);
this.setHeight(height);
this.setWidth(width);
}
public void setHeight(double height) {
this.height = height;
}
public void setWidth(double width) {
this.width = width;
}
public void setColor(String color) {
this.color = color;
}
public double getHeight() {
return height;
}
public double getWidth() {
return width;
}
public String getColor() {
return color;
}
public double getArea(){
double area;
area=this.height*this.width;
return area;
}
public double getLength(){
double length;
length=width+height+width+height;
return length;
}
};
public class Demo1 {
public static void main(String args[]) {
Rectangle rec=null;
rec=new Rectangle(3.0f,4.0f, "红色");
System.out.println(rec.getArea());
System.out.println(rec.getLength());
System.out.println("长:"+rec.getHeight());
System.out.println ( "Width:" + rec.getWidth ());
}
}
run shot:

2.银行账户
import java.util.Scanner;
class Account{
private String id;
private String name;
private int time,password;
private double money;
public Account(){
}
public Account(String id,String name,int time,int password,double money){
this.setId(id);
this.setName(name);
this.setTime(time);
this.setPassword(password);
this.setMoney(money);
}
public void setId(String s){
id=s;
}
public void setName(String n){
name=n;
}
public void setTime(int m){
time=m;
}
public void setPassword(int e){
password=e;
}
public void setMoney(double c){
money=c;
}
public String getId(){
return id;
}
public String getName(){
return name;
}
public int getTime(){
return time;
}
public int getPassword(){
return password;
}
public double getMoney(){
return money;
}
public void showup(){
System.out.println("账户名:"+id);
System.out.println("姓名:"+name);
System.out.println("开户时间:"+time);
System.out.println("账户密码:"+password);
System.out.println("账户余额:"+money);
}
public void qukuan(){
while(true){
SC = new new Scanner Scanner (the System.in);
System.out.println ( "Enter password:");
int = sc.nextInt Pass ();
IF (Pass == password) {
System.out.println ( "withdrawal amount: ");
int sc.nextInt = sUM ();
IF (sUM <= Money) {
Money = Money-sUM;
System.out.println (" balance: "Money +);
}
the else {
System.out.println ( "the balance is insufficient, the amount of re-enter");
}
BREAK;
}
the else
{
System.out.println ( "wrong password, to re-enter");
}
}
}
public void cunqian (int balance) {
Money Money + = balance;
the System .out.println ( "deposit amount:" + balance);
System.out.println ( "balance:" + money);
}
public static void main(String agrs[]){
Account acc = new Account ( "VennieJ7618 ", " Wen Cleveland", 20000101,123456,0);
Scanner sc = new new Scanner (System.in);
System.out.println ( "You need the kind of service:");
System.out.println ( "1: basic information account");
System.out.println ( "2: withdrawal");
System.out.println ( ". 3: deposit");
System.out.println ( ". 4: password services ");
System.out.println (" 5: exit ");
int G = sc.nextInt ();

Switch (G) {
Case. 1:
System.out.println ( "Account Information Basic");
acc.showup ();
Case 2:
System.out.println ( "withdrawal");
acc.qukuan ();
Case. 3:
System.out.println ( "deposit");
acc.cunqian (0);
Case. 4:
Case. 5:
System.exit (0);
BREAK;
}
}
}

Run shot:

Guess you like

Origin www.cnblogs.com/Vennien/p/11574220.html