Xiao Ming stroll the supermarket

Source: Internet
Author: User

Abstract class goods{
private String name;
private float price;
private int count;
Public Goods (String name,float price,int count) {
This.setname (name);
This.setprice (price);
This.setcount (count);
}
public void SetName (String name) {
This.name=name;
}
public void Setprice (float price) {
This.price=price;
}
public void SetCount (int count) {
This.count=count;
}
Public String GetName () {
return this.name;
}
public float GetPrice () {
return this.price;
}
public int GetCount () {
return this.count;
}
Public abstract String getlnfo ();
Public String Getlnfo1 () {
Return "Name:" +this.getname () + "unit Price:" +this.getprice () + "Quantity:" +this.getcount ();
}
}
Class Books extends goods{
Private String author;
Private String publish;
Public Books (String name,float price,int count,string author,string publish) {
Super (Name,price,count);
This.setauthor (author);
This.setpublish (publish);
}
public void Setauthor (String author) {
This.author=author;
}
Public String Getauthor () {
return this.author;
}
public void Setpublish (String publish) {
This.publish=publish;
}
Public String Getpublish () {
return this.publish;
}
Public String Getlnfo () {
Return "title:" +this.getname () + "unit Price:" +this.getprice () + "" +this.getauthor () + "Publisher:" +this.getpublish ()
+ "Quantity:" +this.getcount () + "Total Price:" +this.getprice () *this.getcount ();
}
Public String Getlnfo1 () {
Return "Name:" +this.getname () + "unit Price:" +this.getprice () + "Quantity:" +this.getcount ();
}
}
Class Cloths extends goods{
Private String title;
private String style;
Public cloths (String name,float price,int count,string title,string style) {
Super (Name,price,count);
This.settitle (title);
This.setstyle (style);
}
public void Settitle (String title) {
This.title=title;
}
Public String GetTitle () {
return this.title;
}
public void SetStyle (String style) {
This.style=style;
}
Public String GetStyle () {
return this.style;
}
Public String Getlnfo () {
Return "Name:" +this.getname () + "unit Price:" +this.getprice () +
"Brand:" +this.gettitle () + "style:" +this.getstyle () +
"Quantity:" +this.getcount () + "Total Price:" +this.getprice () *this.getcount ();
}
Public String Getlnfo1 () {
Return "Name:" +this.getname () + "unit Price:" +this.getprice () + "Quantity:" +this.getcount ();
}
}
Class shopcar{
Private goods[] Goods;
private int foot;
Public Shopcar (int len) {
if (len>0) {
This.goods=new Goods[len];
}else{
This.goods=new Goods[1];
}
}
Public boolean Add (Goods Goods) {
if (this.foot<this.goods.length) {
This.goods[this.foot]=goods;
this.foot++;
return true;
}else{
return false;
}
}
Public goods[] GetContent () {
return this.goods;
}
Public goods[] Search (String keyWord) {
Goods G[]=null;
int count=0;
for (int i=0;i<this.goods.length;i++) {
if (this.goods[i]!=null) {
if (This.goods[i].getname (). IndexOf (KeyWord)!=-1) {
count++;
}
}
}
G=new Goods[count];
int f=0;
for (int i=0;i<this.goods.length;i++) {
if (this.goods[i]!=null) {
if (This.goods[i].getname (). IndexOf (KeyWord)!=-1) {
G[f]=this.goods[i];
f++;
}
}
}
return g;
}
}
public class Mai {

/**
* @param args
*/
public static void Main (string[] args) {
TODO auto-generated Method Stub
Shopcar sc=new Shopcar (6);
Sc.add (New Books ("xxx", 69.9f,1, "SAS", "ZX"));
Sc.add (New Books ("Asdf", 79.9f,5, "Fdgd", "qwe"));
Sc.add (New Books ("DG", 69.9f,3, "ASD", "DFG"));
Sc.add (New Cloths ("Ghj", 69.9f,2, "Rter", "Zxcs"));
Sc.add (New Cloths ("ZFG", 69.9f,2, "ASFD", "DFG"));
Sc.add (New Cloths ("QW", 69.9f,1, "FDG", "sad"));
System.out.println ("========= has bought a list of goods =========");
Print1 (Sc.getcontent ());
System.out.println ("========= for product Details =========");
Try
{
Print (Sc.search (args[0));
}
catch (Exception e) {
SYSTEM.OUT.PRINTLN ("No input to query for item or input error:" + "format: \njava Test product name (or any character in the product name)");
}
}
public static void Print1 (Goods goods[]) {
for (int i=0;i<goods.length;i++) {
System.out.println (Goods[i].getlnfo1 ());
}
}
public static void print (Goods goods[]) {
for (int i=0;i<goods.length;i++) {
System.out.println (Goods[i].getlnfo ());
}
}
}

Xiao Ming stroll the supermarket

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.