IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

【Java】购物超市

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

小明去超市买东西,所有买到的东西都放在了购物车之中,最后到收银台一起结账。

package chapter6;


public class Job6 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        ShoppingCart ps = new ShoppingCart(2);
        ps.add(new Phone("iphone5",1,1000));
        ps.add(new Computer("huashuo",2,2000));

        ps.del("huashuo");
        ps.printCart();
        System.out.println(Shop.paymen(ps));
    }

    public static Commodity[] delete(int i, Commodity[] c)
    {
        Commodity[] cnew = new Commodity[c.length-1];
        for(int j=0;j<c.length-1;j++)
        {
            if(j<i)
            {
                cnew[j] = c[j];
            }
            else
            {
                cnew[j] = c[j+1];
            }

        }
        return cnew;
    }

}
interface Commodity
{
    public String getName();
    public int getAmount();
    public double getPrice();
}

class Phone implements Commodity
{
    private String name;
    private int amount;
    private double price;

    public Phone(String name, int amount, double price) {
        super();
        this.name = name;
        this.amount = amount;
        this.price = price;
    }

    public String getName() {
        return name;
    }

    public int getAmount() {
        return amount;
    }

    public double getPrice() {
        return price;
    }

}

class Computer implements Commodity
{
    private String name;
    private int amount;
    private double price;
    public Computer(String name, int amount, double price) {
        super();
        this.name = name;
        this.amount = amount;
        this.price = price;
    }
    public String getName() {
        return name;
    }
    public int getAmount() {
        return amount;
    }
    public double getPrice() {
        return price;
    }

}


class ShoppingCart
{
    private Commodity[] goods;
    private int foot;

    public ShoppingCart(int len)
    {
        if(len>0)
            this.goods = new Commodity[len];
        else 
            this.goods = new Commodity[1];
    }
    public boolean add(Commodity commodity)
    {
        if(this.foot<this.goods.length)
        {
            this.goods[this.foot] = commodity;
            this.foot++;
            return true;
        }
        else
        {
            return false;
        }
    }
    public boolean del(String name)
    {
        int t = 0;
        Commodity[] goodsnew = null;
        for(int i = 0;i<this.goods.length;i++)
        {
            if(this.goods[i]!=null)
            {
                if(this.goods[i].getName().indexOf(name)!=-1)
                {
                    goodsnew = Job6.delete(i, this.goods);
                    t = 1;
                }
            }
        }
        if(t==1)
        {
            this.goods = goodsnew;
            this.foot--;
            return true;
        }
        else
            return false;
    }

    public void printCart()
    {
        for(int i=0;i<this.goods.length;i++)
        {
            if(this.goods[i]!=null)
                System.out.println(goods[i].getName()+','+goods[i].getAmount()+','+goods[i].getPrice());
        }
    }
    public Commodity[] getGoods() {
        return goods;
    }
    public int getFoot() {
        return foot;
    }


}

class Shop
{
    public static  double paymen(ShoppingCart sc)
    {
        double sum  = 0;
        for(int i=0;i<sc.getGoods().length;i++)
        {
            sum += sc.getGoods()[i].getPrice() * sc.getGoods()[i].getAmount();
        }
        return sum;
    }

}






文章永久链接:https://tech.souyunku.com/?p=20035


Warning: A non-numeric value encountered in /data/wangzhan/tech.souyunku.com.wp/wp-content/themes/dux/functions-theme.php on line 1154
赞(82) 打赏



未经允许不得转载:搜云库技术团队 » 【Java】购物超市

IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码
IDEA2023.1.3破解,IDEA破解,IDEA 2023.1破解,最新IDEA激活码

评论 抢沙发

大前端WP主题 更专业 更方便

联系我们联系我们

觉得文章有用就打赏一下文章作者

微信扫一扫打赏

微信扫一扫打赏


Fatal error: Uncaught Exception: Cache directory not writable. Comet Cache needs this directory please: `/data/wangzhan/tech.souyunku.com.wp/wp-content/cache/comet-cache/cache/https/tech-souyunku-com/index.q`. Set permissions to `755` or higher; `777` might be needed in some cases. in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php:367 Stack trace: #0 [internal function]: WebSharks\CometCache\Classes\AdvancedCache->outputBufferCallbackHandler() #1 /data/wangzhan/tech.souyunku.com.wp/wp-includes/functions.php(5109): ob_end_flush() #2 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(303): wp_ob_end_flush_all() #3 /data/wangzhan/tech.souyunku.com.wp/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters() #4 /data/wangzhan/tech.souyunku.com.wp/wp-includes/plugin.php(470): WP_Hook->do_action() #5 /data/wangzhan/tech.souyunku.com.wp/wp-includes/load.php(1097): do_action() #6 [internal function]: shutdown_action_hook() #7 {main} thrown in /data/wangzhan/tech.souyunku.com.wp/wp-content/plugins/comet-cache/src/includes/traits/Ac/ObUtils.php on line 367