




已阅读5页,还剩2页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
天津商业大学学生实验报告开课实验室:现代信息交流中心403 开课时间: 2015年3月1日 实验报告:2015年4月8日 学院名称信息工程学院年级、专业、班信管1303班学号20134612姓名张云森同组姓名无课程名称Java程序设计实验项目名称Java面向对象程序设计(1)指导教师尉斌实验类型验证 综合 设计 创新 成绩教师评语 教师签名: 年 月 日一、 实验目的:熟悉类、属性、构造方法、普通方法、对象的使用方法。二、实验内容:(抄写课本296页8.2、8.7、8.8的题目至此。抄写英文即可)8.2 (The stock class)Following the example of the Circle class in $8.2,design a class named Stock that contains:n A string data field named symbol for the stocks symbol.n A string datd field named name for the stocks name.n A double data field named previousClosingPrice that stores the stock price for the previous day.n A constructor that creates a stock with specified symbol and name.n A method named getChangePercent() that returns the percentage changed from previousClosingPrice to currentPrice.Draw the UMLdiagram for the class.Implement the class.Write a test program that creates a Stock object with the stock symbol JAVA,the name Sun Microsystems Inc,and the previous closing price of 4.5.Set a new current price to 4.35 and display the price-change percentage. 8.7(The Account class)Design a class named Account that contains:n A private int data field named id for the account(default 0).n A private double 三、源代码清单:1、源代码清单方法一:package 实验2;public class shiyan1 public static class Aprivate String number1;private double newPrice;public static void main(Stringargs)A symbol= new A();System.out.println(The stock number is :+symbol.number1);A name=new A(中国银行);System.out.println(The stock name is :+1);A Price=new A(3900,4000);System.out.println(The stock PreviousPrice is :+Price.oldPrice);System.out.println(The stock CurrentPrice is :+Price.newPrice);System.out.println(The stock getChangePercent is :+Price.getChangePercent();String number11,name1;double PreviousPrice,CurrentPrice,oldPrice,newPrice1;A()number1 = 000001;A(String name2)name1=name2;A(double Price1,double Price2)oldPrice=Price1;newPrice=Price2;double getChangePercent()return (newPrice-oldPrice)/oldPrice;方法二:package 实验2;public class shiyan11 public static class Stock private String symbol;private String name;public Stock(String symbol, String name)this.symbol = symbol; = name;public static void main(String args) Stock name = new Stock(JAVA, Sun Microsystems Inc);System.out.println(name.symbol+ ++,+The price-change percentage betwwen+ name.previousClosingPrice + and + name.currentPrice + is+ name.getChangePercent();double previousClosingPrice = 4.5;double currentPrice = 4.35;double getChangePercent() return (previousClosingPrice - currentPrice) / previousClosingPrice;2、方法一:package 实验2;public class Account private int ID=0;private double balance=0;private double annuanIntersetRate=0;private String dataCreated=2015年1月1日;public Account (int newID)ID=newID;public int getid()return ID;public Account (double newBalance,double newAnnuanIntersetRate)balance=newBalance;annuanIntersetRate=newAnnuanIntersetRate;public double getBalance()return balance;public double getannuaIntersetRate()return annuanIntersetRate/12;public Account(String newDataCreated)dataCreated=newDataCreated;public String getdataCreated()return dataCreated;public double getWithdraw()return balance-2500;public double getDeposit()return balance-2500+3000;package 实验2;public class Account1 public static void main(Stringargs)Account myID=new Account(1122);System.out.println(The ID is :+myID.getid();Account myBalance=new Account(20000.0,0.045);System.out.println(The banlane is :+myBalance.getBalance();System.out.println(The newBalance is :+myBalance.getWithdraw();System.out.println(The lastBalance is :+myBalance.getDeposit();System.out.println(The data created is :+myBalance.getdataCreated();System.out.println(The month rate is :+myBalance.getannuaIntersetRate(); 方法二:package exercise;import java.util.Date;import java.util.Scanner;public class TestAccount public static void main(String args)Account account = new Account(1122,20000);account.setAnnualInterestRate(4.5);account.withdraw(2500);account.deposit(3000);System.out.println(The balance is :+account.getbalance();System.out.println(Monthly interest is + account.getMonthlyTnterest(); System.out.println(This account was created at + account.getDateCreated();class AccountString ID;double balance=0.0;double annualInterestRate;Date dateCreated;Account(String newID,double balance)ID=newID;this.balance=balance;dateCreated=new Date(); void setAnnualInterestRate(double annualInterestRate)this.annualInterestRate=annualInterestRate;public Date getDateCreated()return dateCreated;public double getbalance()return balance;public double getMonthlyTnterest()return balance * (annualInterestRate / 1200);public double withdraw(double number)balance=balance-number;return balance;public double deposit(double number)balance=balance+number;return balance;3、源代码清单package 实验2;public class Fanint speed=1;boolean on=false;double radius=5;String color=blue;public Fan()public void turnOn()on=true;public void turnOff()on=false;public void setSpeed(int newSpeed)if(on&newSpeed=1&newSpeed=3)speed=newSpeed;public void setColor(String newColor)
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 工程师职业素养提升路径与终身学习机制的构建
- 高效教学督导体系的组织与功能设计
- 北京市海淀区101中学2024-2025学年物理八上期末考试模拟试题含解析
- 江苏省无锡市江阴市第二中学2024-2025学年八上数学期末质量跟踪监视试题含解析
- 重庆市渝北区实验中学2024年八上数学期末考试模拟试题含解析
- 山东省新泰市西部联盟2024年化学九年级第一学期期末统考试题含解析
- 智慧能源发展之路:分布式光伏储能技术的应用与发展
- 能源物联网边缘网关行业研究报告:现状趋势与未来展望
- 农业产业链中作物品质检测的商业价值探索
- 基于虚拟现实的智能制造与智能设计体验
- 呼伦贝尔农垦集团有限公司招聘笔试题库2025
- 医养结合养老院养老中心项目可行性研究报告
- 个人餐饮技术服务合同(4篇)
- GB/T 34571-2017轨道交通机车车辆布线规则
- HF-01型电除尘器高频电源使用说明书
- 消毒供应室专科理论考试题库(单选、多选共500题)
- 询价单(表格模板)
- QC降低矿山法围岩隧道爆破超挖量
- 2023年5月FDA口服速释制剂根据BCS分类系统的生物利用度与生物等效性研究及生物等效性豁免
- 蓝色海洋经济海事航海渔业水产养殖港口码头海运PPT模板
- 不饱和聚酯树脂化学品安全技术说明书MSDS
评论
0/150
提交评论