ImageVerifierCode 换一换
格式:DOCX , 页数:24 ,大小:580.63KB ,
资源ID:6176913      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/6176913.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(Java上机实验报告.docx)为本站会员(b****6)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

Java上机实验报告.docx

1、Java上机实验报告Java上机实验报告练习21、WORKING WITH NUMERIC VALUESDemoVariables.javapublic class DemoVariables public static void main(String args) int entry = 315; System.out.print(The entry is ); System.out.println(entry); 2、ACCEPTING USER DATADemoVariables2.javaimport java.util.Scanner;public class DemoVariabl

2、es2 public static void main(String args) int entry; Scanner keyBoard = new Scanner(System.in); System.out.print(Enter an integer ); entry = keyBoard.nextInt(); System.out.print(The entry is ); System.out.println(entry); 3、PERFORMING ARITHMETICDemoVariables3.javaimport java.util.Scanner;public class

3、DemoVariables3 public static void main(String args) int entry; int anotherEntry; Scanner keyBoard = new Scanner(System.in); System.out.print(Enter an integer ); entry = keyBoard.nextInt(); System.out.print(Enter another integer ); anotherEntry = keyBoard.nextInt(); System.out.println(entry + plus +

4、anotherEntry + is + (entry + anotherEntry); System.out.println(entry + minus + anotherEntry + is + (entry - anotherEntry); System.out.println(entry + times + anotherEntry + is + (entry * anotherEntry); System.out.println(entry + divided by + anotherEntry + is + (entry / anotherEntry); System.out.pri

5、ntln(The remainder is + (entry % anotherEntry); 练习41、CREATING A STATIC METHOD THAT REQUIRES NO ARGUMENTS AND RETURNS NO VALUESSetUpSite.javapublic class SetUpSite public static void statementOfPhilosophy() System.out.println(Event Handlers Incorporated is); System.out.println(dedicated to making you

6、r event); System.out.println(a most memorable one.); public static void main(String args) statementOfPhilosophy(); 2、CALLING A STATIC METHOD FROM ANOTHER CLASSTestStatement.javapublic class TestStatement public static void main(String args) System.out.println(Calling method from another class); SetU

7、pSite.statementOfPhilosophy(); 3、CREATING A STATIC METHOD THAT ACCEPTS ARGUMENTS AND RETURNS VALUESSetUpSite2.javaimport java.util.Scanner;public class SetUpSite2 public static void statementOfPhilosophy() System.out.println(Event Handlers Incorporated is); System.out.println(dedicated to making you

8、r event); System.out.println(a most memorable one.); public static int calculateAge(int originYear, int currDate) int years; years = currDate - originYear; return years; public static void main(String args) final int FOUNDED_YEAR = 1977; int currentYear; int age; Scanner input = new Scanner(System.i

9、n); System.out.print(Enter the current year as a four-digit number ); currentYear = input.nextInt(); age = calculateAge(FOUNDED_YEAR, currentYear); System.out.println(Founded in + FOUNDED_YEAR); System.out.println(Serving you for + age + years ); 4、CREATING A CLASS THAT CONTAINS INSTANCE FIELDS AND

10、METHODSEventSite.javapublic class EventSite private int siteNumber; public int getSiteNumber() return siteNumber; public void setSiteNumber(int n) siteNumber = n; 5、CREATING A CLASS THAT INSTANTIATES OBJECTS OF ANOTHER CLASSSetUpSite3.javaimport java.util.Scanner;public class SetUpSite3 public stati

11、c void statementOfPhilosophy() System.out.println(Event Handlers Incorporated is); System.out.println(dedicated to making your event); System.out.println(a most memorable one.); public static int calculateAge(int originYear, int currDate) int years; years = currDate - originYear; return years; publi

12、c static void main(String args) statementOfPhilosophy(); final int FOUNDED_YEAR = 1977; int currentYear; int age; EventSite oneSite = new EventSite(); int siteNum; Scanner input = new Scanner(System.in); System.out.print(Enter the current year as a four-digit number ); currentYear = input.nextInt();

13、 System.out.print(Enter the event site number ); siteNum = input.nextInt(); age = calculateAge(FOUNDED_YEAR, currentYear); System.out.println(Founded in + FOUNDED_YEAR); System.out.println(Serving you for + age + years ); oneSite.setSiteNumber(siteNum); System.out.println(The site number is + oneSit

14、e.getSiteNumber(); 6、ADDING A CONSTRUCTOR TO A CLASSEventSite.javapublic class EventSite private int siteNumber; public EventSite() siteNumber = 999; public int getSiteNumber() return siteNumber; public void setSiteNumber(int n) siteNumber = n; TestConstructor.javapublic class TestConstructor public

15、 static void main(String args) EventSite oneSite = new EventSite(); System.out.println(Site number + oneSite.getSiteNumber(); 练习51、DEMONSTRATING SCOPEDemoBlock.javapublic class DemoBlock public static void main(String args) System.out.println(Demonstrating block scope); int x = 1111; System.out.prin

16、tln(In first block x is + x); int y = 2222; System.out.println(In second block x is + x); System.out.println(In second block y is + y); int y = 3333; System.out.println(In third block x is + x); System.out.println(In third block y is + y); demoMethod(); System.out.println(After method x is + x); Sys

17、tem.out.println(After method block y is + y); System.out.println(At the end x is + x); public static void demoMethod() int x = 8888, y = 9999; System.out.println(In demoMethod x is + x); System.out.println(In demoMethod block y is + y); 2、OVERLOADING METHODSpublic class DemoOverload public static vo

18、id overloadDate(int mm) System.out.println(Event date + mm + /1/2011); public static void overloadDate(int mm, int dd) System.out.println(Event date + mm + / + dd + /2011); public static void overloadDate(int mm, int dd, int yy) System.out.println(Event date + mm + / + dd + / + yy); public static vo

19、id main(String args) int month = 6, day = 24, year = 2010; overloadDate(month); overloadDate(month, day); overloadDate(month, day, year); 3、CREATING A CONSTRUCTOR THAT REQUIRES AN ARGUMENTEventSite.javapublic class EventSite private int siteNumber; private double fee; private String name; public Eve

20、ntSite() siteNumber = 999; fee = 0; name = XXX; public EventSite(int siteNum) this(); siteNumber = siteNum; public int getSiteNumber() return siteNumber; public void setSiteNumber(int n) siteNumber = n; public double getFee() return fee; public void setFee(double n) fee = n; public String getName()

21、return name; public void setName(String n) name = n; DemoConstructor.javapublic class DemoConstructor public static void display(EventSite site) System.out.println(nEvent site # + site.getSiteNumber() + nFee is $ + site.getFee() + nName of site is + site.getName(); public static void main(String arg

22、s) EventSite site1 = new EventSite(); EventSite site2 = new EventSite(678); display(site1); display(site2); 4、USING AN EXPLICITLY IMPORTED PREWRITTEN CLASSCalendarDemo.javaimport java.util.*;public class CalendarDemo public static void main(String args) GregorianCalendar now = new GregorianCalendar(

23、); System.out.println(YEAR: + now.get(Calendar.YEAR); System.out.println(MONTH: + now.get(Calendar.MONTH); System.out.println(WEEK_OF_YEAR: + now.get(Calendar.WEEK_OF_YEAR); System.out.println(WEEK_OF_MONTH: + now.get(Calendar.WEEK_OF_MONTH); System.out.println(DATE: + now.get(Calendar.DATE); System

24、.out.println(DAY_OF_MONTH: + now.get(Calendar.DAY_OF_MONTH); System.out.println(DAY_OF_YEAR: + now.get(Calendar.DAY_OF_YEAR); System.out.println(DAY_OF_WEEK: + now.get(Calendar.DAY_OF_WEEK); System.out.println(AM_PM: + now.get(Calendar.AM_PM); System.out.println(HOUR: + now.get(Calendar.HOUR); Syste

25、m.out.println(HOUR_OF_DAY: + now.get(Calendar.HOUR_OF_DAY); System.out.println(MINUTE: + now.get(Calendar.MINUTE); System.out.println(SECOND: + now.get(Calendar.SECOND); System.out.println(MILLISECOND: + now.get(Calendar.MILLISECOND); 5、CREATING AN INTERACTIVE APPLICATION WITH A TIMERDialogTimer.jav

26、aimport javax.swing.JOptionPane;import java.util.*;public class DialogTimer public static void main(String args) int time1, time2, milli1, milli2, sec1, sec2, timeDifference; final int MILLISECSINSECOND = 1000; JOptionPane.showConfirmDialog(null, Is stealing ever justified? ); GregorianCalendar befo

27、re = new GregorianCalendar(); milli1 = before.get(GregorianCalendar.MILLISECOND); sec1 = before.get(GregorianCalendar.SECOND); time1 = MILLISECSINSECOND * sec1 + milli1; GregorianCalendar after = new GregorianCalendar(); milli2 = after.get(GregorianCalendar.MILLISECOND); sec2 = after.get(GregorianCa

28、lendar.SECOND); time2 = MILLISECSINSECOND * sec2 + milli2; timeDifference = time2 - time1; JOptionPane.showMessageDialog(null,It took + timeDifference + milliseconds for you to answer); 练习71、To create the general Event class:Event.javaimport javax.swing.*;public class Event private int eventGuests; public void displayEventGuests() JOptionPane.showMessageDialog(null, Event guests: + eventGuests); public void inputEventGuests() char inChar; String guestsString = new String(); guestsString = JOptionPane.s

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1