• 实验报告2


    题一

    package test2;
    
    public class Rectangle {
    	private double width,height;
    	private String color;
    	public Rectangle(double width,double height,String color){
    		this.setWidth(width);
    		this.setHeight(height);
    		this.setColor(color);
    	}
    
    	public double getWidth(){
    		return width;
    	}
    	public void setWidth(double w){
    		width = w;
    	}
    	public double getHeight(){
    		return height;
    	}
    	public void setHeight(double h){
    		height = h;
    	}
    	public String getColor(){
    		return color;
    	}
    	public void setColor(String c){
    		color = c;
    	}		
    	public void getArea(){
    		double area=0;
    		area=this.height*this.width;
    		System.out.println(area);
    		}
    		public void getLength(){
    		double length;
    		length=width+height+width+height;
    		 System.out.println(length);
    		 }
    }
    package test2;
    
       public class demo{
      public static void main (String args[]){
    	 Rectangle rec=new Rectangle(12.00,14.00,"红色");
    	 rec.getArea();
    	 rec.getLength();
    	 rec.getColor();
    	 System.out.println(rec.toString());
    }
    }
    

    实验二

    package test1;
    
    import java.util.Scanner;
    
    import test1.Account;
    public class Account {
        public int id;
        public int password;
        public String name;
        public int money;
        
                     public Account(int id, int password, String name, int money) {
            this.id = id;
            this.password = password;
            this.name = name;
            this.money = money;
        }
        public void show(){
            System.out.println("账户:" + id);
            System.out.println("姓名:" + name);
            System.out.println("余额:" + money);
        }
        public void takeMoney(){
            while(true){
                Scanner sc = new Scanner(System.in);
                System.out.println("输入密码");
                int pass = sc.nextInt();
                if(pass == password){
                    System.out.println("取款金额:");
                    int withdrawals = sc.nextInt();
                    if(withdrawals <= money) {
                        money= money-withdrawals;
                        System.out.println("余额为:" + money);
                    }
                                                                    else {
                        System.out.println("当前余额不足" );
                    }
                    break;
                }
                                                    else{
                    System.out.println("密码错误,请重新输入!");
                }
            }
        }
        
        public void saveMoney(int moneys){    
            money = money+moneys;
            System.out.println("此次存款为:" + moneys);
            System.out.println("账户余额为:" + money);
        }
        
        public static void main(String[] args) {
            Account acc = new Account(10010,123456,"陈果",0);
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入需要执行的操作");
            System.out.println("1银行账户信息");
            System.out.println("2取款操作");
            System.out.println("3存款操作");
            System.out.println("4退出系统");
            int s = sc.nextInt();
                switch(s) {
                case 1:
                    System.out.println("银行账户");
                    acc.show();
                    break;
                case 2:
                    System.out.println("取款");
                    acc.takeMoney();
                    break;
                case 3:
                    System.out.println("存款");
                    acc.saveMoney(1000);
                    break;
                case 4:
                    System.exit(0);
                    break;
                }
        }
     
    }
    

  • 相关阅读:
    TensorFlow 学习(4)——MNIST机器学习进阶
    TensorFlow 学习(3)——MNIST机器学习入门
    TensorFlow 学习(2)——正式起步
    TensorFlow 学习(1)——第一个程序:线性回归
    OpenCV学习笔记(15)——更多的轮廓函数
    OpenCV学习笔记(14)——轮廓的性质
    OpenCV学习笔记(13)——轮廓特征
    OpenCV学习笔记(12)——OpenCV中的轮廓
    机器学习
    机器学习- Attention Model结构解释及其应用
  • 原文地址:https://www.cnblogs.com/swaggy89/p/11549160.html
Copyright © 2020-2023  润新知