GIDForums  

Go Back   GIDForums > Computer Programming Forums > Java Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 23-Sep-2005, 19:36
pjpav's Avatar
pjpav pjpav is offline
New Member
 
Join Date: Sep 2005
Location: Beautiful NorthEastern Pennsylvania!
Posts: 8
pjpav is on a distinguished road

Convert the input into square yards


Since I was a bit vague the last time, here is my program which is suppossed to apply a discount based on square yards of carpet purchased at twenty dollars a square foot.The program is suppossed to convert the input into square yards and perform various operations. Will someone who knows what they are doing take a look at this and tell me what I am doing wrong? It would be greatly appreciated, PAY IT FORWARD!

JAVA Code:
 import java.util.Scanner;
    public class CarpetSale
   {
       public static void main(String[] args)
      {
     String units;
     
     
     
      double length, width;
      double squareYard;
      double inch, in, inches;
      double feet, ft, foot;
      int area;
    double squareFoot;
     double squareInch;
    
     inch = ft % 12;
       yard = ft * 3;
      ft = inch * 12;
      in = foot % 12;
       length = feet + inches;
       width = feet + inches; 
       area = length * width;
       squareInch = inch * 12;
        
       squareFoot = squareInch * 144;
         squareYard = squareFoot * 9;

      	
      	
      	
 
           
     
     
     
           double measurement;
      
      
      {
      Scanner scan = new Scanner( System.in );
     
     char measurement;
      
      
      
         System.out.print("Enter the length of your measurement in feet or inches:")
         int length = scan.nextInt();
         
      		while(true){ 
         
      	measurement = getDouble();
      	
      	if (measurement == 0)
      	break; 
      	
      	units = feet;            
            units = inches;




if (units.equals("inch") || units.equals("inches") 
                                            || units.equals("in")) {
                inches = measurement;
            }
			
				else if (units.equals("foot") || units.equals("feet") 
                                            || units.equals("ft")) {
                inches = measurement * 12;
            }



      	
      	
      		/* Get the user's input, and convert units to lower case. */
           
         	
      		
      		
      		System.out.print ("That is equivalent to:" + measurement);
         
      	
      
      	
      	
      	int measurement = scan.nextInt();
          Scanner scan = new Scanner( System.in );
      char measurement

      	
          System.out.print("Enter the width of your measurement in feet and inches:");
         int second = Integer.parseInt(secondString);
         int measurement + second = total price;
         int total price = w
         
         int totalMeasurement = length * width;
        
        int totalMeasurement = x
        if ( x < 10 );
         Scanner scan = new Scanner( System.in );
      char measurement

        
         System.out.print (" Your total price is:" w + x * 20);
        int total price 
         Scanner scan = new Scanner( System.in );
      char measurement;


        
        if ( x > 10 || x < 20)
         System.out.print ( " Your cost for the carpet is:" x * 20);
      		String s = new String ( " Your discount is 10%:"(x * 20 * .10 );
      		double y = (x * 20 * .10)
      		Scanner scan = new Scanner( System.in );
      char measurement;

      	 System.out.print ( "Your total cost for the carpet is:" ( x * 20 - y)         
         System.out.print( " You saved:" + y)
        
        if ( x > 20 || x < 30) 
        System.out.print ( " Your cost for the carpet is:" x * 20);
        		String s = new String ( " Your discount is 15%:" (x * 20 * .15 )
      		double y = ( x * 20 * .15)
      		System.out.print ( "Your total cost for the carpet is:" ( x * 20 - y)
      		System.out.print( " You saved:" + y)
      	
      if (x > 30) 
      System.out.print ( " Your cost for the carpet is:" (x * 20)
      	String s = new String ( " Your discount is 20%:" (x * 20 * .20)
      	double y =  (x * 20 * .20)
      	System.out.print ( "Your total cost for the carpet is:" ( x * 20 - y) 	 
           	System.out.print( "You saved:" = y)
           System.out.print ( " Can I help you with anything else today?"
         System.exit(0);
      }
   }

}

I TRIED THIS PROGRAM ALSO

JAVA Code:
import java.util.Scanner;
    public class CarpetDiscount
   {
       public static void main(String[] args)
      {

double measurement;

string units; 

double feet, inches, length, width, square_yards, square_foot;

Scanner scan = new Scanner ( System.in );

 System.out.print( "Enter the length of the room in feet and inches, you could use abbreviations:");

while (true) {

/* get the users input and convert units to lower case */

length = getDouble();
measurement = TextIO.getDouble();

if (length == 0)
break; //terminate the loop

units = TextIO.getlnWord();            
           
 units = units.toLowerCase();
 
 /* Convert the input measurement to square yards. */
 
feet = inches / 12;
inches = feet / 36;
yard = (feet *3) == (inches * 36);
square_foot = 9 * feet;
square_yards = 9 * square_feet;

/* Output measurement in terms of each unit of measure. */


           
         
        



           
System.out.print("Thats equivalent to:" + square_yards);

String secondString = JOptionPane.showInputDialog( "Enter the width of the room in feet and inches, you could use abbreviations:");

while (true) {

/* get the users input and convert units to lower case */

length = getDouble();
measurement = TextIO.getDouble();

if (length == 0)
break; //terminate the loop

units = TextIO.getlnWord();            
           
 units = units.toLowerCase();
 
 /* Convert the input measurement to square yards. */
 
feet = inches / 12;
inches = feet / 36;
yard = (feet *3) == (inches * 36);
square_foot = 9 * feet;
square_yards = 9 * square_feet;

/* Output measurement in terms of each unit of measure. */
            
JOptionPane.showMessageDialog(null,"Thats equivalent to:" + square_yards);

            
} // end while loop


}
Last edited by LuciWiz : 26-Sep-2005 at 02:24. Reason: Fixed tags
  #2  
Old 08-Oct-2005, 07:43
Paramesh's Avatar
Paramesh Paramesh is offline
Regular Member
 
Join Date: Sep 2005
Location: The Milky Way
Posts: 929
Paramesh is a jewel in the roughParamesh is a jewel in the roughParamesh is a jewel in the rough
Smile

Re: Convert the input into square yards


hi pjpav,

You should make the following changes in your CarpetSale program:

1. You cannot use spaces(blank characters) in your variable names.
You should use underscore(_) instead.
so correct the corresponding variables by using _ instead of space.

2.You typed these at once you declared the variables. In java the variables are assigned to 0 default. so these code have no effect. You have to enter these code only after you know all the values of the variables to the right.
JAVA Code:
     inch = ft % 12;
       yard = ft * 3;
      ft = inch * 12;
      in = foot % 12;
       length = feet + inches;
       width = feet + inches; 
       area = length * width;
       squareInch = inch * 12;
        
       squareFoot = squareInch * 144;
         squareYard = squareFoot * 9;

3. You missed out a semicolon in numerous occasions. Please correct those errors.

4. You missed out a comma in the System.out.println statements.
for example in line 115,
JAVA Code:
       System.out.print ( " Your cost for the carpet is:" x * 20); 
you should insert comma between you " and *.
ie your statement should be like this:
JAVA Code:
       System.out.print ( " Your cost for the carpet is:" ,x * 20); 

5. You can never declare like this:
JAVA Code:
         int measurement + second = total price; 
if you want a new variable called total_price(and not total price), then declare like this:
JAVA Code:
int total_price = measurement + second;

6.You have initialized the measurement variable of type char in numerous occasions. it should be done only once. remove the extra
JAVA Code:
char measurement
s.

7. You cannot use the measurement variables of type int and char at the same time.
JAVA Code:
int measurement;
JAVA Code:
char measurement;
so change the name of any one of those variables.

8. You have complicated the program very much. try to simplify your program.

In your CarpetDiscount.java:

1.You didnt include the header files to use JOptionPane, getDouble() and getlnWord().

2.You didnt declare many of your variables.


bye,
Paramesh.
__________________

Don't walk in front of me, I may not follow.
Don't walk behind me, I may not lead.
Just walk beside me and be my friend.
 
 

Recent GIDBlogInstall Adobe Flash - Without Administrator Rights by LocalTech

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
GradeBook Program x3ro C++ Forum 19 03-Apr-2005 19:28
Using files for input crystalattice C++ Forum 15 31-Aug-2004 18:53
[C] Discarding input Alhazred C Programming Language 8 04-Aug-2004 11:45
IP tables rogermark100 C Programming Language 6 18-Apr-2004 07:22

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 07:47.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.