Advertisement
Guest User

Reworked

a guest
Sep 18th, 2013
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. package reddit.Challenges.Challenge138;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Challenge138 {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner sc = new Scanner(System.in);
  9.        
  10.         String data1 = sc.nextLine();
  11.        
  12.         Particle particle1 = new Particle(data1);
  13.        
  14.         String data2 = sc.nextLine();
  15.  
  16.         Particle particle2 = new Particle(data2);
  17.        
  18.         float deltaX = particle2.getX() - particle1.getX();
  19.         float deltaY = particle2.getY() - particle1.getY();
  20.         double distance = Math.sqrt(deltaX*deltaX + deltaY*deltaY);
  21.        
  22.         double force = (particle1.getMass() * particle2.getMass())/(distance*distance);
  23.         System.out.println("Force between particles: " + force);
  24.        
  25.         sc.close();
  26.     }
  27.  
  28. }
  29.  
  30.  
  31. public class Particle {
  32.  
  33.     public Particle(String data) {
  34.         Scanner sc = new Scanner(data);
  35.         sc.useDelimiter(" ");
  36.         float mass = sc.nextFloat();
  37.         float x = sc.nextFloat();
  38.         float y = sc.nextFloat();
  39.        
  40.         this.setMass(mass);
  41.         this.setX(x);
  42.         this.setY(y);
  43.     }
  44.    
  45.    
  46.  
  47.     public float getX() {
  48.         return x;
  49.     }
  50.  
  51.     public void setX(float x) {
  52.         this.x = x;
  53.     }
  54.  
  55.     public float getY() {
  56.         return y;
  57.     }
  58.  
  59.     public void setY(float y) {
  60.         this.y = y;
  61.     }
  62.  
  63.     public float getMass() {
  64.         return mass;
  65.     }
  66.  
  67.     public void setMass(float mass) {
  68.         this.mass = mass;
  69.     }
  70.  
  71.     private float x;
  72.     private float y;
  73.     private float mass;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement