




已阅读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(S
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025汽车典当合同全书
- 2025鞋履销售合同书
- 2025农业机械租赁合同范本
- 劳务外包合同
- 第8课 循环结构-for循环说课稿-2025-2026学年初中信息技术浙教版2020八年级上册-浙教版2020
- 环保监测服务合同协议
- 八年级物理下册 7.2力的描述说课稿 (新版)教科版
- 2024秋四年级英语上册 Module 9 Unit 1 Are you going to run on sports day说课稿 外研版(三起)
- 第14课 数字名章我制作说课稿-2025-2026学年小学信息技术人教版一 二年级起点五年级上册-人教版(一、二年级起点)
- 关于宝葫芦的秘密读后感
- (9月3日)铭记历史珍爱和平-纪念中国人民抗日战争暨世界反法西斯战争胜利80周年爱国主义主题教育班会课件
- 私域流量运营策略及五大关键原则
- 2026高中语文选择性必修上册 - -第二单元综合测试卷
- 2025年一级建造师《通信与广电工程管理与实务》案例背诵本
- 外墙真石漆安全培训课件
- 第三章真核微生物 (一)
- 中石化内部控制培训课件
- 2025年青少年法律知识竞赛试题库(试题及答案)
- 收单商户管理办法
- 分类管理理念下国有企业股权投资后评价体系的构建与实践
- 新生儿支气管肺炎护理查房
评论
0/150
提交评论