作业1:实现一个数字加密器,加密规则是:    加密结果 = (整数*10+5)/2 + 3.14159,加   密结果仍为一整数。

详细代码:

package com.bbb.Work.cc;

import java.util.Scanner;

public class W1 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
     Scanner sc=new Scanner(System.in);
     System.out.println("请输入一个是数字:");
     int d=sc.nextInt();
     int result=(d*10+5)/2+(int)3.14159;
     System.out.println(result);
    }

}

运行截图:

一只死宅的Java作业(1)

作业二:

训练要点: 运算符(*、=)的使用 从控制台输出信息 需求说明: 用户可以享受购物8折的优惠,请计算实际消费金额

实现思路:

1、创建Java类Pay

2、在Pay.java文件中声明变量存储信息

3、计算总金额 难点指导: 消费总额 = 各商品的消费金额之和 * 折扣

作业三:

需求说明: 结算时打印购物小票 计算此次购物获得的会员积分

作业四:

训练要点: 运算符(%、/)的使用 使用Scanner类接收用户输入

需求说明: 商场推出幸运抽奖活动 根据抽奖规则计算会员卡号各位数字之和

实现思路:

1、接收输入的会员卡号

2、分解获得各位数字

3、计算各位数字之和 难点指导: 分解获得各位数字

作业5:

需求说明: 从控制台输入基本工资,并计算输出实领工资

详细代码:(估计是我吃多了  闲的  把后面四个作业合到一起写了  而且还好像写错了)

package com.gump.buy;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Buy {

    public static final double Discount = 0.8;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        List<Goods> goodsList = new ArrayList<>();
        goodsList.add(new Goods("T恤", 245));
        goodsList.add(new Goods("网球鞋", 570));
        goodsList.add(new Goods("网球拍", 320));
        goodsList.add(new Goods("乒乓球", 10));
        goodsList.add(new Goods("足球", 100));
        goodsList.add(new Goods("篮球", 120));

        List<GoodsItem> goodsItemList = new ArrayList<>();

        while (true) {
            for (int i = 0; i < goodsList.size(); i++) {
                Goods goods = goodsList.get(i);
                System.out.printf("%d.\t%-10s\t¥%.2f\r\n", i + 1, goods.getName(), goods.getPrice());
            }
            System.out.printf("请选择要购买的商品(输入0结束选择):");
            int idx = scanner.nextInt();
            if (idx == 0 || idx > goodsList.size()) {
                break;
            }
            Goods goods = goodsList.get(idx - 1);

            System.out.printf("请输入要购买的%s数量:", goods.getName());
            int count = scanner.nextInt();
            goodsItemList.add(new GoodsItem(goods, count));
        }
        System.out.println();

        double totalMoney = 0;
        System.out.print("**************************消费单**************************\r\n");
        System.out.printf("%-10s\t%-10s\t%-10s\t%-10s\r\n", "购买物品", "单价", "个数", "金额");
        for (int i = 0; i < goodsItemList.size(); i++) {
            GoodsItem item = goodsItemList.get(i);
            double money = item.getGoods().getPrice() * item.getCount();
            System.out.printf("%-10s\t¥%-10.2f\t%-10d\t¥%-10.2f\r\n", item.getGoods().getName(),
                    item.getGoods().getPrice(), item.getCount(), money);
            totalMoney += money;
        }
        totalMoney *= Discount;
        System.out.print("**********************************************************\r\n\r\n");

 

        System.out.printf("%-10s\t%.1f\r\n", "折扣:", Discount * 10);
        System.out.printf("%-10s\t¥%.2f\r\n", "消费总金额:", totalMoney);

        double payMoney = 0;
        while (true) {
            System.out.print("请输入交费金额:");
            payMoney = scanner.nextDouble();
            if (payMoney < totalMoney) {
                System.out.println("交费金额不足");
            } else {
                break;
            }
        }

        System.out.printf("%-10s\t¥%.2f\r\n", "找钱:", payMoney - totalMoney);

        scanner.close();
    }

}

package com.bbb.Work.cc;


public class Lucky {
 public static int l=Buy.q/1000;
 public static int m=Buy.q/100%10;
 public static int n=Buy.q/10%10;
 public static int o=Buy.q%10;
 public static int p=l+m+n+o;
  
}

