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

[تنبيه - عنوان غير مناسب : ]طلب مساعدة في تعديل هذا البرنامج

بدأه sibrahim في 16 ديسمبر 2009 · 3 رد · 420 مشاهدة · في JavaSE
مشاركة: واتساب 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 # {:content:}quot;+ price1 );

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


price2= input.nextFloat();
System.out.println("Enter a price for item # {:content:}quot;+ 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 # {:content:}quot;+ 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 # {:content:}quot;+ 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 # {:content:}quot;+ 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 # {:content:}quot;+ 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 # {:content:}quot;+ 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 # {:content:}quot;+ 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 # {:content:}quot;+ 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 # {:content:}quot;+ 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 {:content:}quot;+payment+" is {:content:}quot;+subtrction);




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




}//end main


} //end PracticeProject2

تم تعديل هذه المشاركة بواسطة herch في 16 ديسمبر 2009 في 17:10 — السبب: إضافة الوسم [code]، وهو الزر "<>"

#2

ارجوا منك في المرات القادمة اختيار اسم واضح لعنوان الموضوع.

package test;

import java.util.Scanner;

public class PracticeProject1 {

	/**
	 * @param args
	 */
	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 price=0,totalPrice=0;



		while(price!=-1){
			price = input.nextFloat();
			if(price!=-1){
				System.out.printf("Enter a price for item # $%s \n", price );
				totalPrice+=price;
				System.out.printf("That was %s . Your total is $%s \n", price, 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 = payment- totalPrice;
		System.out.printf("Your change from $%s is $%s",payment,subtrction);
		System.out.printf("Thank you for shopping at SuperMart, %s", name);
	}

}

تم تعديل هذه المشاركة بواسطة العيافـي في 16 ديسمبر 2009 في 09:27

1
#3

جزيت خيراً اخي ع مساعدتك

شكراً

#4

الأخ الكريم/الأخت الكريمة

السلام عليكم ورحمة الله وبركاته

مرحباً بكم في منتدى الفريق العربي للبرمجة

نود تنبيهك أن العنوان غير مناسب.

الرجاء اختيار عنوان مناسب أكثر في مواضيعك القادمة، وهذا بمثابة إشعار للأهمية.

وفي حال التكرار سيتعرض موضوعك للإغلاق والحذف!!!

قواعد المشاركة

/index.php?showtopic=29343

شاكرين لكم حُسن تعاونكم

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

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…