Question: please assist me with corrections for this task. Task Compulsory Task Follow these steps: Open the first Capstone Project that you created in this level
please assist me with corrections for this task.
Task
Compulsory Task Follow these steps: Open the first Capstone Project that you created in this level (the object-oriented program for a structural engineering company called Poised.) Enhance your program by doing the following: Incorporate exception handling to your code. Your code should include at least two try-catch blocks (Go back to the Defensive Programming task if youre not sure where to start). Make sure all your code is properly debugged. Make sure that the runtime and logical errors are also identified and corrected. Fix the indentation and formatting of the code so that it adheres to the guidelines provided here. Make sure that all the names of variables, classes, methods, etc. adhere to the guidelines provided here. Refactor the code to improve the quality and readability of the code in other ways highlighted in this project.
correction
Unfortunately your code only incorporated one try catch block whereas the task requires that you have at least two. I would suggest focusing your try catch block on one case at a time. For each input that requires digits you could implement one of these.
Code to be corrected
//Importing java utilities import java.util.Scanner; // creating class public class Main { // Creating main method public static void main(String[] args) { // creating scanner Scanner input = new Scanner(System.in); // try statement to define a block of code to be tested for errors while it is being executed try { // Create a new project object System.out.print("Enter project name: "); String projectName = input.nextLine(); System.out.print("Enter project due date: "); String dueDate = input.nextLine(); System.out.print("Enter project fee: "); double fee = input.nextDouble(); Project project = new Project(projectName, dueDate, fee); // Create a new person object System.out.print("Enter person's name: "); String personName = input.nextLine(); System.out.print("Enter person's role: "); String role = input.nextLine(); System.out.print("Enter person's contact details: "); String contactDetails = input.nextLine(); Person person = new Person(personName, role, contactDetails); // Change the due date of the project System.out.print("Enter new due date for project: "); String newDueDate = input.nextLine(); project.setDueDate(newDueDate); // Change the total amount of the fee paid to date System.out.print("Enter new fee paid to date for project: "); double newFeePaid = input.nextDouble(); project.setFeePaid(newFeePaid); // Update a contractor's contact details System.out.print("Enter new contact details for person: "); String newContactDetails = input.nextLine(); person.setContactDetails(newContactDetails); // Finalise the project project.finalise(); } catch (Exception e) { System.out.println("An error occurred: " + e.getMessage()); } finally { input.close(); } } } // create class for people class Project { // creating attributes and defining them private String name; private String dueDate; private double fee; private double feePaid; private boolean finalised; // Creating Constuctor public Project(String name, String dueDate, double fee) { this.name = name; this.dueDate = dueDate; this.fee = fee; this.feePaid = 0; this.finalised = false; } // creating getters and setters to edit public void setDueDate(String dueDate) { this.dueDate = dueDate; } public void setFeePaid(double feePaid) { this.feePaid = feePaid; } public void finalise() { this.finalised = true; } } // creating person class class Person { private String name; private String role; private String contactDetails; // Creating constructor public Person(String name, String role, String contactDetails) { this.name = name; this.role = role; this.contactDetails = contactDetails; } // Creating setters for editing purposes public void setContactDetails(String contactDetails) { this.contactDetails = contactDetails; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
