Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In Java , would anyone know how to create a class diagram/uml from this code. im

ID: 3725378 • Letter: I

Question

In Java, would anyone know how to create a class diagram/uml from this code.

import java.util.Scanner;
/**
*
* @author bjbma
*/
public class GlobalWarmingQuiz {
   
    static Question[] questions;
    static int score;
    static Scanner scanner;
   
    static void initQuestions() {
        questions = new Question[5];
       
        questions[0] = new Question("Which country currently emits the most greenhouse gases?", new String[] { "UK", "US", "China", "India"}, 3);
       
        questions[1] = new Question("Which plante's poisonous atmosphere has been described as the product of a runaway greenhouse effect?", new String[] {"Venus", "Jupiter", "Mars", "Earth"}, 1);
       
        questions[2] = new Question("Which of the following lightbulb types uses the least energy, and therefore results in fewer greenhouse gas emissions?", new String[] {"Incandescent", "Halogen", "Compact flourescent"}, 3);
       
        questions[3] = new Question("How many human deaths per year does the World Health Organization attribute to climate change?", new String[] {"1,500,000", "1,500", "10,500", "150,000"}, 4);
       
        questions[4] = new Question("During what time of day does air travel have the least damaging effect on the environment?", new String [] {"Nighttime", "It makes no difference", "Daytime"}, 3);
       
        score = 0;
   
    }
   
    public static void main(String[] args) {
       
        scanner = new Scanner(System.in);
        initQuestions();
       
        int i = 0;
       
        while (i < questions.length) {
            System.out.println("Question("+(i + 1) + "): " + questions[i].getQuestion());
           
            String[] options = questions[i].getOptions();
           
            for (int j = 0; j < options.length; j++) {
                System.out.println(""+(j + 1) + ":" + options[j]);
            }
           
            System.out.println("Enter choice:");
           
            int choice = Integer.parseInt(scanner.nextLine());
           
            if (choice < 1 || choice > options.length) {
                System.out.println("Invalid choice");
            }
           
            else {
                if (questions[i].isCorrect(choice)) {
                    score++;
                    System.out.println("Correct answer");
                }
               
                else {
                    System.out.println("Wrong answer. The correct option is" + questions[i].getRightOption());
                }
               
                i++;
            }
        }
       
        if (score == 5) {
            System.out.println("Excellent. You have scored" + score + "out of" + questions.length);
        }
       
        else if (score == 4) {
            System.out.println("Very good. You have scored" + score + "out of" + questions.length);
        }
       
        else {
            System.out.println("Time to brush up your knowledge of global warming. You have scored" + score + "out of" + questions.length);
        }
    }
   
}

class Question {
       
        private String question;
        private String[] options;
        private int rightOption;
       
        public Question (String question, String[] options, int rightOption) {
            this.question = question;
            this.options = options;
            this.rightOption = rightOption;
        }
       
        public String getQuestion() {
            return question;
        }
       
        public String[] getOptions() {
            return options;
        }
       
        public int getRightOption() {
            return rightOption;
        }
       
        public boolean isCorrect(int option) {
            if (rightOption == option) {
                return true;
            }
            return false;
        }
    }

Explanation / Answer

Generating UML diagrams from java code is pretty much easy. If you are using Eclipse, then you need to install the Eclipse UML Generators software. Just type 'Eclipse UML Generators' in Google and you will get the link on the top.
If you are using some other IDEs, then you can do the same and search for UML generators in plugins or add/install software option.
Some of the popular, code to UML or reverse ,tools are available such as:

1> www (dot) umldesigner (dot) org

2> www (dot) visual-paradigm (dot) com

The above tools provide easy integration with all the popular IDEs, so that you can easily use them and generate the UML diagrams for your particular class or a whole project.

happy learning :)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote