![Java實驗報告修改版_第1頁](http://file3.renrendoc.com/fileroot_temp3/2022-2/15/c8782bb5-31e2-4787-bc1e-8bcedf37fa84/c8782bb5-31e2-4787-bc1e-8bcedf37fa841.gif)
![Java實驗報告修改版_第2頁](http://file3.renrendoc.com/fileroot_temp3/2022-2/15/c8782bb5-31e2-4787-bc1e-8bcedf37fa84/c8782bb5-31e2-4787-bc1e-8bcedf37fa842.gif)
![Java實驗報告修改版_第3頁](http://file3.renrendoc.com/fileroot_temp3/2022-2/15/c8782bb5-31e2-4787-bc1e-8bcedf37fa84/c8782bb5-31e2-4787-bc1e-8bcedf37fa843.gif)
![Java實驗報告修改版_第4頁](http://file3.renrendoc.com/fileroot_temp3/2022-2/15/c8782bb5-31e2-4787-bc1e-8bcedf37fa84/c8782bb5-31e2-4787-bc1e-8bcedf37fa844.gif)
![Java實驗報告修改版_第5頁](http://file3.renrendoc.com/fileroot_temp3/2022-2/15/c8782bb5-31e2-4787-bc1e-8bcedf37fa84/c8782bb5-31e2-4787-bc1e-8bcedf37fa845.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、開課實驗室:現(xiàn)代信息交流中心403 開課時間: 2015年3月1日 實驗報告:2015年4月8日 學院名稱信息工程學院年級、專業(yè)、班信管1303班學號姓名張云森同組姓名無課程名稱Java程序設(shè)計實驗項目名稱Java面向?qū)ο蟪绦蛟O(shè)計(1)指導教師尉斌實驗類型驗證 綜合 設(shè)計 創(chuàng)新 成績教師評語 教師簽名: 年 月 日一、 實驗目的:熟悉類、屬性、構(gòu)造方法、普通方法、對象的使用方法。二、實驗內(nèi)容:(抄寫課本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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年的合同延續(xù)與權(quán)利轉(zhuǎn)讓協(xié)議樣本
- 2025年企業(yè)租賃新能源汽車合作合同
- 2025年企業(yè)市場營銷策劃委托協(xié)議書樣本
- 2025年合作伙伴店鋪聯(lián)合經(jīng)營協(xié)議
- 2025年共發(fā)展合作協(xié)議示例
- 2025年居民小區(qū)消防系統(tǒng)設(shè)計申請與施工協(xié)議
- 2025年先進技術(shù)許可合同規(guī)范模板
- 2025年全球貿(mào)易增長與多邊合作協(xié)議
- 2025年協(xié)作一致行動人協(xié)議樣本
- 2025年大型卡車租賃服務合同
- GMS要素-持續(xù)改進(CI)-上汽通用五菱-課件
- 信訪事項復查復核申請書
- 神經(jīng)遞質(zhì)和神經(jīng)調(diào)質(zhì)生
- 18CS01 裝配式箱泵一體化消防給水泵站選用及安裝-MX智慧型泵站
- 枇杷常見病蟲害一覽表專家講座
- 《紙杯變變變》教學設(shè)計
- 九九乘法口訣表(超清晰打印版)
- GB/T 3921-2008紡織品色牢度試驗耐皂洗色牢度
- GA/T 1780-2021多道心理測試實驗室建設(shè)規(guī)范
- PPT模板第二講運動選材概述運動選材學
- 營養(yǎng)學基礎(chǔ)知識-課件
評論
0/150
提交評論