package com.bbb.Work.cc;

public class Pay {
    static double shirt=245;
    static double shoes=570;
    static double pat=320;
    static double zk=0.8;
    static double zall=(shirt*Buy.shirtnum+shoes*Buy.shoesnum+pat*Buy.patnum)*zk;
}

package com.bbb.Work.cc;

public class salary {
  static double wj=1200.0;
  static double fz=750.0;
  static double xs=Buy.s+wj+fz;

}
一只死宅的Java作业(1)

下面是大佬写的 (只有作业2和3的    我还有很多要学习的东西)

package com.gump.buy;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Buy {

    public static final double Discount = 0.8;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        List<Goods> goodsList = new ArrayList<>();
        goodsList.add(new Goods("T恤", 245));
        goodsList.add(new Goods("网球鞋", 570));
        goodsList.add(new Goods("网球拍", 320));
        goodsList.add(new Goods("乒乓球", 10));
        goodsList.add(new Goods("足球", 100));
        goodsList.add(new Goods("篮球", 120));

        List<GoodsItem> goodsItemList = new ArrayList<>();

        while (true) {
            for (int i = 0; i < goodsList.size(); i++) {
                Goods goods = goodsList.get(i);
                System.out.printf("%d.\t%-10s\t¥%.2f\r\n", i + 1, goods.getName(), goods.getPrice());
            }
            System.out.printf("请选择要购买的商品(输入0结束选择):");
            int idx = scanner.nextInt();
            if (idx == 0 || idx > goodsList.size()) {
                break;
            }
            Goods goods = goodsList.get(idx - 1);

            System.out.printf("请输入要购买的%s数量:", goods.getName());
            int count = scanner.nextInt();
            goodsItemList.add(new GoodsItem(goods, count));
        }
        System.out.println();

        double totalMoney = 0;
        System.out.print("**************************消费单**************************\r\n");
        System.out.printf("%-10s\t%-10s\t%-10s\t%-10s\r\n", "购买物品", "单价", "个数", "金额");
        for (int i = 0; i < goodsItemList.size(); i++) {
            GoodsItem item = goodsItemList.get(i);
            double money = item.getGoods().getPrice() * item.getCount();
            System.out.printf("%-10s\t¥%-10.2f\t%-10d\t¥%-10.2f\r\n", item.getGoods().getName(),
                    item.getGoods().getPrice(), item.getCount(), money);
            totalMoney += money;
        }
        totalMoney *= Discount;
        System.out.print("**********************************************************\r\n\r\n");

        System.out.printf("%-10s\t%.1f\r\n", "折扣:", Discount * 10);
        System.out.printf("%-10s\t¥%.2f\r\n", "消费总金额:", totalMoney);

        double payMoney = 0;
        while (true) {
            System.out.print("请输入交费金额:");
            payMoney = scanner.nextDouble();
            if (payMoney < totalMoney) {
                System.out.println("交费金额不足");
            } else {
                break;
            }
        }

        System.out.printf("%-10s\t¥%.2f\r\n", "找钱:", payMoney - totalMoney);

        scanner.close();
    }

}

package com.gump.buy;

public class Goods {

    private String name;

    private double price;

    public Goods(String name, double price) {
        this.name = name;
        this.price = price;
    }

    public String getName() {
        return name;
    }

    public double getPrice() {
        return price;
    }
}

package com.gump.buy;

public class GoodsItem {

    private Goods goods;

    private int count;

    public GoodsItem(Goods goods, int count) {
        this.goods = goods;
        this.count = count;
    }

    public Goods getGoods() {
        return goods;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

}
大佬的运行截图:

一只死宅的Java作业(1)

相关文章:

  • 2021-11-10
  • 2021-10-09
  • 2022-12-23
  • 2021-08-20
  • 2021-10-27
  • 2021-06-14
  • 2021-04-21
猜你喜欢
  • 2021-12-24
  • 2021-10-23
  • 2021-06-06
  • 2021-06-12
  • 2021-06-13
  • 2021-06-14
  • 2021-08-28
相关资源
相似解决方案