手机计数

这是一个简单的Java程序,实现了一个手机销售管理系统的功能。包括手机类(Mobile)的定义,包含品牌、数量、单价等属性及相应的方法。系统提供显示手机信息、按单价排序和查询特定品牌手机的功能。用户通过命令行输入选择操作,程序会根据输入执行对应功能。
摘要由CSDN通过智能技术生成
package Abcd;

import java.util.Scanner;
class Mobile{
	private int num;
	private String brand;
	private double amount;
	private double price;
	private double all;
	public Mobile() {
		
	}
	public Mobile(int num,String brand,double amount,double price,double all) {
		this.num=num;
		this.brand=brand;
		this.amount=amount;
		this.price=price;
		this.all=all;
	}
	public int getNum() {
		return num;
	}
	public void setNum(int num) {
		this.num = num;
	}
	public String getBrand() {
		return brand;
	}
	public void setBrand(String brand) {
		this.brand = brand;
	}
	public double getAmount() {
		return amount;
	}
	public void setAmount(double amount) {
		this.amount = amount;
	}
	public double getPrice() {
		return price;
	}
	public void setPrice(double price) {
		this.price = price;
	}
	public double getAll() {
		return all;
	}
	public void setAll(double all) {
		this.all = all;
	}
	public void printMobile() {
		
		System.out.println(this.num+"	"+this.brand+"	"+this.amount+"	"+this.price+"	"+this.all);
	}
	public static void printMb() {
		System.out.println("      		手机信息                       ");
		System.out.println("序号 	手机品牌	数量	单价	小计");
	}
	public static void printMu() {
		System.out.println("**********手机销售管理**********");
		System.out.println("----1.显示---------2.按单价排序--");
		System.out.println("----3.查询---------0.退出--");
		System.out.println("请输入功能代码(0~3)");
	}
	
}
public class Demo13 {



	public static void main(String[]args) {
		Mobile phone[]=new Mobile[4];
		phone[0]=new Mobile(1,"华为",10,3500,35000);
		phone[1]=new Mobile(2,"小米",20,2100,42000);
		phone[2]=new Mobile(3,"VIVO",17,2800,47600);
		phone[3]=new Mobile(4,"OPPO",8,1355,10840);
		Mobile.printMu();
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		switch(a) {
		case(1):{
			Mobile.printMb();
			for(int i=0;i<phone.length;i++) {
				phone[i].printMobile();
			}
			break;
		}
		case(2):{
			Mobile m=new Mobile();
			for(int j=1;j<4;j++)
				for(int k=0;k<4;k++)
				{
					if(phone[j].getPrice()<phone[k].getPrice())
					{
						m=phone[k];
						phone[k]=phone[j];
						phone[j]=m;
					}
					
				}
			for(int i=0;i<phone.length;i++) {
				phone[i].printMobile();
			}
			
			break;
		}
		case(3):{
			Scanner scan1=new Scanner(System.in);
			System.out.println("请输入需要查寻手机的名称:");
			String str=scan1.next();
			for(int i=0;i<4;i++) {
				if(phone[i].getBrand().equals(str))
				phone[i].printMobile();	
			}
			break;
		}
		default:{
			System.exit(0);
			break;
		}

		}
	}
}

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值