(JAVA)山东大学高级程序设计语言课程实验手册

您所在的位置:网站首页 软件高级工程师考试论文忘了选择题目 (JAVA)山东大学高级程序设计语言课程实验手册

(JAVA)山东大学高级程序设计语言课程实验手册

2023-03-13 16:49| 来源: 网络整理| 查看: 265

高级程序设计语言课程实验手册 实验要求

Java程序设计上机。

要求对每个实验交一份电子版的实验报告(具体格式见附1),总结整个java程序设计实验的心得体会以及经常遇到的问题(很重要)及解决方法(即正确答案)。实验报告命名为 “学号姓名.doc”。每次实验过后不迟于第二天早上8点,提交至FTP(使用方法见附2)。

实验1:熟悉IDEA开发环境

(见课件:IDEA实验环境.pptx)

实验2:输入输出小程序

实验目的

本实验对应课本第二章知识,交互式应用程序:

掌握利用Scanner获取数据,println输出结果的基本方法

掌握Java中的基本数据类型、变量、表达式以及数据类型转化等基本概念

实验内容

1、编写一个程序,从键盘读入三位(不要求任意位)十进制数,以八进制的形式输出,要求程序有较友好的交换过程、源代码撰写较规范。例如,读入 888,输出1570

2、编写一个程序,从键盘读入一元二次方程ax2 + bx + c = 0的系数a,b,c,计算输出其两个根。提示:开方(Math.sqrt(bb-4a*c))

实验3:分支循环初步

本实验对应课本第五章内容,流程控制:

实验目的

尝试阅读理解简单的分支、循环程序

实验内容:

1、编写程序,随机生成10个1…100内的整数,打印这10个整数的总和,算数平均数,最大值,最小值,第二大数值以及第二小数值。

