#I am facing some logical issues, just started coding in java a week ago

1 messages ยท Page 1 of 1 (latest)

delicate burrowBOT
#

<@&987246399047479336> please have a look, thanks.

delicate burrowBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

#

Here is an AI assisted attempt to answer your question ๐Ÿค–. Maybe it helps! In any case, a human is on the way ๐Ÿ‘. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.

#

ve to create objects of module in assessment and pass the tests

Here are the tests:

  1. Create a module object with the name "Math" and code "MATH101". Check if the name and code are correct.

  2. Create a module object with the name "Science" and code "SCI201". Check if the name and code are correct.

  3. Create an assessment object with the title "Quiz 1" and maximum marks 20. Check if the title and maximum marks are correct.

  4. Create an assessment object with the title "Midterm Exam" and maximum marks 50. Check if the title and maximum marks are correct.

  5. Add both assessments to the Math module. Check if both assessments are added successfully.

  6. Add both assessments to the Science module. Check if both assessments are added successfully.

  7. Calculate the average marks for all assessments in the Math module. The average should be 35 (20 + 50) / 2 = 35.

  8. Calculate the average marks for all assessments in the Science module. The average should be 35 (20 + 50) / 2 = 35.

Here is my code:

Module.java:

public class Module {
private String name;
private String code;
private List<Assessment> assessments;

public Module(String name, String code) {
    this.name = name;
    this.code = code;
#

this.assessments = new ArrayList<>();
}

public String getName() {
    return name;
}

public String getCode() {
    return code;
}

public List<Assessment> getAssessments() {
    return assessments;
}

public void addAssessment(Assessment assessment) {
    assessments.add(assessment);
}

}

Assessment.java:

public class Assessment {
private String title;
private int maxMarks;

public Assessment(String title, int maxMarks) {
    this.title = title;
    this.maxMarks = maxMarks;
}

public String getTitle() {
    return title;
}

public int getMaxMarks() {
    return maxMarks;
}

}

Main.java:

public class Main {
public static void main(String[] args) {
// Create module objects
Module mathModule = new Module("Math", "MATH101");
Module scienceModule = new Module("Science", "SCI201");

    // Check if the name and code are correct for Math module
    System.out.println(mathModule.getName().equals("Math")); // Should print true
    System.out.println(mathModule.getCode().equals("MATH101")); // Should print true

    // Check if the name and code are correct for Science module
    System.out.println(scienceModule.getName().equals("Science")); // Should print true
#

System.out.println(scienceModule.getCode().equals("SCI201")); // Should print true

    // Create assessment objects
    Assessment quiz1 = new Assessment("Quiz 1", 20);
    Assessment midtermExam = new Assessment("Midterm Exam", 50);

    // Check if the title and maximum marks are correct for Quiz 1 assessment
    System.out.println(quiz1.getTitle().equals("Quiz 1")); // Should print true
    System.out.println(quiz1.getMaxMarks() == 20); // Should print true

   // Check if the title and maximum marks are correct for Midterm Exam assessment
   System.out.println(midtermExam.getTitle().equals("Midterm Exam")); // Should print true
   System.out.println(midtermExam.getMaxMarks() == 50); // Should print true

   // Add assessments to Math module
   mathModule.addAssessment(quiz1);
   mathModule.addAssessment(midtermExam);

   // Check if both assessments are added successfully to Math module
   System.out.println(mathModule.getAssessments().contains(quiz1)); // Should print true
   System.out.println(mathModule.getAssessments().contains(midtermExam)); // Should print true

   // Add assessments to Science module
   scienceModule.addAssessment(quiz1);
   scienceModule.addAssessment(midtermExam);
#

// Check if both assessments are added successfully to Science module
System.out.println(scienceModule.getAssessments().contains(quiz1)); // Should print true
System.out.println(scienceModule.getAssessments().contains(midtermExam)); // Should print true

   // Calculate average marks for all assessments in Math module
   int mathTotalMarks = 0;
   List<Assessment> mathAssessments = mathModule.getAssessments();
   for (Assessment assessment : mathAssessments) {
       mathTotalMarks += assessment.getMaxMarks();
    }
    double mathAverageMarks = (double) mathTotalMarks / mathAssessments.size();
    System.out.println(mathAverageMarks == 35.0); // Should print true

    // Calculate average marks for all assessments in Science module
    int scienceTotalMarks = 0;
    List<Assessment> scienceAssessments = scienceModule.getAssessments();
    for (Assessment assessment : scienceAssessments) {
        scienceTotalMarks += assessment.getMaxMarks();
    }
    double scienceAverageMarks = (double) scienceTotalMarks / scienceAssessments.size();
    System.out.println(scienceAverageMarks == 35.0); // Should print true
}

}

Please let me know if there are any logical issues or errors in my code.

cobalt violet
#

ah

high carbon
#

try debugging

cobalt violet
#

that redtext comes from debugging

#

in the ss

#

OHH wait

#

I didnt read a very important part in the question

#

My problem is solved now

#

Thanks

velvet halo
cobalt violet