博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[ZhuJie]JAVA实验一 JavaHowToProgram
阅读量:3573 次
发布时间:2019-05-20

本文共 3443 字,大约阅读时间需要 11 分钟。

ZhangGuizhu是个好老师!

题目要求:

这里写图片描述
这里写图片描述
这里写图片描述

代码如下,有四个class文件:

package chTwoWorks;import java.util.Scanner;public class SeparatingDigits {    public static void main(String[] args) {        // TODO Auto-generated method stub        Scanner input = new Scanner(System.in);        int[] digit = new int[6];        int number = input.nextInt();        for(int i=4;i>=0;i--) {            digit[i] = number%10;            number /= 10;        }        for(int i=0;i<=4;i++) {            System.out.printf("%d ",digit[i]);        }        input.close();        System.exit(0);    }}
package chTwoWorks;public class TableOfSquaresAndCubes {    public static void main(String[] args) {        // TODO Auto-generated method stub        System.out.println("number  square  cube   ");        for(int number = 0;number <= 10;number ++) {            System.out.printf("%-8d%-8d%-8d\n",number,number*number,number*number*number);        }        System.exit(0);    }}
package chThreeWorks;//Exercise 3.11 Solution: Account.javapublic class Accounts {    private double balance;    private String name;    public  Accounts(String name, double balance) {        this.name = name;// assign name to instance variable name        if(balance > 0.0)            this.balance = balance;    }    public void deposit(double depositAmount) {         if(depositAmount > 0.0)             balance += depositAmount;     }    public void withdraw(double withdrawalAmount) {        if(withdrawalAmount > balance)            System.out.println("Balance is not enough!");        else            balance -= withdrawalAmount;    }    public double getBalance() {        return balance;    }    public String getName() {        return name;    }}
package chThreeWorks;//Exercise 3.11 Solution: AccountTest.java import java.util.Scanner;public class AccountTest {    public static void main(String[] agrs) {        //define two accounts        Accounts account1 = new Accounts("HuangTao",100.0);        Accounts account2 = new Accounts("WangYuchen",-17.5);        //print accounts & balance        System.out.printf("%s Balance: ¥ %.2f \n",account1.getName(),account1.getBalance());        System.out.printf("%s Balance: ¥ %.2f \n\n",account2.getName(),account2.getBalance());        Scanner input = new Scanner(System.in);        double depositAmount;        double withdrawalAmount;        //account1 deposit & withdraw        System.out.print("Enter the deposit amount of account1: ");        depositAmount = input.nextDouble();        account1.deposit(depositAmount);        System.out.printf("%s Balance: ¥%.2f \n\n",account1.getName(),account1.getBalance());        System.out.print("Enter the withdrawal amount of account1: ");        withdrawalAmount = input.nextDouble();        account1.withdraw(withdrawalAmount);        System .out.printf("%s Balance: ¥%.2f \n\n",account1.getName(),account1.getBalance());        //account2 deposit & withdraw        System.out.print("Enter the deposit amount of account2: ");        depositAmount = input.nextDouble();        account2.deposit(depositAmount);        System.out.printf("%s Balance: ¥%.2f \n\n",account2.getName(),account2.getBalance());        System.out.print("Enter the withdrawal amount of account1: ");        withdrawalAmount = input.nextDouble();        account2.withdraw(withdrawalAmount);        System .out.printf("%s Balance: ¥%.2f \n\n",account2.getName(),account2.getBalance());        input.close();        System.exit(0);    }}
你可能感兴趣的文章
[LeetCode javaScript] 26. 删除排序数组中的重复项
查看>>
[LeetCode javaScript] 8. 字符串转换整数 (atoi)
查看>>
[LeetCode javaScript] 28. 实现strStr()
查看>>
cv2.error: OpenCV(3.4.2) c:\projects\opencv-python\opencv\modules\imgproc\src\color.hpp:25
查看>>
前端网页学习7(css背景属性)
查看>>
前端网页学习8(css三大特性:层叠性,继承性,优先级)
查看>>
前端网页学习9(css盒子)
查看>>
python学习8(列表)
查看>>
JavaScript学习(new1)
查看>>
http GET 和 POST 请求的优缺点、区别以及误区
查看>>
JVM的4种垃圾回收算法、垃圾回收机制
查看>>
什么是分布式事务
查看>>
常用的分布式事务解决方案
查看>>
设计模式:单例模式 (关于饿汉式和懒汉式)
查看>>
一致性Hash算法
查看>>
更新Navicat Premium 后打开数据库出现1146 - Table 'performance_schema.session_variables' doesn't exist
查看>>
安装rabbitmq时踩的坑
查看>>
2021-06-09数据库添加多条数据
查看>>
简单的JAVA小作品
查看>>
CMake下载
查看>>