JAVA对象和实验报告.docVIP

  • 9
  • 0
  • 约1.03万字
  • 约 8页
  • 2016-10-06 发布于贵州
  • 举报
JAVA对象和实验报告

实验项目名称 : 对象和类 (所属课程: Java语言程序设计 ) 院 系:计算机科学与信息工程 专业班级:12级物联网工程 姓 名: 学号: 实验地点: A-06 411 指导老师: 本实验项目成绩: 教师签字: 日期: 一.实验目的 (1)了解类的封装方法,以及如何创建类和对象。 (2)了解成员变量和成员方法的特性。 (3)掌握 OOP 方式进行程序设计的方法。 二.实验内容 (1)设计一个体现面向对象思想的程序。 (2)设计一个创建对象和使用对象的方法的程序。 (3)设计不同成员变量修饰方法的程序。 (4) 设计不同成员方法修饰方法的程序。 三.实验要求 (1)编写一个体现面向对象思想的程序。 (2)编写一个创建对象和使用对象的方法的程序。 (3)编写不同成员变量修饰方法的程序。 (4)编写不同成员方法修饰方法的程序。 四.实验器材 pc机及配套软件、一人一套package main; import economic.Account; public class Accountmain { public static void main(String[] args) { Account acc = new Account(1122,20000,0.045); System.out.println(账户ID: + acc.getId()); if(acc.withDraw(2500) == 0) System.out.println(取款成功,剩余金额: + acc.getBalance()); else System.out.println(取款失败,剩余金额: + acc.getBalance()); if(acc.deposit(3000) == 0) System.out.println(存款成功,剩余金额: + acc.getBalance()); else System.out.println(取款失败,剩余金额: + acc.getBalance()); System.out.println(月利率为: + acc.getMonthlyInterestRate()); System.out.println(开户日期为: + acc.getDateCreate().toString()); } } package economic; import java.util.Date; public class Account { private int id = 0; private double balance = 0; private double annualInterestRate = 0; private Date dateCreate = new Date(); public Account(int id, double balance, double annualInterestRate){ this.id = id; this.balance = balance; this.annualInterestRate = annualInterestRate; } public int getId(){ return id; } public int setId(int id){ if(id 0){ return -1; } else{ this.id = id; return 0; } } public double getBalance(){ return balance; } public double setBalance(double balance){ if(balance 0){ return -1; } else{ this.balance = balance; return 0; } } publi

文档评论(0)

1亿VIP精品文档

相关文档