Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Question 4 of the ICSE Specimen Paper 2020.
- * Specimen Paper: http://www.cisce.org/pdf/ICSE-Class-X-Specimen-Question-Papers-2020/Computer%20Applications_Specimen_2020.pdf
- */
- import java.util.Scanner;
- public class Atransport
- {
- String name;
- int w, charge;
- Atransport()
- {
- name = "";
- w = 0;
- charge = 0;
- }
- void accept()
- {
- Scanner sc = new Scanner(System.in);
- System.out.println("Please enter your name.");
- name = sc.next();
- System.out.println("Please enter the weight of the parcel.");
- w = sc.nextInt();
- sc.close();
- }
- void calculate()
- {
- if(w <= 10)
- charge = w * 25;
- else if(w > 10 && w <= 30)
- charge = w * 20;
- else
- charge = w * 10;
- charge += charge * 5/100;
- }
- void print()
- {
- System.out.println("Name\tWeight\tBill amount");
- System.out.println(name +"\t"+ w +"\t"+ charge);
- }
- public static void main(String[] args)
- {
- Atransport s1 = new Atransport();
- s1.accept();
- s1.calculate();
- s1.print();
- }
- }
Add Comment
Please, Sign In to add comment