家庭收支记账软件Java

家庭收支记账软件

在这里插入图片描述

在这里插入图片描述
利用基础语法

无调用方法版

import java.util.Scanner;

    public class HomeWork01{
        private static int sum=10000;
        private static String info="";
        private static boolean flag=true;
        public static void main(String[] args) {
            int in = 0;
            int out = 0;
            String note="";
            Scanner scanner = new Scanner(System.in);
            do {
                System.out.println("------------家庭收支记账软件-----------");
                System.out.println("              1.收支明细");
                System.out.println("              2.登记收入");
                System.out.println("              3.登记开支");
                System.out.println("              4.退   出");
                System.out.println();
                System.out.print("              请输入1-4:");
                int n = scanner.nextInt();
                if (n == 1) {
                    System.out.println("近期开支如下:");
                    System.out.println(info);
                    System.out.println("余额:"+sum);
                }
                if (n == 2) {
                    System.out.println("本次收入金额:");
                    in = scanner.nextInt();
                    System.out.println("本次收入说明:");
                    note = scanner.next();
                    sum+=in;
                    info+="收入金额:"+in+"收入说明:"+note+"\n";
//                    InCome(in, note);
                }
                if (n == 3) {
                    System.out.println("本次支出金额:");
                    out=scanner.nextInt();
                    System.out.println("本次支出说明:");
                    note=scanner.next();
                    sum-=out;
                    info+="支出金额:"+out+"支出说明:"+note+"\n";
//                    pay(out, note);
                }
                if(n==4){
                    System.out.print("是否退出(Y/N):");
                        String t = scanner.next();
                        if (t.equals("Y")){
                            flag = false;
                            break;}
                        else if (t.equals("N"))
                            break;
                        else
                            System.out.print("输入错误,请重新输入:");
                }
            }while(flag);//if(n==4)&&t==Y结束循环
        }

//        public static void InCome(int in,String note){
//            sum+=in;
//            info+="收入金额:"+in+"收入说明:"+note+"\n";
//        }
//        public static void pay(int out,String note){
//            sum-=out;
//            info+="支出金额:"+out+"支出说明:"+note+"\n";
//        }
    }


调用同包方法版

import java.awt.*;
import java.util.Scanner;

    public class HomeWork01 {
        protected static String info;
        protected static int sum=10000;
        protected static boolean flag=true;
        public static void main(String[] args) {
            int in = 0;
            int out = 0;
            String note = "";
            Scanner scanner = new Scanner(System.in);
            do {
                Use.Menu();
                int n = scanner.nextInt();
                if (n == 1) {
                    System.out.println("近期开支如下:");
                    System.out.println(info);
                    System.out.println("余额:" + sum);
                }
                if (n == 2) {
                    System.out.println("本次收入金额:");
                    in = scanner.nextInt();
                    System.out.println("本次收入说明:");
                    note = scanner.next();
                    Use.InCome(in, note);
                }
                if (n == 3) {
                    System.out.println("本次支出金额:");
                    out = scanner.nextInt();
                    System.out.println("本次支出说明:");
                    note = scanner.next();
                    Use.pay(out, note);
                }
                if (n == 4) {
                    System.out.print("是否退出(Y/N):");
                    String t = scanner.next();
                    Use.Exit(t);
                }
            } while (flag);//if(n==4)&&t==Y结束循环
        }
    }
import java.util.Scanner;

public class Use {
//    private static int sum=10000;
//    private static String info="";
//    private static boolean flag=true;
    Scanner scanner = new Scanner(System.in);
    public static void Menu() {//调用主菜单
        System.out.println("------------家庭收支记账软件-----------");
        System.out.println("              1.收支明细");
        System.out.println("              2.登记收入");
        System.out.println("              3.登记开支");
        System.out.println("              4.退   出");
        System.out.println();
        System.out.print("              请输入1-4:");
    }

    public static void Sum() {//余额及开销总数据
        System.out.println("近期开支如下:");
        System.out.println(HomeWork01.info);
        System.out.println("余额:"+HomeWork01.sum);
    }
    public static void InCome(int in,String note){
        HomeWork01.sum+=in;
        HomeWork01.info+="收入金额:"+in+"收入说明:"+note+"\n";
    }
    public static void pay(int out,String note){
        HomeWork01.sum-=out;
        HomeWork01.info+="支出金额:"+out+"支出说明:"+note+"\n";
    }

    public static void Exit(String t) {
        if (t.equals("Y")){
            HomeWork01.flag = false;
            }
        else
            System.out.print("输入错误,请重新输入:");
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Mr. Rabbit.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值