Advertisement
Goodiny777

Java lesson 1 homework exr. 2-5

Dec 11th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.69 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class Program
  3. {
  4.     public static void main(String[] args) {
  5.         Scanner sc=new Scanner(System.in);
  6.        
  7.         //targil 2
  8.          
  9.         final int charToInt ='0';//שומר הקבוע את המספר של אות '0'
  10.         System.out.println("Please enter three numbers from 0 to 9 divided by space");
  11.         int ch1=sc.next().charAt(0);// ch1 מקבל מספר של אות שקראנו בעזרת scanner
  12.         int ch2=sc.next().charAt(0);
  13.         int ch3=sc.next().charAt(0);
  14.         System.out.println((ch1-charToInt)*100 + (ch2-charToInt)*10 + (ch3-charToInt));
  15.        
  16.        
  17.         //targil 3
  18.         int abLength ='Z'-'A'+1;//in this case better to do like this
  19.         System.out.println("English Alpabet length is: "+ abLength );
  20.        
  21.        
  22.         //targil 4
  23.         final double startCost = 10.2;
  24.         final double perKM=1.3;
  25.         final double perBag=2.0;
  26.         System.out.println("Please enter length of trip and amount of bags divided by Space");
  27.         int tripLength = sc.nextInt();
  28.         int bags=sc.nextInt();
  29.         System.out.println("Total price: "+(startCost + tripLength*perKM + bags*perBag));
  30.        
  31.        
  32.         //targil5
  33.         final int station = 5;
  34.         final int between = 3;
  35.         System.out.println("Enter your start position, lift start position, and the floor you need to arrive divided by Space");
  36.         int myStartPosition=sc.nextInt();
  37.         int liftStartPosition=sc.nextInt();
  38.         int goal=sc.nextInt();
  39.         System.out.println("Tatal time in seconds: "+((liftStartPosition-myStartPosition)*between+station+(goal-myStartPosition)*between));
  40.        
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement