-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
212 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package edu.xatu; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
import java.io.IOException; | ||
|
||
public class Canvas extends JPanel {//画布 | ||
private Interface anInterface=null; | ||
Image beijing; | ||
|
||
{ | ||
try { | ||
beijing= GameUtil.getImage("tupian/背景.png"); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
@Override | ||
public void paint(Graphics g){ | ||
super.paint(g); | ||
g.drawImage(beijing,0,0,null); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package edu.xatu; | ||
|
||
public class Flower { | ||
private String name; | ||
private int price; | ||
private int number; | ||
|
||
public Flower(String name, int price, int number) { | ||
this.name = name; | ||
this.price = price; | ||
this.number = number; | ||
} | ||
@Override | ||
public String toString() { | ||
return "Flower{" + "name='" + name + '\'' + ", price=" + price + ", number=" + number + '}'; | ||
} | ||
public String getName() { | ||
return name; | ||
} | ||
public int getPrice() { | ||
return price; | ||
} | ||
public int getNumber() { | ||
return number; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package edu.xatu; | ||
|
||
import javax.imageio.ImageIO; | ||
import java.awt.*; | ||
import java.awt.image.BufferedImage; | ||
import java.io.IOException; | ||
import java.net.URL; | ||
|
||
public class GameUtil { | ||
private GameUtil(){ | ||
|
||
} | ||
|
||
/* | ||
*讲想画的图片的路径传进去 | ||
* */ | ||
|
||
public static Image getImage(String path) throws IOException { | ||
BufferedImage bi=null; | ||
URL u=GameUtil.class.getClassLoader().getResource(path); | ||
bi= ImageIO.read(u); | ||
return bi; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package edu.xatu; | ||
|
||
import javax.swing.*; | ||
import java.awt.*; | ||
import java.awt.event.ActionEvent; | ||
import java.awt.event.ActionListener; | ||
import java.io.IOException; | ||
|
||
public class Interface extends JFrame {//容器 | ||
Image beijing; | ||
|
||
{ | ||
try { | ||
beijing= GameUtil.getImage("tupian/背景.png"); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
@Override | ||
public void paint(Graphics g){ | ||
super.paint(g); | ||
g.drawImage(beijing,10,20,null); | ||
} | ||
public Interface(){ | ||
super("花店管理"); | ||
this.setSize(500,667);//设置界面大小 | ||
this.setLocation(650,130);//设置初始位置 | ||
this.setVisible(true);//显示窗口 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package edu.xatu; | ||
import java.util.Scanner; | ||
|
||
public class Main { | ||
|
||
public static void main(String[] args) { | ||
Flower [] a=new Flower[5]; | ||
Method method =new Method(); | ||
Interface inc=new Interface(); | ||
Scanner in=new Scanner(System.in); | ||
// for (int i=0;i<5;i++){ | ||
// System.out.println("请依次输入花的名称,价格,数量"); | ||
// Flower x=new Flower(in.next(),in.nextInt(),in.nextInt()); | ||
// a[i]=x; | ||
// } | ||
/* | ||
* 为了方便测试,我直接给赋值 | ||
*/ | ||
a[0]=(new Flower("菊花",27,35)); | ||
a[1]=(new Flower("兰花",25,37)); | ||
a[2]=(new Flower("梅花",22,67)); | ||
a[3]=(new Flower("紫罗兰",35,62)); | ||
a[4]=(new Flower("风信子",56,23)); | ||
while (true) { | ||
System.out.println("\t\t\t\t\t\t****************************************"); | ||
System.out.println("\t\t\t\t\t\t请输入需要选择的功能"); | ||
System.out.println("\t\t\t\t\t\t1:统计并输出鲜花的总价格,平均价格,最高价和最低价"); | ||
System.out.println("\t\t\t\t\t\t2:按照价格降序排序并输出"); | ||
System.out.println("\t\t\t\t\t\t3:统计高于平均价格和低于平均价格的鲜花数量"); | ||
System.out.println("\t\t\t\t\t\t4:输入鲜花名称查询商品的价格和数量"); | ||
System.out.println("\t\t\t\t\t\t****************************************"); | ||
int i=in.nextInt(); | ||
if (i==1) | ||
method.calculation(a); | ||
else if (i==2) | ||
method.sort(a); | ||
else if (i==3) | ||
method.statistics(a); | ||
else if (i==4) | ||
method.query(a); | ||
System.out.println("\t\t\t\t****************************************"); | ||
System.out.println("\t\t\t\t继续使用菜单请输入0"); | ||
System.out.println("\t\t\t\t****************************************"); | ||
i=in.nextInt(); | ||
if (i!=0) | ||
break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package edu.xatu; | ||
|
||
import java.util.Scanner; | ||
|
||
public class Method { | ||
private double ag; | ||
Scanner in=new Scanner(System.in); | ||
public void calculation(Flower[] a){ | ||
int total=0,max=0,min=a[0].getPrice(); | ||
double average=0.0; | ||
for (int i=0;i<5;i++){ | ||
average+=a[i].getPrice(); | ||
total+=(a[i].getNumber()*a[i].getPrice()); | ||
if (max<a[i].getPrice()) { | ||
max = a[i].getPrice(); | ||
}else | ||
if (min>a[i].getPrice()) { | ||
min = a[i].getPrice(); | ||
} | ||
} | ||
average=average/5; | ||
this.ag=average; | ||
System.out.println("它的总价格:"+total+"平均价格:"+average+"最高价:"+max+"最低价:"+min); | ||
}//统计价格 | ||
public void sort(Flower[] a){ | ||
int leng=a.length-1; | ||
for(int i =0;i<leng;i++) { | ||
for(int j=0;j<leng-i;j++) { | ||
if (a[j].getPrice()<a[j+1].getPrice()) { | ||
Flower x = null; | ||
x=a[j]; | ||
a[j]=a[j+1]; | ||
a[j+1]=x; | ||
} | ||
} | ||
} | ||
for (int i=0;i<a.length;i++){ | ||
System.out.println(a[i]); | ||
} | ||
}//排序 | ||
public void statistics(Flower[] a){ | ||
int high=0,low=0; | ||
for (int i=0;i<a.length;i++){ | ||
if (a[i].getPrice()<this.ag) | ||
low+=a[i].getNumber(); | ||
if (a[i].getPrice()>this.ag) | ||
high+=a[i].getNumber(); | ||
} | ||
System.out.println("高于平均价格的数量:"+high+"低于平均价格的数量:"+low); | ||
}//统计数量 | ||
public void query(Flower[] a){ | ||
System.out.println("请输入要查询的花的名字"); | ||
String name=in.nextLine(); | ||
for (int i=0;i<a.length;i++){ | ||
if (a[i].getName().equals(name)) | ||
System.out.println("它的价格为:"+a[i].getPrice()+"它的数量为:"+a[i].getNumber()); | ||
} | ||
}//查询 | ||
} |