网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

java语言编写代码你好 java语言代码大全及其含义

谁会用JAVA语言写这个程序?感谢好心人写好发照片,谢谢!

我说过帮你完成的,以下是原创代码:

创新互联公司专业为企业提供栾川网站建设、栾川做网站、栾川网站设计、栾川网站制作等企业网站建设、网页设计与制作、栾川企业网站模板建站服务,10年栾川做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

package 商品系统;

import java.io.BufferedReader;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.FileWriter;

import java.io.IOException;

import java.util.Scanner;

public class SellSystem {

Goods[] goods=new Goods[1000];

int k;

public SellSystem() throws Exception{

for(int i=0;i1000;i++){goods[i]=new Goods();}

  read();

}

void addgoods(){

String id,name,price,num;

Scanner input=new Scanner(System.in);

System.out.printf("请输入商品编号:\n"氏笑);

id=input.nextLine();

System.out.printf("请输入商品名称\n");

name=input.nextLine();

System.out.printf("请输入商品价格:\n");

price=input.nextLine();

System.out.printf("请输入商品数量:\n");

num=input.nextLine();

goods[k]=new Goods(id,name,price,num);

k++;

write();

System.out.printf("\n商品添加成功!\n");

}

void deletegoods(String id)

{

int d=find(id);

if(d==-1)

System.out.printf("删除失侍核灶败,该商品编号不存在\n");

else{

for(int i=d;i=k;i++)

{

goods[d].id=goods[d+1].id;

goods[d].name=goods[d+1].name;

goods[d].price=goods[d+1].price;

goods[d].num=goods[d+1].num;

}

k--;

write();

}

// System.out.printf(d+"\n");

}

///////////////////////////////////////////////////////////////////////////////////

int find(String goodsId)

{

int index=-1;

for(int i=0;ik;i++)

{

//System.out.printf("\n"+goods[0].id);

if(goods[i].id.equals(goodsId))

{

index=i;

break;

}

}

return index;

}

/////////////////////////////////////////////////////////////////////////////////////

void write()

{

String temp="";

temp=k+" ";

for(int i=0;ik;i++){

temp+=goods[i].id+" "+goods[i].name+" "+goods[i].price+" "+goods[i].num+" ";

}

try {

FileWriter message=new FileWriter("老扮d:/商品信息.txt");

message.write(temp);

message.close();

} catch (IOException e) {

// TODO 自动生成的 catch 块

e.printStackTrace();

}

}

/////////////////////////////////////////////////////////

boolean read() throws IOException{

String temp="";

String[] strs=null;

boolean flag=true;

try {

FileReader message=new FileReader("d:/商品信息.txt");

BufferedReader reader = new BufferedReader(message);

temp=reader.readLine();

strs = temp.split (" ");

       k=Integer.parseInt(strs[0]);

for(int i=0;ik;i++){

for(int j=1;j=4;j++){

switch(j){

case 1:goods[i].id=strs[i*4+j];break;

case 2:goods[i].name=strs[i*4+j];break;

case 3:goods[i].price=strs[i*4+j];break;

case 4:goods[i].num=strs[i*4+j];break;

}

}

}

} catch (FileNotFoundException e) {

// TODO 自动生成的 catch 块

e.printStackTrace();

}

return flag;

}

///////////////////////////////////////////////////////////

void print(){

for(int i=0;ik;i++)

System.out.printf("商品编号:"+goods[i].id+"\n商品名称:"+goods[i].name+"\n商品价格:"+goods[i].price+"\n商品数量:"+goods[i].num+"\n----------\n");

}

//////////////////////////////////////////////////////////////////////////////////////

int findp(String price){

int index=-1;

for(int i=0;ik;i++){

if(goods[i].price.equals(price)){

System.out.printf("商品编号:"+goods[i].id+"\n商品名称:"+goods[i].name+"\n商品价格:"+goods[i].price+"\n商品数量:"+goods[i].num+"\n----------\n");

index=1;

}

}

return index;

}

////////////////////////////////////////////////////////////////////////////////

void change(String cid)

{

int j=find(cid);

while(true){

Scanner t=new Scanner(System.in);

System.out.printf("1.修改商品名称\n");

System.out.printf("2.修改商品价格\n");

System.out.printf("3.修改商品数量\n");

System.out.printf("请输入相应的序号进行操作:");

int select=t.nextInt();

switch(select){

case 1:

System.out.printf("修改名称为:");

Scanner w=new Scanner(System.in);

   goods[j].name=w.nextLine();

   System.out.printf("商品名称修改成功!\n");break;

case 2:

System.out.printf("修改价格为:");

   Scanner o=new Scanner(System.in);

       goods[j].price=o.nextLine();

       System.out.printf("商品价格修改成功!\n");break;

case 3:

System.out.printf("修改数量为:");

   Scanner l=new Scanner(System.in);

       goods[j].num=l.nextLine();

       System.out.printf("商品数量修改成功!\n");break;

 }

System.out.printf("按输入任意值返回继续修改,输入“0”退出修改\n");

Scanner qq=new Scanner(System.in);

int exit=qq.nextInt();

if(exit==0)break;

write();

}

}

//////////////////////////////////////////////

void menu(){

System.out.printf("商品管理系统\n");

System.out.printf("1.查询\n");

System.out.printf("2.添加\n");

System.out.printf("3.删除\n");

System.out.printf("4.修改\n");

System.out.printf("5.退出\n");

System.out.printf("请输入相应的序号进行操作:\n");

System.out.printf("------------------------------------\n");

Scanner a=new Scanner(System.in);

int choose1=a.nextInt();

int choose2;

String findid,p,q;

int n,i;

switch(choose1){

case 1:

System.out.printf("(1)全部查询\n");

System.out.printf("(2)编号查询\n");

System.out.printf("(3)价格查询\n");

System.out.printf("请输入相应的序号进行操作:");

choose2=a.nextInt();

if(choose2==1)print();

else if(choose2==2)

{

System.out.printf("请输入进行查询的商品编号:");

Scanner c=new Scanner(System.in);

findid=c.nextLine();

  n=find(findid);

  if(n!=-1)

  System.out.printf("商品编号:"+goods[n].id+"\n商品名称:"+goods[n].name+"\n商品价格:"+goods[n].price+"\n商品数量:"+goods[n].num+"\n");

  else System.out.printf("该商品编号不存在!\n");

}

else if(choose2==3){

Scanner d=new Scanner(System.in);

System.out.printf("请输入相应的价格:");

p=d.nextLine();

if(findp(p)==-1)System.out.printf("不存在该价格的商品信息!");

}

break;

case 2:addgoods();break;

case 3:

Scanner e=new Scanner(System.in);

System.out.printf("请输入要删除的商品编号:");

q=e.nextLine();

deletegoods(q);

System.out.printf("该商品已经被删除!\n");break;

case 4:System.out.printf("请输入需要修改的商品的对应编号:\n");

Scanner v=new Scanner(System.in);

change(v.nextLine());break;

}

}

//////////////////////////////////////////////////////////////////////////////////////

public static void main(String[] args) throws Exception{

SellSystem a=new SellSystem();

Scanner h=new Scanner(System.in);

int b;

while(true){

a.menu();

System.out.printf("输入任意值返回主菜单,输入0退出系统");

b=h.nextInt();

if(b==0)System.exit(0);

}

//System.out.printf(""+a.goods[0]);

}

}

//////////////////////////////////////////////////////////////////////////////////////////////

class Goods{

String id;

String name;

String price;

String num;

public Goods(String id,String name,String price,String num){

this.id=id;

this.name=name;

this.price=price;

this.num=num;

}

public Goods(){

this.id=null;

this.name=null;

this.price=null;

this.num=null;

}

}

附上部分效果图

好吧,就这样了,你自己测试一下吧,有问题可以联系我QQ459384320

输出你好用java语言编写代码怎么写

你空前盯是问斗和悔中hello world吗?

public Class MyClass {

public static void main() {

system.out.println("Hello World");

}

}


网站栏目:java语言编写代码你好 java语言代码大全及其含义
分享地址:http://bjjierui.cn/article/dsphjjh.html

其他资讯