Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // import java.util.sanner;
- import java.util.Scanner;
- public class checkEligibility {
- public static void main(String[] args) {
- // system.out.printin("Customer_number\tAge\tUnit");
- System.out.println("id\tAge\tUnit");
- int age[] = {50, 60, 70, 30};
- int unit[] = {300,200,100,400};
- for (int counter = 0; counter < age.length; counter++) {
- // system.out.println(counter + "\t" + age[counter] + "\t" + unit[counter]);
- System.out.println(counter + "\t" + age[counter] + "\t" + unit[counter]);
- }
- for (int counter = 0; counter < age.length; counter++) {
- if (age[counter] < 55 && unit[counter] > 250) {
- // <added>
- System.out.print("id " +counter +": ");
- // </added>
- // JavaException();
- new JavaException();
- }
- }
- }
- }
- class JavaException {
- // public static void main(String args[]) {
- JavaException() {
- try {
- throw new MyException(2);
- // throw is used to create a new exception and throw it.
- } catch (MyException e) {
- System.out.println(e);
- }
- }
- }
- // <added>
- class MyException extends Exception {
- private static final long serialVersionUID =
- 1L; //eg.
- public MyException(int n) {
- //... ?
- }
- // </added>
- public String toString(){
- return ("The consumer is not eligible for getting the discount.");
- }
- }
- /* Output:
- id Age Unit
- 0 50 300
- 1 60 200
- 2 70 100
- 3 30 400
- id 0: The consumer is not eligible for getting the discount.
- id 3: The consumer is not eligible for getting the discount.
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement