This is for a project code im working on please complete the steps below and the
ID: 3718470 • Letter: T
Question
This is for a project code im working on please complete the steps below and the code is under the steps that I have completed so far and you would only need to work on the ProjectTest2
//Use a for loop to find and print all the projects that have more than 1500 lines of code.
//Use a for loop to find the project with maximum number of lines of code.
//Change the code in Step 2 above into a loop that prompt user to enter the information for each project exactly the same way as in Part 1 of this assignment, create the corresponding Project object and assign that to each array element.
--- for that last step this is what it means by step 2 (((Create three Project objects as follows and assign to each of the array element.
Create one Project object with the following information:
title: Online Bookstore
3 members: Ellen Johnson, Michael Smith, Linda Wang
total number of lines: 2138
Create the second Project object with the following information:
title: D2L Chatroom
2 members: Ming Chen, Harry Williams
total number of lines: 1689
Create the third Project object with the following information:
title: Family Shopping Coordinator
4 members: Allen Brothers, Veronica Harris, Rachel Lee, Robert Jones
total number of lines: 1296)))))
it just wants to change the code in ProjectTest2
here is the code
public class Project {
private String title1;
private String students1;
private int integer1;
public Project(String title1, String sutends1, int integer1) {
this.title1 = title1;
this.students1 = students1;
this.integer1 = integer1;
}
public String getTitle() {
return this.title1;
}
public void setTitle(String title1) {
this.title1 = title1;
}
public String getStudents() {
return this.students1;
}
public void setStudents(String students1) {
this.students1 = students1;
}
public int getInteger() {
return this.integer1;
}
public void setInteger(int integer1) {
this.integer1 = integer1;
}
//printed
@Override
public String toString(){
return "Project: title = " + title1 + " members = " + students1 + " # lines of code = " + integer1;
}
}
import java.util.Scanner;
public class ProjectTest1{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
Project p1 = new Project("Online Bookstore", "Ellen Johnson, Michael Smith, Linda Wang", 2138);
Project p2 = new Project("D2L chatroom", "Ming Chen, Harry Williams", 1689);
Project p3 = new Project("Family Shopping Coordinator", "Allen Brothers, Veronica Harris, Rachel Lee, Robert Jones", 1296);
System.out.println(p1);
System.out.println(p2);
System.out.println(p3);
System.out.print("Please enter the title of the project");
String title1 = input.nextLine();
System.out.print("Please enter the students who worked on the project");
String students1 = input.nextLine();
System.out.print("Please enter the total number of lines of code in the project");
int integer1 = Integer.parseInt(input.nextLine());
int project1 = input.nextInt();
input.nextLine();
Project pa = new Project(title1, students1, integer1);
System.out.print("Online Bookstore");
String title2 = input.nextLine();
System.out.print("Ellen Johnson, Michael Smith, Linda Wang");
String students2 = input.nextLine();
System.out.print("2138");
int integer2 = Integer.parseInt(input.nextLine());
System.out.printf("Title = %s, students = %s, integer = %d ", title2, students2, integer2);
}
}
import java.util.Scanner;
public class ProjectTest2{
public static void main(String[] args){
Scanner input = new Scanner(System.in);
Project[] projects = new Project[3];
projects[0] = new Project("Online Bookstore", "Ellen Johnson, Michael Smith, Linda Wang", 2138);
projects[1] = new Project("D2L chatroom", "Ming Chen, Harry Williams", 1689);
projects[2] = new Project("Family Shopping Coordinator", "Allen Brothers, Veronica Harris, Rachel Lee, Robert Jones", 1296);
Project pa = new Project("Online Bookstore", "Ellen Johnson, Michael Smith, Linda Wang", 2138);
Project pa2 = new Project("D2L Chatroom", "Ming Chen, Harry Williams", 1689);
Project pa3 = new Project("Family Shopping Coordinator", "Ellen Brothers, Veronica Harris, Rachel Lee, Robert Jones", 1296);
System.out.println(pa);
System.out.println(pa2);
System.out.println(pa3);
for(int i = 0; i < projects.length;i++) {
System.out.println(projects[i]);
}
for(int i = 0; i < projects.length;i++) {
if(integer1 > 1500) {
System.out.println(projects[i]);
}
}
}
}
Explanation / Answer
As stated in the question did not change Project.java and ProjectTest1.java(corrected spelling of students1 variable in constructor), Made changes to ProjectTest2.java so that the system prompts input for project details and based on project details, projects with more thatn 1500 lines will be printed and for loop is used to sort the projects based on number of lines and prints the project with maximum number of Lines.
Project.java
public class Project {
private String title1;
private String students1;
private int integer1;
public Project(String title1, String students1, int integer1) {
this.title1 = title1;
this.students1 = students1;
this.integer1 = integer1;
}
public String getTitle() {
return this.title1;
}
public void setTitle(String title1) {
this.title1 = title1;
}
public String getStudents() {
return this.students1;
}
public void setStudents(String students1) {
this.students1 = students1;
}
public int getInteger() {
return this.integer1;
}
public void setInteger(int integer1) {
this.integer1 = integer1;
}
// printed
@Override
public String toString() {
return "Project: title = " + title1 + " members = " + students1 + " # lines of code = " + integer1;
}
}
ProjectTest1.java
import java.util.Scanner;
public class ProjectTest1 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
Project p1 = new Project("Online Bookstore", "Ellen Johnson, Michael Smith, Linda Wang", 2138);
Project p2 = new Project("D2L chatroom", "Ming Chen, Harry Williams", 1689);
Project p3 = new Project("Family Shopping Coordinator",
"Allen Brothers, Veronica Harris, Rachel Lee, Robert Jones", 1296);
System.out.println(p1);
System.out.println(p2);
System.out.println(p3);
System.out.print("Please enter the title of the project");
String title1 = input.nextLine();
System.out.print("Please enter the students who worked on the project");
String students1 = input.nextLine();
System.out.print("Please enter the total number of lines of code in the project");
int integer1 = Integer.parseInt(input.nextLine());
int project1 = input.nextInt();
input.nextLine();
Project pa = new Project(title1, students1, integer1);
System.out.print("Online Bookstore");
String title2 = input.nextLine();
System.out.print("Ellen Johnson, Michael Smith, Linda Wang");
String students2 = input.nextLine();
System.out.print("2138");
int integer2 = Integer.parseInt(input.nextLine());
System.out.printf("Title = %s, students = %s, integer = %d ", title2, students2, integer2);
}
}
ProjectTest2.java
import java.util.Scanner;
public class ProjectTest2 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
// Enter the project details
Project[] projectsEntered = new Project[3];
for (int j = 0; j < 3; j++) {
System.out.print(" Please enter the title of the project " + (j + 1) + ":");
String title = input.nextLine();
System.out.print("Please enter the students who worked on the project" + (j + 1) + ":");
String students = input.nextLine();
System.out.print("Please enter the total number of lines of code in the project" + (j + 1) + ":");
int totalNoOfLines = Integer.parseInt(input.nextLine());
Project project = new Project(title, students, totalNoOfLines);
projectsEntered[j] = project;
}
// for loop to find and print all the projects that have more than
// 1500 lines of code.
System.out.println(" Projects with more than 1500 lines of code:");
for (int i = 0; i < projectsEntered.length; i++) {
if (projectsEntered[i].getInteger() > 1500) {
System.out.println(projectsEntered[i].toString());
}
}
// for loop to sort the projects Entered in descending order so that
// first project of the sorted array has maximum lines
Project maxNoOfLines = projectsEntered[0];
for (int i = 1; i < projectsEntered.length; i++) {
if (projectsEntered[i - 1].getInteger() < projectsEntered[i].getInteger()) {
// swap elements
maxNoOfLines = projectsEntered[i - 1];
projectsEntered[i - 1] = projectsEntered[i];
projectsEntered[i] = maxNoOfLines;
}
}
System.out.println(" Project With Maximum number of Lines: ");
System.out.println(projectsEntered[0]);
input.close();
}
}
Sample output:
Please enter the title of the project 1:Online Bookstore
Please enter the students who worked on the project1:Ellen Johnson, Michael Smith, Linda Wang
Please enter the total number of lines of code in the project1:2138
Please enter the title of the project 2:D2L Chatroom
Please enter the students who worked on the project2:Ming Chen, Harry Williams
Please enter the total number of lines of code in the project2:1689
Please enter the title of the project 3:Family Shopping Coordinator
Please enter the students who worked on the project3:Allen Brothers, Veronica Harris, Rachel Lee, Robert Jones
Please enter the total number of lines of code in the project3:1296
Projects with more than 1500 lines of code:
Project: title = Online Bookstore members = Ellen Johnson, Michael Smith, Linda Wang # lines of code = 2138
Project: title = D2L Chatroom members = Ming Chen, Harry Williams # lines of code = 1689
Project With Maximum number of Lines:
Project: title = Online Bookstore members = Ellen Johnson, Michael Smith, Linda Wang # lines of code = 2138
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.