Ⅰ 我有道java編程小題求編程:商場價格打折 無需界面
我寫了個簡單的僅供參考:
public class Seal {
private static double totalMoney;
public double getTotalMoney() {
return totalMoney;
}
@SuppressWarnings("static-access")
public void setTotalMoney(double totalMoney) {
this.totalMoney = totalMoney;
}
/**
* 打任意折扣
* @param discount
* @return
*/
public static double sealX(float discount){
return totalMoney*discount;
}
/**
* 打任意折扣並減任意錢
* @param discount
* @param sealPrice
* @return
*/
public static double sealAndCut(float discount,int sealPrice){
return (totalMoney*discount)-sealPrice;
}
public static void main(String[] args) {
//模擬打七折
Seal.totalMoney=500.0D;
System.out.println(Seal.sealX(0.7F));
//模擬打七折後減100元
System.out.println(Seal.sealAndCut(0.7F, 100));
}
}
如果要體現OOP思想,那麼至少要寫兩個類,比如:TotalMoney(消費總額)和Seal(折扣類)
消費總額類裡面只有:totalMoney這個屬性。
折扣類裡面有兩個方法:打任意折扣的方法和打任意折扣後減任意錢的方法
大致如此,有問題可以Q我:335452735
Ⅱ 高手們請幫我看看如何用switch語句編好下面一題的c語言編程題!
#include <stdio.h>
void main()
{
int a;
float p,d,f;
scanf("%f",&p);
a=p/100;
switch(a){
case 0 : printf("%f",p);break;
case 1 : printf("f=%f,p=%f,d=%f",p-p*(5.0/100.0),p,p*(5.0/100.0));break;
...
...
default :printf ("qing zai shu ru\n");
}
裡面的語句塊我就不再寫了反正都一樣~你應回該會寫對答吧~
Ⅲ java編程,某市場推出促銷活動,不同時段給予不同的優惠。請針對該項活動設計與實現批發計費類CalcFee。
這個是按您的需求寫的,您看看吧,沒有用您說要求的Date,Round,因為我覺得我用的方法會更好一點
import java.text.DecimalFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
public class CalcFee {
int num;//批發數量
double per_price;//單價
int start_num;//起批數量
int discount;//優惠折扣
double total_price;//總價
boolean boo;//是否可以起批
//根據當前時間段設置起批數量、單價、優惠折扣等信息
public void set_info(){
Calendar calendar = GregorianCalendar.getInstance();
int hour = calendar.get(Calendar.HOUR_OF_DAY);
if (hour == 11 || hour == 16){
start_num = 100;
per_price = 3;
discount = 8;
} else {
start_num = 200;
per_price = 5;
discount = 9;
}
}
//根據批發數量num計算總價
public void calc(int num){
this.num = num;
boo = this.num > start_num;
if (boo) {
total_price = (per_price * start_num) + (per_price * (num-start_num) * discount/10);
} else {
total_price = per_price * num;
}
}
//輸出費用清單
public void show(){
DecimalFormat df = new DecimalFormat("###.00");
String display =
"起批數量:"+start_num +
"
單價:"+per_price +
"
優惠折扣:"+ discount +"折"+
"
批發數量:"+ num +
"
============" +
"
總價:"+df.format(total_price);
System.out.println(display);
}
public static void main(String[] args) {
CalcFee c = new CalcFee();
c.set_info();
c.calc(201);
c.show();
}
}
Ⅳ 用C語言寫一個打折程序.如圖所示
#include<stdio.h>
intmain()
{
intx;
floaty;
printf("請輸入本次消費的金額: ");
scanf("%d",&x);
if(x>=1000)
y=x*0.85;
elseif(500<=x&&x<1000)
y=0.9*x;
elseif(300<=x&&x<500)
y=0.96*x;
elseif(x<300&&x>0)
y=x;
printf("實際花費的金額:%.2f",y);
return0;
}
Ⅳ c語言一道編程題!會的幫忙 謝謝
#include <stdio.h>
main(){
float price;
int flag=1;
while(flag){
printf("請輸入消費金額");
scanf(price,%f);
if(price<0)
{printf("對不起,您輸入的數據有誤,請重新輸入 /n");
continue;}
else if(price<100)
{printf("折扣率是0%/n");
printf("您的應付金額為" & price,%f);
break;
}
else if(price<200)
{printf("折扣率是5%/n");
printf("您的應付金額為" & price*0.95,%f);
break;}
else if(price<500)
{printf("折扣率是10%/n");
printf("您的應付金額為" & price*0.90,%f);
break;}
else if(price<1000)
{printf("折扣率是15%/n");
printf("您的應付金額為" & price*0.85,%f);
break;}
else if(price>=1000)
{printf("折扣率是20%/n");
printf("您的應付金額為" & price*0.80,%f);
break;}
else
break;
}
}
Ⅵ 買書打折用C語言怎麼編程
1 涉及的C語言知識
(1)輸入
(2)加減乘除運算
(3)輸出
2 一個小示例
#include<stdio.h>
floatget_discount(intx){
floatoutput=0;
//當輸入以0結尾時,不合法,返回0
if(x%10==0)
returnoutput;
//當輸入為85時,代表85折,輸出應為0.85
if(x>10&&x<100)
output=x/100.0;
//當輸入為7時,代表7折,輸出應為0.7
if(x<10&&x>=1)
output=x/10.0;
returnoutput;
}
intmain(){
floatcount;
intdiscount_str;
puts("輸入書的金額和列印情況(以空格為分割符,按回車結束):");
puts("(如輸入的是207則表示20元的書打7折)");
scanf("%f%d",&count,&discount_str);
floatdiscount_f=get_discount(discount_str);
if(discount_f==0)
puts("輸入的打折情況不合法.");
else{
floatresult=count*discount_f;
printf("打折後的金額為:%.2f ",result);
}
getchar();
getchar();
return0;
}
3 運行情況
Ⅶ 商品打折編程題
if(原價<=100)
價格=原價*0.95
else if(原價<1000)
價格=原價*0.9
else
價格=原價*0.85
大致就這樣
自己看看吧
Ⅷ c#編程,某商場正在促銷打折,購物滿100減50,輸入購買的商品的原價,編寫方法計算顧客實際的付款
Console.WriteLine("請輸入商品原價:");
decimal pay = Convert.ToDecimal(Console.ReadLine());
if (pay < 100)
{
Console.WriteLine("顧客實際應付款{0}元", pay);
}
else
{
Console.WriteLine("顧客實際應付款{0}元", pay-50);
}
Console.ReadKey();
說明:以上是C#編程,基於.Net平台進行,本人使用的是Visual Studio 2010(語言是C#)
Ⅸ c語言試題:淘寶商城促銷活動,一次性購物滿300元(以上)的打九折,一次性購物滿500元(以上)的
這方面的問1題,你還是要去3禾塘月色平台學4習下,哪裡很5多值得學習的
Ⅹ C語言編程,題目:周末商場促銷,某品牌服裝即可以買套裝,又可以買單件,若買的不少於50套,每套80
#include<stdio.h>
int Get(int count)
{
if(count>=50)
return count*80;
else
return count*90;
}
int Pay(int shangyi,int kuzi)
{
int gold=0;
int left=0;
if(shangyi==kuzi)
gold=Get(shangyi);
else if(shangyi>kuzi)
{
gold=Get(kuzi);
left=shangyi-kuzi;
gold+=left*60;
}
else if(shangyi<kuzi)
{
gold=Get(shangyi);
left=kuzi-shangyi;
gold+=left*45;
}
return gold;
}
int main()
{
int shangyi=55;
int kuzi=50;
int gold=Pay(shangyi,kuzi);
printf("%d ",gold);
system("pause");
}