第四周课程总结&试验报告2
试验报告2
写一个名为Rectangle的类表示矩形。其属性包括宽width、高height和颜色color,width和height都是double型的,而color则是String类型的。要求该类具有:
(1) 使用构造函数完成各属性的初始赋值
(2) 使用get…()和set…()的形式完成属性的访问及修改
(3) 提供计算面积的getArea()方法和计算周长的getLength()方法
实验代码:
public class Rectangle {
private double width;
private double height;
private String color;
public void tell() {
System.out.print("面积是"+(width*height)+"\n"+"周长是"+*(width+height)+"\n");
System.out.println("高为"+height);
System.out.println("宽为"+width);
System.out.println("颜色为"+color);
}
public String getColor(){
return color;
}
public void setColor(String n){
color=n;
}
public double getWidth(){
return width;
}
public void setWidth(double a){
width=a;
}
public double getHeight() {
return height;
}
public void setHeight(double b) {
height=b;
}
}
public class fff{
public static void main(String arge[]) {
Rectangle r1=new Rectangle();
r1.setColor("黄色");
r1.setHeight();
r1.setWidth();
r1.tell();
}
}
输出:

2.银行的账户记录Account有账户的唯一性标识(11个长度的字符和数字的组合),用户的姓名,开户日期,账户密码(六位的数字,可以用0开头),当前的余额。银行规定新开一个账户时,银行方面提供一个标识符、账户初始密码123456,客户提供姓名,开户时客户可以直接存入一笔初始账户金额,不提供时初始余额为0。定义该类,并要求该类提供如下方法:存款、取款、变更密码、可以分别查询账户的标识、姓名、开户日期、当前余额等信息。
实验代码:
public class Account{
private String name,date="2019.9.20";
private int cipher=,money=;
private String ccount="abcdefg";
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public int getCipher() {
return cipher;
}
public void setCipher(int cipher) {
this.cipher = cipher;
}
public int getMoney() {
return money;
}
public void setMoney(int money) {
this.money = money;
}
public String getCcount() {
return ccount;
}
public void setCcount(String ccount) {
this.ccount = ccount;
}
public void username(){
System.out.print("请输入用户名称:");
Scanner username = new Scanner(System.in);
String name = username.nextLine();
System.out.print("请输入开户时间:");
Scanner userdate = new Scanner(System.in);
String date = userdate.nextLine();
setName(name);
setDate(date);
System.out.print("开户成功!\n初始密码:123456\n开间:"+date+"\n");
}
public void ChangePWD(){
System.out.print("请输入更改密码:");
Scanner usercipher = new Scanner(System.in);
int cipher = usercipher.nextInt();
setCipher(cipher); 量中
System.out.print("更改密码成功!\n新密码:"+cipher+"\n");
}
public void all(){
System.out.print("用户名:"+name+" 开户日期:"+date+"\n账号:"+ccount+" 密码:"+cipher+"\n余额:"+money+"\n");
}
public void Depositsandwithdrawals(){
System.out.print("存款:1\n"+"取款:0\n");
System.out.print("请选择:");
Scanner j = new Scanner(System.in);
int i = j.nextInt();
if(i==) {
System.out.print("取款数:");
Scanner usermoney = new Scanner(System.in);
int money = usermoney.nextInt();
money=this.money-money;
setMoney(money);
}
else {
System.out.print("存款数:");
Scanner usermoney = new Scanner(System.in);
int money = usermoney.nextInt();
money=this.money+money;
setMoney(money);
}
}
public static void main(String[] args) {
System.out.print("Welcome\n");
System.out.print("进入系统请按1\n");
System.out.print("请选择:");
Scanner j = new Scanner(System.in);
int J = j.nextInt();
int I=;
robet user = new robet();
for(int k=;k>;) {
if(J==||I==) {
System.out.print("开户:1 "+"更改密码:2\n"+"查询用户信息:3 "+"存取款:4\n");
System.out.print("请选择:");
Scanner b = new Scanner(System.in);
int B = b.nextInt();
if(B==) {
user.username();
}else if(B==){
user.ChangePWD();
}else if(B==){
user.all();
}else if(B==){
user.Depositsandwithdrawals();
}
System.out.print("返回主页面:1\n"+"退出:0\n");
System.out.print("请选择:");
Scanner i = new Scanner(System.in);
I = i.nextInt();
J=;
}else{
break;
}
}
System.out.print("已安全退出");
}
}
课程总结
行实例化,其开辟了多个空间;String类中的字符串内容不可修改;符号”==“比较的是对象的地址;equals()方法比较的是对象的内容;
String类常用操作方法表格在书110页。
学了对像数组,对象数组指包含了一组相关的对象;
数组一定要先开辟空间因其是应用数据类型使用时每一个对象必须分别进行实例化操作,格式为:类 对象数组名称[]=new 类[数组长度];
了解了包的概念及使用:package在多个接口或类时,避免名称重复的措施;系统常见包见239页。( •̀ ω •́ )y
第四周课程总结&试验报告2的更多相关文章
- 第四周课程总结&试验报告(二)
实验二 Java简单类与对象 实验目的 掌握类的定义,熟悉属性.构造函数.方法的作用,掌握用类作为类型声明变量和方法返回值: 理解类和对象的区别,掌握构造函数的使用,熟悉通过对象名引用实例的方法和属性 ...
- 第四周课程总结&试验报告
实验二 Java简单类与对象 实验目的 掌握类的定义,熟悉属性.构造函数.方法的作用,掌握用类作为类型声明变量和方法返回值: 理解类和对象的区别,掌握构造函数的使用,熟悉通过对象名引用实例的方法和属性 ...
- 第五周课程总结&试验报告(三)
第五周课程总结&试验报告(三) 实验三 String类的应用 实验目的 掌握类String类的使用: 学会使用JDK帮助文档: 实验内容 ###1.已知字符串:"this is a ...
- 第四周课程总结&实验报告(二)
Java实验报告(二) 实验二 Java简单类与对象 一. 实验目的 (1) 掌握类的定义,熟悉属性.构造函数.方法的作用,掌握用类作为类型声明变量和方法返回值: (2) 理解类和对象的区别,掌握构造 ...
- 第四周课程总结&实验报告二
第四周课程总结 第四周课程总结 本周重点为学习String;首先String用以创建字符串,且通过有一次课堂练习加强理解到:String 类是不可改变的,一旦创建了 String 对象,那它的值就无法 ...
- 第四周课程总结与第二次实验报告(Java简单类与对象)
1.写一个名为Rectangle的类表示矩形.其属性包括宽width.高height和颜色color,width和height都是double型的,而color则是String类型的.要求该类具有: ...
- 实验报告2&&第四周课程总结
实验报告: 写一个名为Rectangle的类表示矩形.其属性包括宽width.高height和颜色color,width和height都是double型的,而color则是String类型的.要求该类 ...
- 第五周课程总结&试验报告三
第五周课程总结 一.第五周课程总结 1.this关键字 this可用于任何实例方法内指向当前对象,也可指向对其调用当前方法的对象,或者在需要当前类型对象引用时使用.当一个类的属性(成员变量)名与访问该 ...
- 第十四周课程总结&记事本功能的简单实现。
(1)课程总结: 这周简单学习了下JDBC的内容: JDBC API 允许用户访问任何形式的表格数据,尤其是存储在关系数据库中的数据. 执行流程: (1)连接数据源,如:数据库. (2)为数据库传递查 ...
随机推荐
- Amazon Redshift and the Case for Simpler Data Warehouses
Redshift是Amazon一个商业产品上的进化 但并不是技术的进化,他使用的无非都是传统数仓领域的技术 如果说创新,就是大量使用Amazon本身的云服务的云原生架构,大大提升的产品的迭代速度,可维 ...
- vue使用子路由时,默认的子路由视图不显示问题
解决办法是,将父级的name去掉.(大多数情况下是按name来跳转的,不过这样一改,调到父级就得用路径跳转了): 下面上一下路由的配置: { path: "/index", com ...
- 快速乘(O(1))
inline long long multi(long long x,long long y,long long mod) { long long tmp=(x*y-(long long)((long ...
- git上传项目已经删除文件,但是Jenkins中没有删除
jenkins 缓存造成的,需要清理工作空间
- Java项目框架搭建系列(Java学习路线)
前言: 已经工作4年,真是时间飞逝. 其实当你在一间公司工作一两年之后,公司用到的开发框架的基本使用你应该都会了. 你会根据一个现有项目A复制一下搭建出另外一个类似框架的项目B,然后在项目B上进行业务 ...
- (十三)C语言之break、continue
- CodeForce 137B
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Description " ...
- 基本CSS布局二
基本CSS布局二------基本页面布局二 /*主面板样式*/ #container { width:100%; margin:0px auto;/*主面板DIV居中*/ } /*顶部面板样式*/ # ...
- 使用redis时遇到的问题及解决方法
最近在向redis中写入数据的时候,报了下面的错误: failed opening the rdb file crontab (in server root dir /etc) for saving ...
- [论文理解] An Analysis of Scale Invariance in Object Detection – SNIP
An Analysis of Scale Invariance in Object Detection – SNIP 简介 小目标问题一直是目标检测领域一个比较难解决的问题,因为小目标提供的信息比较少 ...