Question

In: Computer Science

Write a program in java that does the following: Create a StudentRecord class that keeps the...

Write a program in java that does the following:

  1. Create a StudentRecord class that keeps the following information for a student: first name (String), last name (String), and balance (integer). Provide proper constructor, setter and getter methods.
  2. Read the student information (one student per line) from the input file “csc272input.txt”. The information in the file is listed below. You can use it to generate the input file yourself, or use the original input file that is available alone with this midterm document.

C12345 Abex Mary 900

F98733 Alberto Peter 80

C93832 Walter Mary 200

C32334 Lee Kate 1000

F32145 Rockey Keith 20

F09121 Shaffer John 1000

F94321 Lewis Stephen 100

C83243 Chandler Lily 200

  1. Uses a HashMap to store the student information. The HashMap’s key should be the student ID (e.g. C12345, F98733, etc.), and the value should be a StudentRecord object.
  2. In your program, design a function called printHashMap that takes the HashMap and display the student information in it in the same format as the input file. Invoke this function to display the HashMap generated in part (c).
  3. Copy all the student IDs, which are the HashMap’s keys, into a String array from the HashMap.
  4. Merge sort the student ID String array to alphabetical ascending order (A à Z).
  5. Overload the function printHashMap from part (d) to take the HashMap and a String array with sorted key, then display all the student information in sorted order. Invoke this function to display the student information in the HashMap using the sorted student ID array from step (f).

Solutions

Expert Solution

Hi there, as you didn't specify which subaprt to solve i have solve first two subpart as we are allocated with limited time that's why only two parts were possible to solve, for remaining parts repost.

If you find any difficuly with solution do comment I'll be happy to helpnyour further.

If you like my solution please rate it.

I have used eclipse ide

code:

a)

this code goes into StudentRecord file

public class StudentRecord{
    private String firstName;
    private String lastName;
    private int balance;

    public StudentRecord(String firstName, String lastName, int balance) {
        this.firstName = firstName;
        this.lastName = lastName;
        this.balance = balance;
    }

    public String getfirstName() {
        return firstName;
    }
    public String getlastName() {
        return lastName;
    }
    public int getbalance() {
        return balance;
    }
    public String getfullName() {
        return firstName +" " + lastName;
    }
    public void setfirstName(String firstName) {
        this.firstName = firstName;
    }
    public void setlastName(String lastName) {
        this.lastName = lastName;
    }
    public void setbalance(int balance) {
        this.balance = balance;
    }
}

Main class


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        System.out.println("Enter Student First Name: ");
        String firstName = sc.nextLine();

        System.out.println("Enter Student Last Name: ");
        String lastName = sc.nextLine();
        
        System.out.println("Enter Student balance: ");
        int balance = sc.nextInt();

        StudentRecord student = new StudentRecord(firstName,lastName,balance);

        System.out.println("Student Information\n");
        System.out.println("FirstName: " + student.getfirstName()  + " " + "LastName: "+ student.getlastName() +" " + "balance: " + student.getbalance());
        System.out.println("FullName: " + student.getfullName());
    }
}

Screenshot

b).

code

public class StudentRecord{
    private String firstName;
    private String lastName;
    private String ID;
    private int balance;

    public StudentRecord(String firstName, String lastName, String ID, int balance) {
        this.firstName = firstName;
        this.lastName = lastName;
        this.ID = ID;
        this.balance = balance;
    }

    public String getfirstName() {
        return firstName;
    }
    public String getlastName() {
        return lastName;
    }
    public String getStudentID() {
        return ID;
    }
    public int getbalance() {
        return balance;
    }
    public String getfullName() {
        return firstName +" " + lastName;
    }
    public void setfirstName(String firstName) {
        this.firstName = firstName;
    }
    public void setlastName(String lastName) {
        this.lastName = lastName;
    }
    public void setStudentID(String ID) {
        this.ID = ID;
    }
    public void setbalance(int balance) {
        this.balance = balance;
    }
}

Main class


import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws FileNotFoundException {
        //change path according to you.
        File file = new File("D:\\Geekster\\csc272input.txt"); 
        Scanner sc = new Scanner(file); 
        String[] splitStr = null;
      

        System.out.println("Student Information\n");
        while (sc.hasNextLine()) {
                String get = sc.nextLine();
                splitStr = get.split("\\s+");
        StudentRecord student = new StudentRecord(splitStr[0],splitStr[1],splitStr[2],Integer.parseInt(splitStr[3]));

        System.out.println(student.getStudentID() + " " + student.getfirstName()  + " " + 
        student.getlastName() + " " + student.getbalance());
       // System.out.println("FullName: " + student.getfullName());
        }
    }
}

