CSC248 Assessment1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

CSC248 OCT22

Assessment #1

Practical Test : Sorting and Searching (20%)

You are required to create a complete JAVA program to sort an array list of an objects with
multiple attributes, and to search a specific element in the list.

The following are the processes of the program that you need to develop.

1. Repeatedly, READ the input from the users into an ArrayList named alTemp until
user terminates with a sentinel.

2. DISPLAY the ArrayList values before sorting.

3. SORT the ArrayList temperature values by using Bubble Sort algorithm in


ASCENDING order.

4. DISPLAY the ArrayList values after sorting.

5. SORT the ArrayList location values by using Bubble Sort algorithm in ASCENDING
order.

6. DISPLAY the ArrayList values after sorting.

7. SEARCH a location by using Binary Search algorithm and DISPLAY appropriate


message.
CSC248 OCT22

Below is the skeleton of the main application:


/*
Matric :
Name :
Group :
Lecturer :
*/

import java.util.ArrayList;
import java.util.Scanner;
public class myTemperature {
private String loc; //location
private float temp; //temperature

public myTemperature(String l, float t){


loc=l;
temp=t;
}
public String getLocation(){
return loc;
}
public float getTemperature(){
return temp;
}
public String toString(){
return loc+" "+temp;
}

public static void main(String[] args) {

System.out.println("\t\t\t Welcome to Sorting and Searching Program");


System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");

// Repeatedly, READ the input from the users into an ArrayList named alTemp
// until user terminates with a sentinel.
...
...
// DISPLAY the ArrayList values before sorting.
...
...
// SORT the ArrayList based on temperature in ASCENDING order.
...
...
// DISPLAY the ArrayList values after sorting.
...
...
// SORT the ArrayList based on location in ASCENDING order.
...
...
// DISPLAY the ArrayList values after sorting.
...
...
// Request search key and perform the binary search.
...
...
}
}
CSC248 OCT22

The sample of input and output of a running program is given as follows:

Welcome to Sorting and Searching Program


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Location : Kangar
Temperature : 30.1
Continue (Y/N) : y
Location : Alor Setar
Temperature : 31.2
Continue (Y/N) : y
Location : Georgetown
Temperature : 30.2
Continue (Y/N) : y
Location : Ipoh
Temperature : 30.4
Continue (Y/N) : y
Location : Kuala Lumpur
Temperature : 29.4
Continue (Y/N) : y
Location : Seremban
Temperature : 29.6
Continue (Y/N) : y
Location : Melaka
Temperature : 29.7
Continue (Y/N) : y
Location : Johor Bahru
Temperature : 29.7
Continue (Y/N) : y
Location : Kuantan
Temperature : 29.5
Continue (Y/N) : y
Location : Kuala Terengganu
Temperature : 29.3
Continue (Y/N) : y
Location : Kota Bharu
Temperature : 29.2
Continue (Y/N) : n
Unsorted List : [Kangar 30.1, Alor Setar 31.2, Georgetown 30.2, Ipoh
30.4, Kuala Lumpur 29.4, Seremban 29.6, Melaka 29.7, Johor Bahru 29.7,
Kuantan 29.5, Kuala Terengganu 29.3, Kota Bharu 29.2]
Sorted List : [Kota Bharu 29.2, Kuala Terengganu 29.3, Kuala Lumpur
29.4, Kuantan 29.5, Seremban 29.6, Melaka 29.7, Johor Bahru 29.7, Kangar
30.1, Georgetown 30.2, Ipoh 30.4, Alor Setar 31.2]
CSC248 OCT22

New sorted List : [Alor Setar 31.2, Georgetown 30.2, Ipoh 30.4,
Johor Bahru 29.7, Kangar 30.1, Kota Bharu 29.2, Kuala Lumpur 29.4, Kuala
Terengganu 29.3, Kuantan 29.5, Melaka 29.7, Seremban 29.6]
Search Location : Kota Bharu
Element is found at index: 5
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Thank You and See You Again!

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy