




已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 在线教育培训服务协议条款
- 2024-2025学年河南省新乡市长垣市人教版三年级下册期末考试数学试卷(含答案)
- 合作研究与开发科技成果共享协议
- 观后感夏洛的网1200字10篇
- 2025年教师招聘之《幼儿教师招聘》考前冲刺练习题库及参考答案详解(黄金题型)
- 教师招聘之《幼儿教师招聘》练习题库含答案详解(典型题)
- 肉毒素课件教学课件
- 2025秋大象版(2024)小学科学三年级上册《装订我的小书》教学设计
- 新质生产力物料搬运设备
- 押题宝典期货从业资格之《期货法律法规》试题含答案详解【研优卷】
- 2025年下半年安徽省港航集团有限公司所属企业社会公开招聘22名考试参考试题及答案解析
- 人教PEP版六年级英语上册全册教案
- 3D打印技术在制造业2025年发展趋势及市场前景可行性分析报告
- 综合楼玻璃安装合同协议书范本模板6篇
- 2025年度集中供暖项目暖气设施安装及售后服务合同
- 护士医护人员职业安全防护培训
- 2025福建厦门市公安局同安分局招聘警务辅助人员50人笔试备考试题及答案解析
- 莲山教学课件下载
- 大学生创新创业基础课件 第7章 创业与创业历程
- 班主任育人故事经验分享陪伴每一名学生慢慢成长模板
- 2025至2030中国漂白粉行业发展研究与产业战略规划分析评估报告
评论
0/150
提交评论