Summary of the third week of Java basic learning

Posted by arbab on Sat, 22 Feb 2020 08:33:36 +0100

1, Summary of knowledge points

1. Object oriented




2. modifiers

1. Write a worker class and create multiple worker objects.

1. Add three private properties to the worker class:
1). Sting type name, indicating the name of the person.
2). int type age, indicating the age of the person.
3). double type salary, indicating the salary of a person.
2. Add two construction methods to the worker class:
1) . open nonparametric construction method
2) . accept the construction method of three parameters, which are string, int and double types.
3. Add two work methods to the worker class:
1) . nonparametric construction method
2) . with integer parameter construction method, indicating how many hours people work)
2. Create an Address class, described as follows:
1. This class has two private properties:
1) . address of type string, indicating the address.
2) . zipCode of type string, indicating zip code.
2. This class has two construction methods:
1) . nonparametric construction method
2) . method with two parameters
3. The worker class adds an attribute addr, which is the Address class
Requirements: create a Worker object with the name of "zhangsan", the year of 25, the salary of 2500, the home address of "No.1 Qinghua garden, Haidian District, Beijing", and the postcode of 100084

package com.qf.day15.t1.question;

class Worker{
	
	private String name;
	private int age;
	private double salary;
	private Address addr;
	
	public Worker(){
		
	}
	
	public Worker(String name,int age,double salary,Address addr){
		this.name = name;
		this.age = age;
		this.salary = salary;
		this.addr = addr;
	}
	
	public void Work(){
		
	}
	
	public void Work(int hour){
		
	}
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public double getSalary() {
		return salary;
	}

	public void setSalary(double salary) {
		this.salary = salary;
	}

	public Address getAddr() {
		return addr;
	}

	public void setAddr(Address addr) {
		this.addr = addr;
	}
	
}

class Address{
	
	private String address;
	private String zipCode;
	
	public Address(){
		
	}
	
	public Address(String address,String zipCode){
		this.setAddress(address); 
		this.setZipCode(zipCode);
	}
	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getZipCode() {
		return zipCode;
	}

	public void setZipCode(String zipCode) {
		this.zipCode = zipCode;
	}
}

public class TestWorker {
	public static void main(String[] args){
		Address add = new Address();
		add.setAddress("No.1, Qinghua garden, Haidian District, Beijing");
		add.setZipCode("100084");
				
		Worker wok = new Worker("zhangsan",25,2500.0,add);
		
		System.out.println(wok.getName() +" "+ wok.getAge() +" "+ wok.getSalary() +" "+ wok.getAddr().getAddress() +" "+ wok.getAddr().getZipCode());
	}
	
}


Three, summary

    In the third week of Java learning, there are more knowledge to learn than last week, and the connectivity of knowledge is gradually increasing. It needs more practice, more thinking, more review and more summary. The basic knowledge should be firm, and the solutions to the problems should be more comprehensive, and the solutions should be more and more handy. For the same case, we should think of several solutions to achieve the highest efficiency Case.
Published 3 original articles, won praise 0, visited 22
Private letter follow

Topics: Attribute Java