@[TOC] Supermarket shopping program design

<> Task description
When shopping , If the goods purchased are available in the supermarket , It indicates that the shopper has bought a commodity , Otherwise, I didn't buy anything .
<> Realization idea

The supermarket shopping program contains goods , Supermarkets and shoppers are three objects .
First, define the name attribute and function attribute of three objects (get Method acquisition ,set Method assignment ), Secondly, define selling and shopping methods , Finally, all operations are implemented in the main method .

<> one ,Product Commodity category
// Commodity category public class Product { // Define product name private String proName; //get method public
StringgetProductName() { return proName; } //set method public void setProduct(
String proName) { this.proName = proName; } }
<> two ,Supermarket Supermarket
// Supermarket public class Supermarket { //1. Define supermarket name , Setting method private String supermaketName;
public String getSupermaketName() { return supermaketName; } public void
setSupermaketName(String supermaketName) { this.supermaketName = supermaketName;
} //2. Define shelf array private Product[] productArr; public Product[] getProductArr() {
return productArr; } public void setProductArr(Product[] productArr) { this.
productArr= productArr; } //3. Selling method Product sell(String name) {// Pass in the name of the product to be purchased for(
int i=0; i<productArr.length; i++) {// Traverse commodity array if(productArr[i].getProductName()==
name) { return productArr[i]; } } return null; } }
<> three ,Person Shopper category
// Shopper category public class Person { //1. Define person's name private String personName; public String
getPersonName() { return personName; } public void setPersonName(String
personName) { this.personName = personName; } //2. Purchase method Product shopping(
Supermarket market,String name) {// Incoming supermarket and trade name return market.sell(name);
// Call the supermarket sales method to return the result } }
<> four ,Shopping Main class
public class Shopping { public static void main(String[] args) { //1. Create item object
Product p1= new Product(); Product p2 = new Product(); Product p3 = new Product(
); Product p4 = new Product(); Product p5 = new Product(); Product p6 = new
Product(); //2. Call commodity class set Method assignment p1.setProduct(" Huatian fruit wine "); p2.setProduct(" jackfruit "); p3.
setProduct(" Pepsi Cola "); p4.setProduct(" Happy potato chips "); p5.setProduct(" Master Kang: fat beef noodles in golden soup "); p6.
setProduct(" Red wolf special pan "); //3. Create supermarket object Supermarket s1 = new Supermarket();
Supermarket s2= new Supermarket(); Supermarket s3 = new Supermarket();
//4. call set assignment s1.setSupermaketName(" Carrefour "); s1.setProductArr(new Product[] {p1,p2,
p3,p4,p5,p6}); s2.setSupermaketName(" RT Mart "); s2.setProductArr(new Product[] {p1,
p2,p3,p4,p5,p6}); s3.setSupermaketName(" Wal-Mart "); s3.setProductArr(new Product[] {
p1,p2,p3,p4,p5,p6}); //5. Creator object Person n1 = new Person(); Person n2 = new Person(
); Person n3 = new Person(); //6. call set Method assignment n1.setPersonName(" Zhang Yixing "); n2.
setPersonName(" Lau Andy "); n3.setPersonName(" Yang Mi "); n3.shopping(s2," Yang Mi "); Product
result= s2.sell(" Master Kang: fat beef noodles in golden soup "); if(result == null) { System.out.println("Emmmmmm,"+
n3.getPersonName()+" Strolled around "+s2.getSupermaketName()+" supermarket , I didn't buy anything "); }else { System.
out.println(n3.getPersonName()+" Strolled around "+s2.getSupermaketName()+" After the supermarket , Bought the legendary "+
result.getProductName()); } } }
<> five , Implementation results

©2019-2020 Toolsou All rights reserved,
evo Tool usage problems ——Degenerate covariance rank, Umeyama alignment is not possible Experiment 4 Automated test tools - software test mysql Export data sql sentence _mysql according to sql Query statement export data Create a thread ——— Javaweb (3) Data structure experiment ( three )—— Stacks and queues TS stay vue2 Writing in the project web Front end signature plug-in _signature_pad Plug in implements electronic signature function docker Where is the image stored Qt Getting Started tutorial 【 Basic controls 】QCalendarWidget calendar control springboot How to get reality in ip address