الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

عمل كود لمنشأه

بدأه sibrahim في 15 ديسمبر 2009 · 0 رد · 613 مشاهدة · في قسم البرمجة بــ Javascript
مشاركة: واتساب X فيسبوك تيليجرام
#1

السلام عليكم

عندي شوية خلفية عن الجافا ايكليبس. طبعا قمت بتصميم هذا البرنامج بس عندي مشكلة في عمل الwhile loop and the if statment حابه انه المدخلات تكون لا محدودة بحيث انه المستخدم اذا ادخل -1 المستخدم بيخرج من البرنامج وبيعطيه اجمالي المشتريات ثم اذا ادخل المستخدم قيمة يعطية الباقي

ارجوا الرد بسرعة ويعطيكم الف عافية

طبعا هذا هو الكود

/*

* Coder: SI

* Date:Dec.15-2009

* Purpose: create a program for the SuperMart Store

* 1)It is going to ask the customer about his/her name.

* 2)To calculate their total purchases for example if the user enter his or her the purchase cost then it is going to

* show up on the screen

* 3)The program will execute the total

* 4) the program is going to be exited when the user hit -1

* 5) After that the user (customer)is going to enter the value (ex. $100)and the program is going to calculate and tell

* the user how much change that he/she going to get.

*///***************************************************///

import java.util.Scanner;

public class PracticeProject1 {

public static void main (String args[]){

System.out.println(" +-----------------------------------------------------------+");

System.out.println(" | SuperMart Self-Serve Checkout |");

System.out.println(" +-----------------------------------------------------------+");

//to show a greeting message

System.out.println(" Hi. Welcome to the SuperMart Checkout. What is your name? ");

//to let the user insert their values

Scanner input = new Scanner (System.in);

String name;

name = input.next(); //this is the first variable for inserting the name

//message to ask the user about his/her name

System.out.println("OK, "+name+ " enter the price of each of your purchases in\ndollars and cents and then"+" hit the ENTER key. For example ,"+

" if your item costs $5.99, enter 5.99 ");

//message for the user how to use this program

System.out.println("When you've entered all of your prices ,"

+" enter -1, to indicate that you've finished your entries ");

//to insert a new line

System.out.println();

float price1 ,price2,totalPrice;

//int i;

//while(i>=30){

price1= input.nextFloat();

// to exicute an if statment

//if( price1==0.1){

System.out.println("Enter a price for item # $"+ price1 );

System.out.println("That was "+ price1+" . Your total is $ "+ price1);

price2= input.nextFloat();

System.out.println("Enter a price for item # $"+ price2 );

totalPrice=price1+ price2;

System.out.println("That was "+ price2+" . Your total is $ "+ totalPrice);

// i++; //to increment the value of i

/*

else if (price1==-1){

System.out.println(" Bye "+name +" have a nice day");

// }//end enner if

*/

// } //end if

// }//end while

float price3;

price3= input.nextFloat();

System.out.println("Enter a price for item # $"+ price3 );

totalPrice=totalPrice+price3;

System.out.println("That was "+ price3+" . Your total is $ "+ totalPrice);

float price4;

price4= input.nextFloat();

System.out.println("Enter a price for item # $"+ price4 );

totalPrice=totalPrice+price4;

System.out.println("That was "+ price4+" . Your total is $ "+ totalPrice);

float price5;

price5= input.nextFloat();

System.out.println("Enter a price for item # $"+ price5 );

totalPrice=totalPrice+price5;

System.out.println("That was "+ price5+" . Your total is $ "+ totalPrice);

float price6;

price6= input.nextFloat();

System.out.println("Enter a price for item # $"+ price6 );

totalPrice=totalPrice+price6;

System.out.println("That was "+ price6+" . Your total is $ "+ totalPrice);

float price7;

price7= input.nextFloat();

System.out.println("Enter a price for item # $"+ price7 );

totalPrice=totalPrice+price7;

System.out.println("That was "+ price7+" . Your total is $ "+ totalPrice);

float price8;

price8= input.nextFloat();

System.out.println("Enter a price for item # $"+ price8 );

totalPrice=totalPrice+price8;

System.out.println("That was "+ price8+" . Your total is $ "+ totalPrice);

float price9;

price9= input.nextFloat();

System.out.println("Enter a price for item # $"+ price9 );

totalPrice=totalPrice+price9;

System.out.println("That was "+ price9+" . Your total is $ "+ totalPrice);

float price10;

price10= input.nextFloat();

System.out.println("Enter a price for item # $"+ price10 );

totalPrice=totalPrice+price10;

System.out.println("That was "+ price10+" . Your total is $ "+ totalPrice);

float gst,pst,TPGP;

gst = (float)(totalPrice * 0.05);

pst = (float)(totalPrice * 0.08);

TPGP = (float)totalPrice+gst+pst;

System.out.println();

System.out.println();

System.out.println("With "+gst+"GST and "+pst+"PST that comes to "+TPGP);

float payment = 0 ;

float subtrction;

System.out.println("Enter the amount you are presenting for payment and press ENTER...");

payment=input.nextFloat();

subtrction = (float)payment- TPGP;

System.out.println("Your change from $"+payment+" is $"+subtrction);

System.out.println("Thank you for shopping at SuperMart, "+ name);

}//end main

} //end PracticeProject2

مواضيع مشابهة