带参数

import java.util.*;
import java.util.Arrays;
/**
 * 实现客户信息的管理 
 *
 */
public class CustomerBiz {
	class StudentsBiz {
		// 字符串数组作为参数和返回值
		public void sortNames(String[] names) {
			Arrays.sort(names);
			return names;
		}
	}
}
public class TestSort {
	public static void main(String[] args) {
		CustomerBiz st = new CustomerBiz();
		String[] namesbysort = new String[] { "Tom", "Jack", "Merry", "Smith","Sunny" };
		System.out.println("****排序前****");
		for (int i = 0; i < namesbysort.length; i++) {
			if (namesbysort[i] != null) {
				System.out.print(namesbysort[i] + "\t");
			}
		}
		//调用排序方法
		st.sortNames(namesbysort);
		System.out.println("\n****排序后****");
		for (int i = 0; i < namesbysort.length; i++) {
			if (namesbysort[i] != null) {
				System.out.print(namesbysort[i] + "\t");
			}
		}
	}
}

实例2

class Customer {
	public String name;
	public int age;
	public boolean isMember;

	public void showInfo() {
		System.out.println(name + "\t" + age + "\t" + isMember);
	}
class CustomersBiz {

	Customer[] customers = new Customer[30]; // 客户数组

	/**
	 * 增加客户
	 * 
	 * @param 一个客户
	 */
	public void addCustomer(Customer cust) {
		for (int i = 0; i < customers.length; i++) {
			if (customers[i] == null) {
				customers[i] = cust;
				break;
			}
		}
	}

	/**
	 * 显示客户信息
	 * 
	 */
	public void showCustomers() {
		System.out.println("客户信息:");
		for (int i = 0; i < customers.length; i++) {
			if (customers[i] != null) {
				customers[i].showInfo();
			}
		}
		System.out.println();
	}
}
import java.util.Scanner;

public class TestAdd {

	/**
	 * 调用有参方法
	 */
	public static void main(String[] args) {
		// 实例化客户对象
		Customer customer1 = new Customer();
		customer1.name = "王一";
		customer1.age = 30;
		customer1.isMember = false;
		Customer customer2 = new Customer();
		customer2.name = "郝强";
		customer2.age = 19;
		customer2.isMember = true;

		// 新增客户对象
		CustomersBiz customersBiz = new CustomersBiz();
		customersBiz.addCustomer(customer1);
		customersBiz.addCustomer(customer2);
		customersBiz.showCustomers();// 显示客户信息
	}

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值