版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、开课实验室:现代信息交流中心403 开课时间: 2015年3月1日 实验报告:2015年4月8日 学院名称信息工程学院年级、专业、班信管1303班学号姓名张云森同组姓名无课程名称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、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 specifi
3、ed 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
4、 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 shiya
5、n1 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,400
6、0);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,ol
7、dPrice,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 n
8、ame;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.pr
9、eviousClosingPrice + "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
10、 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=newAnnuanInterset
11、Rate;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()ret
12、urn 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
13、.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.getannuaInterse
14、tRate(); 方法二: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
15、 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;Accou
16、nt(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 getMonthlyTnteres
17、t()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)if (on
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 数据治理员安全检查知识考核试卷含答案
- 小学生卫生知识培训课件
- 沙地治理工安全实践强化考核试卷含答案
- 电阻器专用合金粉制造工岗前工作改进考核试卷含答案
- 疫苗菌毒种培育工班组安全测试考核试卷含答案
- 2025年天津市静海区北师大实验学校教师招聘真题
- 2025年陕西警官职业学院辅导员考试真题
- 培训公司规章制度课件
- 黑龙江奶茶培训课件图片
- 碎煤机培训课件
- 中国水性丙烯酸压敏胶项目商业计划书
- 液流电池制造项目可行性研究报告
- 组织文化与员工满意度
- 2025年大学消防指挥专业题库- 火场搜救与人员救援
- 国内普通中学艺术设计教育:现状、挑战与突破路径
- 西游记车迟国课件
- GB/T 46075.1-2025电子束焊机验收检验第1部分:原则与验收条件
- DB21-T 1844-2022 保温装饰板外墙外保温工程技术规程
- 艾梅乙安全助产培训课件
- 新生儿科护理服务标准与操作规范
- 困境儿童心理健康教育讲座
评论
0/150
提交评论