2、编写程序,读入正整数n,n public static void main(String args[]) throws Exception { String filename = "data.txt"; int op1,op2,result=0; String operator =""; // create a scanner from the data file Scanner scanner = new Scanner(new File(filename)); // 重复从文件中读取数据 while (scanner.hasNext()) { // retrieve each data element operator = scanner.next(); op1 = scanner.nextInt(); op2 = scanner.nextInt(); if (operator.equals("+")) result = op1 + op2; else if (operator.equals("-")) result = op1 - op2; System.out.println("result is " + result); } scanner.close(); // also closes the File } } Data1.txt + 12 56 - 213 33 * 21 32 / 15 4 / 15 0 + 22 6 Data2.txt 12 + 15 - 13 17 - 18 + 24 33 * 6 / 6 55 / 10 + 2 Data3.txt 2 + 3 * 4 2 + 3 + 2 * 3 + 2 3 * 4 - 2 * 3 1234 - 567 / 7 + 22 实验5:预定义类与自定义类

实验目的

本实验对应课本第三、第四章知识

掌握字符串、数学类等主要预定义类的使用方法

掌握自定义类的一般方法

实验内容

编写一个程序,实现如下功能:

自定义一个银行账户类,包括属性(用户名,账号,余额)以及方法(存钱、取钱、加利息、查询余额)。遵从封装原则。

创建两个用户对象,模拟两个用户的各3次交易,例如:取钱,存钱,查询余额。

创建账户所需的信息由键盘输入;存钱、取钱的数额由随机数模拟。

每次账户交易在屏幕打印交易后的账户信息,有一定的排版

不允许出现账户金额为负数的操作。

实验6:文本处理(选做)

实验目的

本实验对应课本第五章控制流程以及第三章,Java预定义类

综合运用控制流程

学习使用String,Random等类。

实验内容

统计字符串中字符’s’所占比例

/************

字符串及随机数

1、调试程序,使输出正确结果

2、仿照下一页的一篇文章,找10篇左右,存入同一个文本文件中,从文件中读数据,分别统计’s’'z’的出现频率,作为Ground Truth

3、利用随机采样的方法,分别统计’s’'z’的出现频率(例如,随机选择100,1000,10000个字符,计算选中’s’的比例)

4、用excel画一个折线图,可视化不同采样样本数量与GT之间的关系(随着采样数的增加,逐渐逼近Ground Truth)

5、再做一个类似的文本,验证你的结论。

*/

import java.util.Random;

public class T03StringProc {

public static void main(String[] args){

String str=“test”;

int count = 0;

for (int i = 0; i< str.length(); i++){

if (str.charAt(i) == ‘s’){

count++;

}

}

System.out.println("percentage of ‘s’ is " + count/str.length());

}

}

Artificial intelligence (AI), is intelligence demonstrated by machines, unlike the natural intelligence displayed by humans and animals. Leading AI textbooks define the field as the study of “intelligent agents”: any device that perceives its environment and takes actions that maximize its chance of successfully achieving its goals.[3] Colloquially, the term “artificial intelligence” is often used to describe machines (or computers) that mimic “cognitive” functions that humans associate with the human mind, such as “learning” and “problem solving”.[4]

As machines become increasingly capable, tasks considered to require “intelligence” are often removed from the definition of AI, a phenomenon known as the AI effect.[5] A quip in Tesler’s Theorem says “AI is whatever hasn’t been done yet.”[6] For instance, optical character recognition is frequently excluded from things considered to be AI,[7] having become a routine technology.[8] Modern machine capabilities generally classified as AI include successfully understanding human speech,[9] competing at the highest level in strategic game systems (such as chess and Go),[10] autonomously operating cars, intelligent routing in content delivery networks, and military simulations.[11]

Artificial intelligence was founded as an academic discipline in 1955, and in the years since has experienced several waves of optimism,[12][13] followed by disappointment and the loss of funding (known as an “AI winter”),[14][15] followed by new approaches, success and renewed funding.[13][16] For most of its history, AI research has been divided into sub-fields that often fail to communicate with each other.[17] These sub-fields are based on technical considerations, such as particular goals (e.g. “robotics” or “machine learning”),[18] the use of particular tools (“logic” or artificial neural networks), or deep philosophical differences.[21][22][23] Sub-fields have also been based on social factors (particular institutions or the work of particular researchers).[17]

The traditional problems (or goals) of AI research include reasoning, knowledge representation, planning, learning, natural language processing, perception and the ability to move and manipulate objects.[18] General intelligence is among the field’s long-term goals.[24] Approaches include statistical methods, computational intelligence, and traditional symbolic AI. Many tools are used in AI, including versions of search and mathematical optimization, artificial neural networks, and methods based on statistics, probability and economics. The AI field draws upon computer science, information engineering, mathematics, psychology, linguistics, philosophy, and many other fields.

The field was founded on the assumption that human intelligence “can be so precisely described that a machine can be made to simulate it”.[25] This raises philosophical arguments about the mind and the ethics of creating artificial beings endowed with human-like intelligence. These issues have been explored by myth, fiction and philosophy since antiquity.[30] Some people also consider AI to be a danger to humanity if it progresses unabated.[31][32] Others believe that AI, unlike previous technological revolutions, will create a risk of mass unemployment.[33]

In the twenty-first century, AI techniques have experienced a resurgence following concurrent advances in computer power, large amounts of data, and theoretical understanding; and AI techniques have become an essential part of the technology industry, helping to solve many challenging problems in computer science, software engineering and operations research.[34][16]

实验7:日历输出程序Java控制流程

实验目的

更深入的理解Java控制流程

实验内容

基本功能:输入一个月份,给出2019年这个月的日历,日历要求每行显示7列,对应星期一到星期日;

扩展功能:输入一个月份,同时输出该月起始的两个月的日历,要求两个月的日历水平排列而非上下排列。

实验8 自定义ArrayList

实验目的

本部分对应课本第八章,帮助学生深入理解数组使用方法

实验内容:

利用数组实现Java ArrayList类的基本功能,要求实现方法包括:

初始ArrayList长度4,

Append尾部追加一个对象,长度不足容量翻倍策略;

Insert在参数指定位置插入数据,参数位置错误则不加入,长度不足容量翻倍策略;

Delete删除参数指定位置元素,考虑参数位置错误情况

Find,根据参数指定位置定位元素,考虑参数位置错误情况

编写一个测试应用,测试每个方法的正确性。

利用模板,支持课本第八章DVD对象的管理

性能测试:

利用Append尾部加入50万个随机生成的对象;

利用Insert头部加入50万对象;

利用Insert随机位置加入50万个对象。

每加入1万个对象,统计一次时间,画出时间,处理数据量曲线。

利用Java自定义ArrayList做同样的实验,比较时间效率。

实验9 图形家族-继承与多态

实验目的

本实验涉及的知识点主要为 继承、多态、排序,对应课本9、10章知识点

实验内容

1、矩形、正方形、菱形、圆形都是形状,请以形状(Shape)为最顶层的类,设计出一个层次化的类结构,求面积、周长的方法,作为形状类的抽象方法

2、写一个程序,随机创建20个形状,存储到数组中;利用多态思想,(尽量只)写一个静态排序方法,实现所有形状按照周长、面积从大到小及从小到大四种规则排序。修改排序方法,使其同时支持一种新的排序规则,按照面积,所有圆形从小到大排列,后面是所有其他图形从大到小排列。

3、输出结果应当能清晰直观的体现程序的正确性。

实验10 链表操作

实验目的

熟悉链表的原理和基本算法。

加深对引用的理解和使用。

实验内容

阅读课本Magazine Collection例子

在MagazineList类中添加方法,

void sort()//按照书名对链表排序

void mergeSort(MagazineList another)//检查两个链表是否都为排序链表,如果是,归并;如果不是,直接返回。



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3