Tech Support Forum banner

Java confusion.

868 Views 2 Replies 3 Participants Last post by  Crockeo
Hi there!

So basically I need to work minus a percentage off of a price! For some reason this really confused me and left me with this mess:

Code:
import java.util.*;     // Scanner Class

class exercise99
  {
    public static void main() 
      {
        // Define and create a Scanner object
        Scanner inputLine = new Scanner(System.in);
        
        // Define other variables required
        float caryear=0, rate=0, carprice=0;

        // Display a heading on the screen
        System.out.println ("Depreciation calculator");
        System.out.println ("==============================");
        System.out.println ();

        // Ask the user to enter car price
        System.out.print ("Please enter car year: ");
        caryear = inputLine.nextFloat();
        
        System.out.print ("Please enter car price: ");
        carprice = inputLine.nextFloat();
        
        //ask the user to enter car year
        
        //First year
            if (caryear == 1 && (carprice <=25000 ))
          {
              rate = 30;
          }
          
          if (caryear == 1 && (carprice <= 25000) && (carprice  >=45000 ))
          {
              rate = 25;
          }
          
           if (caryear == 1 && (carprice <= 45000))
          {
              rate = 20;
          }
        
                  //Second year and beyond
            if (caryear >=2 && (carprice <=25000 ))
          {
              rate = 15;
          }
          
          if (caryear >=2 && (carprice <= 25000) && (carprice  >=45000 ))
          {
              rate = 12;
          }
          
           if (caryear >=2 && (carprice <= 45000))
          {
              rate = 10;
          }
    
          carprice = carprice - rate; 
          //Calculation for 
        
        // Display the circle area
        System.out.println ("This is the caculated car price:" + carprice );
    }
  }
// End program

any help? D: D: D:
See less See more
Status
Not open for further replies.
1 - 3 of 3 Posts
A little unsure of what your asking. Are you wanting the price of the car to be subtracted? It's a bit hard to tell what you mean, as this looks like a short homework/assignment piece. Is it? That would help to know.
If you're wanting to make it so there's a percent off, like 50% for example, you'd do:

Code:
float X = .5, Y=100, Z = 0;

Z = Y * X;

System.out.println("Half of 100 is: " + Z);
Now for what you're program has to do:
Code:
import java.util.*;     // Scanner Class

class exercise99
  {
    public static void main() 
      {
        // Define and create a Scanner object
        Scanner inputLine = new Scanner(System.in);
        
        // Define other variables required
        float caryear=0, rate=0, carprice=0;

        // Display a heading on the screen
        System.out.println ("Depreciation calculator");
        System.out.println ("==============================");
        System.out.println ();

        // Ask the user to enter car price
        System.out.print ("Please enter car year: ");
        caryear = inputLine.nextFloat();
        
        System.out.print ("Please enter car price: ");
        carprice = inputLine.nextFloat();
        
        //ask the user to enter car year
        
        //First year
            if (caryear == 1 && (carprice <=25000 ))
          {
              rate = [B].3[/B];
          }
          
          if (caryear == 1 && (carprice <= 25000) && (carprice  >=45000 ))
          {
              rate = [B].25[/B];
          }
          
           if (caryear == 1 && (carprice <= 45000))
          {
              rate = [B].2[/B];
          }
        
                  //Second year and beyond
            if (caryear >=2 && (carprice <=25000 ))
          {
              rate = [B].15[/B];
          }
          
          if (caryear >=2 && (carprice <= 25000) && (carprice  >=45000 ))
          {
              rate = [B].12[/B];
          }
          
           if (caryear >=2 && (carprice <= 45000))
          {
              rate = [B].1[/B];
          }
    
          carprice = carprice [B]*[/B] rate; 
          //Calculation for 
        
        // Display the circle area
        System.out.println ("This is the caculated car price:" + carprice );
    }
  }
// End program
Everything I changed I put as bold.

PS: If it confuses you on what I did just ask.
See less See more
1 - 3 of 3 Posts
Status
Not open for further replies.
Top