Guest User

ICSE Specimen Paper 2020 - Question 4

a guest
Oct 29th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.00 KB | None | 0 0
  1. /**
  2.  * Question 4 of the ICSE Specimen Paper 2020.
  3.  * Specimen Paper: http://www.cisce.org/pdf/ICSE-Class-X-Specimen-Question-Papers-2020/Computer%20Applications_Specimen_2020.pdf
  4.  */
  5. import java.util.Scanner;
  6. public class Atransport
  7. {
  8.     String name;
  9.     int w, charge;
  10.     Atransport()
  11.     {
  12.         name = "";
  13.         w = 0;
  14.         charge = 0;
  15.     }
  16.    
  17.     void accept()
  18.     {
  19.         Scanner sc = new Scanner(System.in);
  20.         System.out.println("Please enter your name.");
  21.         name = sc.next();
  22.         System.out.println("Please enter the weight of the parcel.");
  23.         w = sc.nextInt();
  24.         sc.close();
  25.     }
  26.    
  27.     void calculate()
  28.     {
  29.         if(w <= 10)
  30.             charge = w * 25;
  31.         else if(w > 10 && w <= 30)
  32.             charge = w * 20;
  33.         else
  34.             charge = w * 10;
  35.        
  36.         charge += charge * 5/100;
  37.     }
  38.    
  39.     void print()
  40.     {
  41.         System.out.println("Name\tWeight\tBill amount");
  42.         System.out.println(name +"\t"+ w +"\t"+ charge);
  43.     }
  44.    
  45.     public static void main(String[] args)
  46.     {
  47.         Atransport s1 = new Atransport();
  48.         s1.accept();
  49.         s1.calculate();
  50.         s1.print();
  51.     }
  52. }
Add Comment
Please, Sign In to add comment