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 =...
Using Java create a program that does the following: Modify the LinkedList1 class by adding sort()...
Using Java create a program that does the following: Modify the LinkedList1 class by adding sort() and reverse() methods. The reverse method reverses the order of the elements in the list, and the sort method rearranges the elements in the list so they are sorted in alphabetical order. Do not use recursion to implement either of these operations. Extend the graphical interface in the LinkedList1Demo class to support sort and reverse commands, and use it to test the new methods....
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 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...
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 program in java Create a class named PersonalDetails with the fields name and address. The...
write program in java Create a class named PersonalDetails with the fields name and address. The class should have a parameterized constructor and get method for each field.  Create a class named Student with the fields ID, PersonalDetails object, major and GPA. The class should have a parameterized constructor and get method for each field. Create an application/class named StudentApp that declare Student object. Prompts (GUI input) the user for student details including ID, name, address, major and GPA....
Create a Project and a Class called “FinalGrade” Write a Java program to compute your final...
Create a Project and a Class called “FinalGrade” Write a Java program to compute your final grade for the course. Assume the following (you can hard-code these values in your program). Assignments are worth 30% Labs are worth 40% Mid-term is worth 15% Final is worth 15% Ask for the grades in each category. Store them in a double variable. Print out the final percentage grade.           For example, Final Grade Calculation Enter percentage grades in the following order. Assignments,...
Write a java program using the following instructions: Write a program that determines election results. Create...
Write a java program using the following instructions: Write a program that determines election results. Create two parallel arrays to store the last names of five candidates in a local election and the votes received by each candidate. Prompt the user to input these values. The program should output each candidates name, the votes received by that candidate, the percentage of the total votes received by the candidate, and the total votes cast. Your program should also output the winner...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT