Related questions
For beginning Java, two things
1) I got this error from my code and how and where can I fix it:
Main.java:133: error: reached end of file while parsing } ^ 1 error
2) I was told my code is too long and needs to be separate files. How can I fix this into separate Java files?
3) I need to Draw the UML diagram using MS Word or PowerPoint for the classes and implement them.
My original assignment is attached.
Here's my code:
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.time.LocalDate;
class Person {
private String name;
private String address;
private String phoneNumber;
private String emailAddress;
public Person(String name, String address, String phoneNumber, String emailAddress) {
this.name = name;
this.address = address;
this.phoneNumber = phoneNumber;
this.emailAddress = emailAddress;
}
@Override
public String toString() {
return "Person: " + name + "\nAddress: " + address + "\nPhone Number: " + phoneNumber +
"\nEmail Address: " + emailAddress;
}
}
class Student extends Person {
private String classStatus;
public Student(String name, String address, String phoneNumber, String emailAddress, String classStatus) {
super(name, address, phoneNumber, emailAddress);
this.classStatus = classStatus;
}
@Override
public String toString() {
return super.toString() + "\nClass: Student" + "\nClass Status: " + classStatus;
}
}
class Employee extends Person {
private double salary;
private LocalDate dateHired;
public Employee(String name, String address, String phoneNumber, String emailAddress, double salary, LocalDate dateHired) {
super(name, address, phoneNumber, emailAddress);
this.salary = salary;
this.dateHired = dateHired;
}
@Override
public String toString() {
return super.toString() + "\nClass: Employee" + "\nSalary: " + salary + "\nDate Hired: " + dateHired;
}
}
class Faculty extends Employee {
private String officeHours;
private String discipline;
public Faculty(String name, String address, String phoneNumber, String emailAddress, double salary, LocalDate dateHired,
String officeHours, String discipline) {
super(name, address, phoneNumber, emailAddress, salary, dateHired);
this.officeHours = officeHours;
this.discipline = discipline;
}
@Override
public String toString() {
return super.toString() + "\nClass: Faculty" + "\nOffice Hours: " + officeHours + "\nDiscipline: " + discipline;
}
}
class Staff extends Employee {
private String title;
public Staff(String name, String address, String phoneNumber, String emailAddress, double salary, LocalDate dateHired,
String title) {
super(name, address, phoneNumber, emailAddress, salary, dateHired);
this.title = title;
}
@Override
public String toString() {
return super.toString() + "\nClass: Satff" + "\nTitle: " + title;
}
}
// test
public class Main {
public static void main(String[] args) {
// Read data from a text file
try (BufferedReader br = new BufferedReader(new FileReader("data.txt"))) {
String line;
while ((line = br.readLine()) != null) {
String[] data = line.split(",");
switch (data[0]) {
case "Person":
if (data.length >= 5) {
Person person = new Person(data[1], data[2], data[3], data[4]);
System.out.println(person);
}
break;
case "Student":
if (data.length >= 6) {
Student student = new Student(data[1], data[2], data[3], data[4], data[5]);
System.out.println(student);
}
break;
case "Employee":
if (data.length >= 6) {
LocalDate dateHired = LocalDate.parse(data[5]);
Employee employee = new Employee(data[1], data[2], data[3], data[4], Double.parseDouble(data[5]), dateHired);
System.out.println(employee);
}
break;
case "Faculty":
if (data.length >= 8) {
LocalDate facultyDateHired = LocalDate.parse(data[6]);
Faculty faculty = new Faculty(data[1], data[2], data[3], data[4], Double.parseDouble(data[5]), facultyDateHired, data[6], data[7]);
System.out.println(faculty);
}
break;
case "Staff":
if (data.length >= 7) {
LocalDate staffDateHired = LocalDate.parse(data[5]);
Staff staff = new Staff(data[1], data[2], data[3], data[4], Double.parseDouble(data[5]), staffDateHired, data[6]);
System.out.println(staff);
}
break;
default:
System.out.println("Invalid entry");
break;
}
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images
- the following code is centered around data collection, filtering, and using the Singleton pattern in Java, which is all part of a mockup "student information management system", with its purpose being making mockup new student accounts. I've been having issues using the software "dbeaver" for making java projects. Please organize the below code into an executable project "simulation.student" and given step by step instruction as to how this was done Address.java public class Address {private String _city;private String _state;private String _streetName; // Newprivate int _streetNumber; // Newprivate int _apartmentNumber; // New public Address(String city, String state, int zip, String streetName, int streetNumber, int apartmentNumber) {setCity(city);setState(state);setZip(zip);setStreetName(streetName);setStreetNumber(streetNumber);setApartmentNumber(apartmentNumber);} public String getCity() {return _city;} public void setCity(String city) {_city = city;} public String getState()...arrow_forwardI need help with this Java program. I got some minor error that I couldn't fix. Checker Classes You will have to implement specific checks to highlight errors found in the source files. We provided an interface Check.java that defines a single method public Optional<Error> lint(String line, int lineNumber) . All the checkers you write should implement this interface and hence, you need to implement the lint method. All of these should return an an Error when one is present with a custom message of your choosing to describe what the error means to the user. If the condition a Check is looking for is not present for a line, should return Optional.empty(). Other class Error.java public Error(int code, int lineNumber, String message) Constructs an Error given the error code, line number and a message. public String toString() Returns a String representation of the error with the line number, error code and message. The representation should be formatted as (replace curly braces with...arrow_forwardI need help with this Java program. I got some minor error that I couldn't fix. Checker Classes You will have to implement specific checks to highlight errors found in the source files. We provided an interface Check.java that defines a single method public Optional<Error> lint(String line, int lineNumber) . All the checkers you write should implement this interface and hence, you need to implement the lint method. All of these should return an an Error when one is present with a custom message of your choosing to describe what the error means to the user. If the condition a Check is looking for is not present for a line, should return Optional.empty(). Other class Error.java public Error(int code, int lineNumber, String message) Constructs an Error given the error code, line number and a message. public String toString() Returns a String representation of the error with the line number, error code and message. The representation should be formatted as (replace curly braces with...arrow_forward
- Design a Java interface called Priority that includes two methods: setPriority and getPriority. This interface would define a way to establish numeric priority among a set of objects. Your numeric priority values should be on a scale. For easy comparing of priorities, make 1 the lowest priority. It should be more complex than just 1, 2, 3 (low, medium, high). Define constants in the interface for the low, medium, and high priority values. Design and implement a class called Task that represents a task (e.g., something on a to-do list) that implements the Priority interface from above, as well as the Comparable interface from the Java standard class library. A task should have some sort of description. Illustrate your design with a UML class diagram. Create a driver whose main method exercises some Task objects. Make sure you have enough tasks to produce comparisons where a given task is higher, lower, or equal in priority to some other task. Implement the interface such that the tasks...arrow_forwardDevelop a program (or find one on the internet) to exemplify and document dynamic binding). A parent and two or more child classes are needed. Shape, Triangle, Rectangle are common examples where Shape is the parent and Triangle and Rectangle are the child classes. Create a project for the program, add the parent and childs classes to it. Use main to exemplify dynamic binding by creating an array or ArrayList of the parent class type and filling it with objects of the child class types. Loop through the array and display all the objects in it by calling their toString method. Then create a method whose parameter is the parent class type. Have main call the method sending it the child types. What the method does is up to you. Heavily document this program since this is not a prescribed assignment. I want to read your words. So I want you telling me what it does, how it does it, and how it has anything to do with dynamic binding. Then using screen capture software, take...arrow_forwardimport java.util.Scanner; public class LabProgram { public static Roster getInput(){ /* Reads course title, creates a roster object with the input title. Note that */ /* the course title might have spaces as in "COP 3804" (i.e. use nextLine) */ /* reads input student information one by one, creates a student object */ /* with each input student and adds the student object to the roster object */ /* the input is formatted as in the sample input and is terminated with a "q" */ /* returns the created roster */ /* Type your code here */ } public static void main(String[] args) { Roster course = getInput(); course.display(); course.dislayScores(); }} public class Student { String id; int score; public Student(String id, int score) { /* Student Employee */ /* Type your code here */ } public String getID() { /* returns student's id */...arrow_forward
- Please answer question. This is pertaining to Java programming language 2-13arrow_forwardPlease give a full detailed optimized solution in Java 8 for the given problem, use the example code provided as well. Please provide comments and screenshots of code and output. Also, add the time/space complexity and the reason for it.Java 8 Code Example:import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { public static void main(String args[] ) throws Exception { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ } }arrow_forwardSuppose I have implemented classes C and D, where D extends C. "Just for fun" I want to write code such that a variable of type D refers to an object of type C. I’m allowed to use assignments, casts and so on. Explain why Java will make it impossible for me to achieve my goal.arrow_forward
- In Java!!!!!This is a multi-part question. Consider the following UML diagram on attached image: 1.Write Java classes corresponding to the UML diagram. 2. Write getters and setters for all classes 3. Write non-default constructors for each class that initializes all instance variables to values passed as arguments to the constructor 4. Write toString method for each class 5. Modify Vehicle class to maintain inventory (list of all vehicles created) and print the list. What variable(s) you need to add? What additional method(s) you need? What else needs to be modified in the Vehicle class? Do you need to modify any of the descendant classes and explain your answer (if not: why not; if yes, describe what changes). Vehicle {Abstract} manufacturer:String - color:String Car Truck TwoWheeler {Abstract} -numberOfDoors:int -numberOfAxels:int -passengerSeats:int -fuelType:String -fuelLevel:int -fuelType:String -numberOfSeats:int -fuelLevel:int Truck Motorcycle -numberOfAxels:int -fuelType:String...arrow_forwardPlease help with the following question: In Java without using arrays, Integer.parseInt in the main class or this.keyword in the classes code the following. Make 1 project having 1 main class and 3 other classes. For each classes you need make to use the constructor to set its attributes. Your classes have to have setters and getters and their attributes should all be private. Make a class University A university name (string)A university population (int)A university budget(double) Make a class Department An ID(int)A Name(string)A DEP ID(int) Make a class Student Dep Name(string)Dep ID(int) In the main class first Create three departments.Ask the user to input the field values. In the main class create 5 students. Ask the user to input the field values. Write a function in the main class that takes two integers as input and Checks if they are equal. Use that function to check if for a department and a student their DEP ID is equal. (So you have to check if dep1.di=student1.id for...arrow_forwardPlease write the code in Java eclipse.arrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education