In: Computer Science
Write a program in java that does the following:
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
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