已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 计算机实习心得体会内容
- 办公楼消防设备维保合同
- 福建省漳州市华安县2023-2024学年二年级下学期期中考试数学试题
- 《公共电信网增强+支持智能环境预警应用的技术要求GBT+38934-2020》详细解读
- 如何当好护士长课件
- 防范非法集资宣传打击非法集资远离金融诈骗课件
- vte的预防与管理完整版
- 腹腔镜下胃癌根治术并发症预防处理
- 妊娠糖尿病的预防与控制
- 2025高考帮备考教案数学第三章一元函数的导数及其应用第3讲 导数与函数的极值、最值含答案
- GB/T 10781.4-2024白酒质量要求第4部分:酱香型白酒
- 部编版六年级道德与法治下册期末复习课件
- 统计与数据分析基础-形成性考核三(项目6-项目8阶段性测试权重25%)-国开-参考资料
- 教你成为歌唱达人智慧树知到期末考试答案2024年
- 软件源代码合同
- 国开2024春季《形势与政策》大作业:试分析新征程上推进生态文明建设需要处理好哪五个“重大关系”?(一)
- 双减背景下的作业设计与实施优秀案例PPT
- 油烟管道清洗证明报告
- 小学英语语法教学建议ppt
- 土地复垦施工合同
- 在全市中小学防范溺水专项工作会议上的讲话
评论
0/150
提交评论