Screenshot


Related Solutions

Write a Java program that implements a song database. The SongsDatabase class keeps tracks of song...
Write a Java program that implements a song database. The SongsDatabase class keeps tracks of song titles by classifying them according to genre (e.g., Pop, Rock, etc.). The class uses a HashMap to map a genre with a set of songs that belong to such a genre. The set of songs will be represented using a HashSet. Your driver output should sufficiently prove that your code properly implements the code below. public class SongsDatabase { private Map<String, Set<String>> genreMap =...
Java Programming Create a class named Problem1, and create a main method, the program does the...
Java Programming Create a class named Problem1, and create a main method, the program does the following: - Prompt the user to enter a String named str. - Prompt the user to enter a character named ch. - The program finds the index of the first occurrence of the character ch in str and print it in the format shown below. - If the character ch is found in more than one index in the String str, the program prints...
write the program in java. Develop a class RentCabin that does the following: (use JavaDoc comments)...
write the program in java. Develop a class RentCabin that does the following: (use JavaDoc comments) // declare the constructor that sets the type and rate based in the sqft parm        // set values based on sqft <1000 is small with $100 per night, // sqft between 1000 and 2000, mid-sized $200 per night, and // over 2000 as a large cabin with $300 per night        //declare getRate        //declare getType        //declare setRate with int rate parm...
write the program in java. Demonstrate that you understand how to use create a class and...
write the program in java. Demonstrate that you understand how to use create a class and test it using JUnit Let’s create a new Project HoursWorked Under your src folder, create package edu.cincinnatistate.pay Now, create a new class HoursWorked in package edu.cincinnatistate.pay This class needs to do the following: Have a constructor that receives intHours which will be stored in totalHrs Have a method addHours to add hours to totalHrs Have a method subHours to subtract hours from totalHrs Have...
Write a Java program to process the information for a bank customer.  Create a class to manage...
Write a Java program to process the information for a bank customer.  Create a class to manage an account, include the necessary data members and methods as necessary.  Develop a tester class to create an object and test all methods and print the info for 1 customer.  Your program must be able to read a record from keyboard, calculate the bonus and print the details to the monitor.  Bonus is 2% per year of deposit, if the amount is on deposit for 5 years...
Write a program in java processing. Write a program that does the following: · Assume the...
Write a program in java processing. Write a program that does the following: · Assume the canvas size of 500X500. · The program asks the user to enter a 3 digit number. · The program then checks the value of the first and last digit of the number. · If the first and last digits are even, it makes the background green and displays the three digit number at the mouse pointer. · If the two digits are odd, it...
Program in Java Create a class and name it MyArray and implement following method. * NOTE:...
Program in Java Create a class and name it MyArray and implement following method. * NOTE: if you need more methods, including insert(), display(), etc. you can also implement those. Method name: getKthMin(int k) This method receives an integer k and returns k-th minimum value stored in the array. * NOTE: Items in the array are not sorted. If you need to sort them, you can implement any desired sorting algorithm (Do not use Java's default sorting methods). Example: Items...
Program in Java Create a class and name it MyArray and implement following method. * NOTE:...
Program in Java Create a class and name it MyArray and implement following method. * NOTE: if you need more methods, including insert(), display(), etc. you can also implement those. Method name: getKthMin(int k) This method receives an integer k and returns k-th minimum value stored in the array. * NOTE: Items in the array are not sorted. If you need to sort them, you can implement any desired sorting algorithm (Do not use Java's default sorting methods). Example: Items...
The following program will be written in JAVA. Create a class called complex performing arithmetic with...
The following program will be written in JAVA. Create a class called complex performing arithmetic with complex numbers. Write a program to test your class.                         Complex numbers have the form:                         realPart + imaginaryPart * i                                               ___                         Where i is sqrt(-1)                                                 Use double variables to represent data of the class. Provide a constructor that enables an object of this class to be initialized when it is declared. The constructor should contain default values in...
Write a java program that does the following: a) The user will enter data such as...
Write a java program that does the following: a) The user will enter data such as client name and client balance. The user can stop inputting data by entering "stop". The program should store the user inputs as a data member of an array. The type of this array is a class named ClientData. Below the output should be displayed by the program. The parts in bold are inputs from the user and not hard coded in the program Client...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT