第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

庫存應(yīng)用程序不會顯示結(jié)果

庫存應(yīng)用程序不會顯示結(jié)果

PHP
三國紛爭 2021-08-28 17:25:36
我應(yīng)該為庫存管理應(yīng)用程序制作一個 php 程序。我有主程序,還有一個測試程序,以確保一切正常我確實有大部分工作的代碼庫存.phpclass Product{// ----------------------------------------- Properties -----------------------------------------private $product_name = "no name";private $product_code = 0;private $product_price = 0;private $product_quantity = 0;private $product_needs = "no needs";private $error_message = "??";// ---------------------------------- Set Methods ----------------------------------------------function set_product_name($value){$error_message = TRUE;(ctype_alpha($value) && strlen($value) <= 20) ? $this->product_name = $value : $this->error_message = FALSE;return $this->error_message;}function set_product_code($value){$error_message = TRUE;(ctype_digit($value) && ($value > 0 && $value <= 6)) ? $this->product_code = $value : $this->error_message = FALSE;return $this->error_message;}function set_product_price($value){$error_message = TRUE;(ctype_digit($value) && ($value > 0 && $value <= 6)) ? $this->product_price = $value : $this->error_message = FALSE;return $this->error_message;}function set_product_quantity($value){$error_message = TRUE;(ctype_digit($value) && ($value > 0 && $value <= 6)) ? $this->product_quantity = $value : $this->error_message = FALSE;return $this->error_message;}function set_product_needs($value){$error_message = TRUE;(ctype_alpha($value) && strlen($value) <= 40) ? $this->product_needs = $value : $this->error_message = FALSE;return $this->error_message;}// ----------------------------------------- Get Methods ------------------------------------------------------------function get_product_name(){return $this->product_name;}function get_product_code(){return $this->product_code;}function get_product_price(){return $this->product_price;}function get_product_quantity(){return $this->product_quantity;}function get_product_needs(){return $this->product_needs;}
查看完整描述

2 回答

?
繁星淼淼

TA貢獻1775條經(jīng)驗 獲得超11個贊

您的 Product 類 Product 應(yīng)如下所示


class Product {


    private $product_name = "no name";

    private $product_code = 0;

    private $product_price = 0;

    private $product_quantity = 0;

    private $product_needs = "no needs";



    function get_product_name() {

        return $this->product_name;

    }


    function set_product_name($value) {

        $this->product_name = $value;

    }


    function get_product_code() {

        return $this->product_code;

    }


    function set_product_code($value) {

        $this->product_code = $value;

    }


    function get_product_price() {

        return $this->product_price;

    }


    function set_product_price($value) {

        $this->product_price = $value;

    }


    function get_product_quantity() {

        return $this->product_quantity;

    }


    function set_product_quantity($value) {

        $this->product_quantity = $value;

    }


    function get_product_needs() {

        return $this->product_needs;

    }


    function set_product_needs($value) {

        $this->product_needs = $value;

    }


    function get_properties() {

        return $this->product_name . ' ' . $this->product_code . ' ' . $this->product_price . ' ' . $this->product_quantity . ' ' . $this->product_needs;

    }

}

所以你可以創(chuàng)建一個實例并獲得正確的值


//lab.php


$product = new Product();

$product->set_product_code(1234);


print $product->get_product_code(); // print 1234

所有驗證都應(yīng)在產(chǎn)品模型之外進行


$product_quantity = '7.5';


if(is_numeric($product_quantity)) { // check if is numeric


    $product->set_product_quantity($product_quantity); // set the product quantity


    print "Quantity update successful<br />"; // show successful messages

} else {

    print "Quantity update is not successful<br />";

}


查看完整回答
反對 回復(fù) 2021-08-28
?
縹緲止盈

TA貢獻2041條經(jīng)驗 獲得超4個贊

這應(yīng)該使它工作。主要問題是如何處理字符串和數(shù)值。有足夠的空間進行其他結(jié)構(gòu)改進:)。


庫存.php


<?php


class Product

{

// ----------------------------------------- Properties -----------------------------------------

private $product_name = "no name";

private $product_code = 0;

private $product_price = 0;

private $product_quantity = 90;

private $product_needs = "no needs";

private $error_message = "??";


// ---------------------------------- Set Methods ----------------------------------------------

function set_product_name($value)

{

$error_message = TRUE;

(ctype_alpha($value) && strlen($value) <= 20) ? $this->product_name = $value : $this->error_message = FALSE;

return $this->error_message;

}

function set_product_code($value)

{

$error_message = TRUE;

(is_numeric($value) && ($value > 0 && $value <= 999999)) ? $this->product_code = $value : $this->error_message = FALSE;

return $this->error_message;

}

function set_product_price($value)

{

$error_message = TRUE;

(is_numeric($value) && ($value > 0 && $value <= 999999)) ? $this->product_price = $value : $this->error_message = FALSE;

return $this->error_message;

}

function set_product_quantity($value)

{

$error_message = TRUE;

(is_numeric($value) && ($value > 0 && $value <= 999999)) ? $this->product_quantity = $value : $this->error_message = FALSE;

return $this->error_message;

}

function set_product_needs($value)

{

$error_message = TRUE;

(preg_match('/[^a-z_\-0-9]/i', $value) && strlen($value) <= 40) ? $this->product_needs = $value : $this->error_message = FALSE;

return $this->error_message;

}

// ----------------------------------------- Get Methods ------------------------------------------------------------

function get_product_name()

{

return $this->product_name;

}

function get_product_code()

{

return $this->product_code;

}

function get_product_price()

{

return $this->product_price;

}

function get_product_quantity()

{

return $this->product_quantity;

}

function get_product_needs()

{

return $this->product_needs;

}

function get_properties()

{

return "$this->product_name,$this->product_code,$this->product_price,$this->product_quantity,$this->product_needs.";

}

}

實驗室.php


$lab = new Product;

// ------------------------------Set Properties--------------------------

$product_error_message = $lab->set_product_name('Hinge');

print $product_error_message == TRUE ? 'Name update successful<br/>' : 'Name update not successful<br/>';


$product_error_message = $lab->set_product_code(45435);

print $product_error_message == TRUE ? 'Code update successful<br />' : 'Code update not successful<br />';


$product_error_message = $lab->set_product_price(7.50);

print $product_error_message == TRUE ? 'Price update successful<br />' : 'Product update not successful<br />';


$product_error_message = $lab->set_product_quantity(75);

print $product_error_message == TRUE ? 'Quantity update successful<br />' : 'Quantity update not successful<br />';


$product_error_message = $lab->set_product_needs('Wrap in plastic');

print $product_error_message == TRUE ? 'Needs update successful<br/>' : 'Needs update not successful<br/>';

// ------------------------------Get Properties--------------------------

print $lab->get_product_name() . "<br/>";

print $lab->get_product_code() . "<br />";

print $lab->get_product_price() . "<br />";

print $lab->get_product_quantity() . "<br />";

print $lab->get_product_needs() . "<br />";

$product_properties = $lab->get_properties();

list($product_name, $product_code, $product_price, $product_quantity, $product_needs) = explode(',', $product_properties);

print "Name: $product_name. Code: $product_code. Price: $product_price. Quantity: $product_quantity. Needs: $product_needs";

?>


查看完整回答
反對 回復(fù) 2021-08-28
  • 2 回答
  • 0 關(guān)注
  • 147 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號