Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
2.0 kB
3
Indexable
import java.util.*;
import java.text.*;

public class LandApp{
	public static void main(String[] args){
		Scanner scan = new Scanner (System.in);
		Scanner scan1 = new Scanner (System.in);
		
		DecimalFormat df = new DecimalFormat("###,###.00");
		
		//STEP 1: Declare array of object
		System.out.print("Enter size of array: ");
		int size = scan1.nextInt();
		Land[] lnd = new Land[size];
		
		//STEP 2: Instantiate/Create array of object
		for(int i=0; i<size; i++)
			lnd[i] = new Land();
		
				
		//STEP 3: Input Data
		for(int i=0; i<size; i++){
			System.out.print("Enter Id: ");
			int idx = scan1.nextInt();
			System.out.print("Enter Owner Name: ");
			String nme = scan.nextLine();
			System.out.print("Enter House Type: ");
			char hty = scan.nextLine().charAt(0);
			System.out.print("Enter Area: ");
			double are = scan1.nextDouble();
		
			//STEP 4: Strore onto object
			//1. Using normal constructor
			lnd[i] = new Land(idx,nme,hty,are);
		
			//OR
			//2.Using setter
			lnd[i].setId(idx);
			lnd[i].setName(nme);
			lnd[i].setHouseType(hty);
			lnd[i].setArea(are);
		}
				
		//STEP 4: Manipulation

		//1. To display all object information including tax payment
		for(int i=0; i<size; i++)
			System.out.println(lnd[i].toString()+"\nTax: RM "+df.format(lnd[i].calcTax()));
				
		//2. To identify and display the details of information for maximum tax payment.
		double maxTax = lnd[0].calcTax();
		Land maxLand = lnd[0];
		
		for(int i=0; i<size; i++){
			if(lnd[i].calcTax() > maxTax){
				maxTax = lnd[i].calcTax();
				maxLand = lnd[i];
			}
		}
		System.out.println("The highest tax details information: "+maxLand.toString()+"\nHighest Tax: RM "+maxTax);
			
		//3. To calculate the total tax payment
		double totTax=0;
		for(int i=0; i<size; i++){
			totTax += lnd[i].calcTax();
		} 
		System.out.println("\n\nTotal Payment for All Object: RM "+df.format(totTax));
	}
}