| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2185 人关注过本帖
标题:大佬,求帮助
只看楼主 加入收藏
yellowtao
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2018-11-26
结帖率:0
收藏
已结贴  问题点数:20 回复次数:5 
大佬,求帮助
图片附件: 游客没有浏览图片的权限,请 登录注册
2018-11-26 10:44
a511528
Rank: 2
等 级:论坛游民
帖 子:3
专家分:17
注 册:2018-11-26
收藏
得分:7 
好难哦,做求不出来,黄涛我都没得法的
2018-11-26 15:15
纵横阳仔
Rank: 7Rank: 7Rank: 7
来 自:自学成才的火星人儿
等 级:贵宾
威 望:26
帖 子:147
专家分:698
注 册:2016-10-20
收藏
得分:7 
采用面向对象的思路:
创建一个电脑对象,包含四个子类对象(cpu,显卡...),实现对应的获取总价,排序,获取价格区间电脑信息等方法;
2018-11-26 17:48
豆豆的滴
Rank: 9Rank: 9Rank: 9
来 自:湖南
等 级:贵宾
威 望:33
帖 子:368
专家分:1087
注 册:2018-5-7
收藏
得分:7 
自己先试试相信你能行
2018-11-26 19:08
纵横阳仔
Rank: 7Rank: 7Rank: 7
来 自:自学成才的火星人儿
等 级:贵宾
威 望:26
帖 子:147
专家分:698
注 册:2016-10-20
收藏
得分:0 
先自己写写,再看吧
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc =new Scanner(System.in);
        String num = sc.nextLine();
        int cpus =Integer.parseInt(num.split(" ")[0]);
        int memoryChipss =Integer.parseInt(num.split(" ")[1]);
        int mainBorads =Integer.parseInt(num.split(" ")[2]);
        int graphicsCards =Integer.parseInt(num.split(" ")[3]);
        List<CPU> cpulist = new ArrayList<>();
        for (int i = 0;i<cpus;i++) {
            cpulist.add(new CPU(sc.nextLine()));
        }
        List<MemoryChips> memoryChipsList = new ArrayList<>();
        for (int i = 0;i<memoryChipss;i++) {
            memoryChipsList.add(new MemoryChips(sc.nextLine()));
        }
        List<MainBorad> mainBoradList = new ArrayList<>();
        for (int i = 0;i<mainBorads;i++) {
            mainBoradList.add(new MainBorad(sc.nextLine()));
        }
        List<GraphicsCard> graphicsCardList = new ArrayList<>();
        for (int i = 0;i<graphicsCards;i++) {
            graphicsCardList.add(new GraphicsCard(sc.nextLine()));
        }
        List<Computer> computerlist = new ArrayList<>();
        for (CPU cpu : cpulist) {
            for (MemoryChips memoryChips : memoryChipsList) {
                for (MainBorad mainBorad : mainBoradList) {
                    for (GraphicsCard graphicsCard : graphicsCardList) {
                        computerlist.add(new Computer(cpu,memoryChips,mainBorad,graphicsCard));
                    }
                }
            }
        }
        List<Computer> list = new ArrayList<>(computerlist);
        Collections.sort(list);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int i = 1;
        for(Computer computer:list){
            if(computer.getPrice()>=a&&computer.getPrice()<=b){
                System.out.println(computer.toString(i));
                i++;
            }
        }
        
        
    }
}

class Computer implements Comparable<Computer> {
   
    CPU cpu;
    MemoryChips memoryChips;
    MainBorad mainBorad;
    GraphicsCard graphicsCard;
    int price ;
    public Computer(CPU cpu, MemoryChips memoryChips, MainBorad mainBorad, GraphicsCard graphicsCard) {
        this.cpu = cpu;
        this.memoryChips = memoryChips;
        this.mainBorad = mainBorad;
        this.graphicsCard = graphicsCard;
    }
    public String toString(int i) {
        String  s= i+" "+cpu.brand+"-"+cpu.model+"-"+cpu.frequency
                +" "+memoryChips.brand+"-"+memoryChips.model+"-"+memoryChips.capacity
                +" "+mainBorad.brand+"-"+mainBorad.model
                +" "+graphicsCard.brand+"-"+graphicsCard.model+"-"+graphicsCard.capacity
                +" "+getPrice();
        return s;
    }
    int getPrice(){
        return cpu.price+memoryChips.price+mainBorad.price+graphicsCard.price;
    }
    @Override
    public int compareTo(Computer o) {
        return this.getPrice() -o.getPrice();
    }
   
   
}
class CPU{
    CPU(String s){
        this.brand = s.split(" ")[0];
        this.model = s.split(" ")[1];
        this.frequency = s.split(" ")[2];
        this.price = Integer.valueOf(s.split(" ")[3]);
    }
    String brand;//品牌
    String model;//型号
    String frequency;//频率
    int price;//品牌
}
class MemoryChips{//内存条
    MemoryChips(String s){
        this.brand = s.split(" ")[0];
        this.model = s.split(" ")[1];
        this.capacity = s.split(" ")[2];
        this.price = Integer.valueOf(s.split(" ")[3]);
    }
    String brand;//品牌
    String model;//型号
    String capacity;//容量
    int price;//品牌
}
class MainBorad{//主板
    MainBorad(String s){
        this.brand = s.split(" ")[0];
        this.model = s.split(" ")[1];
        this.price = Integer.valueOf(s.split(" ")[2]);
    }
    String brand;//品牌
    String model;//型号
    int price;//品牌
}
class GraphicsCard{//显卡
    GraphicsCard(String s){
        this.brand = s.split(" ")[0];
        this.model = s.split(" ")[1];
        this.capacity = s.split(" ")[2];
        this.price = Integer.valueOf(s.split(" ")[3]);
    }
    String brand;//品牌
    String model;//型号
    String capacity;//容量
    int price;//品牌
}


[此贴子已经被作者于2018-11-27 10:20编辑过]

2018-11-26 19:15
yellowtao
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2018-11-26
收藏
得分:0 
回复 5楼 纵横阳仔
非常感谢😄
2018-11-28 18:39
快速回复:大佬,求帮助
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.027264 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved