Question

JAVA Programming scenario: write a program that will prompt a user for 10 legendary people/characters. After...

JAVA Programming

scenario: write a program that will prompt a user for 10 legendary people/characters. After the entries are complete the program will display all 10 characters information.

requirements:

Create a user-defined class with the fields below:

- First

- Last

- Nickname

- Role

- Origin

Create a main-source that will use the user-defined class and do the prompting.

Create get/set methods in your user-defined class and methods in the main-source.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
The user defined calss that accepts the fields ,First,Last,Nickname,Role,Origin is called UserFields and the main source class is called LedendaryClass

code:

import java.util.Scanner;

class  UserFields
{
    public String first,last,nickname,role,origin;


    public UserFields(String first,String last,String  nickname,String role,String origin)
    {
        this.first = first;
        this.last = last;
        this.nickname = nickname;
        this.origin = origin;
        this.role = role;
    }


    public String getFirst() {
        return first;
    }

    public void setFirst(String first) {
        this.first = first;
    }

    public String getLast() {
        return last;
    }

    public void setLast(String last) {
        this.last = last;
    }

    public String getNickname() {
        return nickname;
    }

    public void setNickname(String nickname) {
        this.nickname = nickname;
    }

    public String getRole() {
        return role;
    }

    public void setRole(String role) {
        this.role = role;
    }

    public String getOrigin() {
        return origin;
    }

    public void setOrigin(String origin) {
        this.origin = origin;
    }
}


public class LegendaryClass
{

    public static void main(String[] args)
    {
        // for 10  legendary people/characters
        int n = 10;

        // temp variables
        String first,last,nickname,role,origin;


        Scanner scanner = new Scanner(System.in);

        UserFields arr[] = new UserFields[n];

        for(int i=0;i<n;i++)
        {
            System.out.println("Enter details for character "+(i+1));
            System.out.print("Enter First name:");
            first = scanner.next();

            System.out.print("Enter Last name:");
            last = scanner.next();

            System.out.print("Enter Nickname:");
            nickname = scanner.next();

            System.out.print("Enter Role:");
            role = scanner.next();

            System.out.print("Enter Origin:");
            origin = scanner.next();

            //using setter to set the values
            arr[i] = new UserFields(first,last,nickname,role,origin);


        }

        for(int i = 0;i<n;i++)
        {
            System.out.println("Details of character "+(i+1));
            System.out.println("First name:"+arr[i].getFirst());
            System.out.println("Last name:"+arr[i].getLast());
            System.out.println("Nickname:"+arr[i].getNickname());
            System.out.println("Role:"+arr[i].getRole());
            System.out.println("Origin:"+arr[i].getOrigin());
            System.out.println("************************************");
        }
}


}

Output: (for this output I have taken n to be 3)

LegendaryClass
Enter details for character 1
Enter First name:naruto
Enter Last name:uzumaki
Enter Nickname:naruto
Enter Role:hokage
Enter Origin:knonha
Enter details for character 2
Enter First name:bruce
Enter Last name:lee
Enter Nickname:phoenix
Enter Role:fighter
Enter Origin:china
Enter details for character 3
Enter First name:nikola
Enter Last name:tesla
Enter Nickname:inventor
Enter Role:inventor
Enter Origin:Serb
Details of character 1
First name:naruto
Last name:uzumaki
Nickname:naruto
Role:hokage
Origin:knonha
************************************
Details of character 2
First name:bruce
Last name:lee
Nickname:phoenix
Role:fighter
Origin:china
************************************
Details of character 3
First name:nikola
Last name:tesla
Nickname:inventor
Role:inventor
Origin:Serb
************************************

Process finished with exit code 0

image of output:

Add a comment
Know the answer?
Add Answer to:
JAVA Programming scenario: write a program that will prompt a user for 10 legendary people/characters. After...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • JAVA PROGRAMMING QUESTION scenario: write a program that will prompt a user for 10 legendary people/characters....

    JAVA PROGRAMMING QUESTION scenario: write a program that will prompt a user for 10 legendary people/characters. After the entries are complete the program will display all 10 characters information. Requirements: Create a user-defined class with the fields below: First Last Nickname Role Origin Create a main-source that will use the user-defined class and do the prompting. Create get/set methods in your user-defined class and methods in the main-source.

  • FOR JAVA: Summary: Create a program that stores info on textbooks. The solution should be named...

    FOR JAVA: Summary: Create a program that stores info on textbooks. The solution should be named TextBookSort.java. Include these steps: Create a class titled TextBook that contains fields for the author, title, page count, ISBN, and price. This TextBook class will also provide setter and getter methods for all fields. Save this class in a file titled TextBook.java. Create a class titled TextBookSort with an array that holds 5 instances of the TextBook class, filled without prompting the user for...

  • Review the structure type address_t described in Programming Project 5 of Chapter 10. Write a program...

    Review the structure type address_t described in Programming Project 5 of Chapter 10. Write a program that will create a binary file of address_t structures by repeatedly prompting the user to enter the IP(internet protocol) address and nickname and writing the address_t structure to the binary file. Create a second program that reads each address_t structure from the binary file and displays it in a readable format on the screen.//////////Here is problem 5 but the part in bold is what...

  • In java, write a program that gets 10 integer numbers from the user using user input,...

    In java, write a program that gets 10 integer numbers from the user using user input, and then calculates and display the sum of the numbers that have been read.   Program Requirements: Write the program in three versions with three loops. Put all three loops in the main method of your source code. version1:  use a while loop. version2:  use a do-while loop. version 3:  use a for loop. For each version, use a loop to input 10 int numbers from the user...

  • In Java 2. Array Exercise ( 10 points) Write a Java program that will prompt the...

    In Java 2. Array Exercise ( 10 points) Write a Java program that will prompt the user to input a size of an array. Create an array of type int. Ask a user to fill the array. Create a functions sortArray() and mostFrequency(). The sortArray() function will sort number into incrementing order. The sorting function must be implemented from scratch and it must not use any function from the library. Feel free to use any sorting algorithm. The program will...

  • In java, write a program that gets 10 integer numbers from the user using user input,...

    In java, write a program that gets 10 integer numbers from the user using user input, and then calculates and display the sum of the numbers that have been read.   Program Requirements: Write the program in three versions with three loops. Put all three loops in the main method of your source code. The program must be in one file. version1:  use a while loop. version2:  use a do-while loop. version 3:  use a for loop. For each version, use a loop to...

  • Write a Java console application that prompts the user to enter the radius of a circle,...

    Write a Java console application that prompts the user to enter the radius of a circle, then prints its radius, diameter, circumference, and area. Write a JavaFX GUI application to do the same calculation, and draw the circle. The Console Output Enter the radius of the circle: 1.2 The radius is 1.2 The diameter is 2.4 The circumference is 7.5398223686155035 The area is 4.523893421169302 Write and document your program per class coding conventions. Add an instance variable double radius. Generate...

  • Write a Java program to meet the following requirements: 1. Prompt the user to enter three...

    Write a Java program to meet the following requirements: 1. Prompt the user to enter three strings by using nextLine(). Space can be part of the string). ( Note: your program requires using loop: for-loop, while-loop or do-while-loop to get the input String ) 2. Write a method with an input variable (string type).The method should return the number of lowercase letters of the input variable. 3. Get the number of the lowercase letters for each user input string by...

  • Java Programming Exercise 9-7 In the exercises in Chapter 6, you created a class named Purchase....

    Java Programming Exercise 9-7 In the exercises in Chapter 6, you created a class named Purchase. Each Purchase contains an invoice number, amount of sale, amount of sales tax, and several methods. Add get methods for the invoice number and sale amount fields so their values can be used in comparisons. Next, write a program that declares an array of five Purchase objects and prompt a user for their values. Then, in a loop that continues until a user inputs...

  • Write a program in Java language to prompt the user to enter 3 integers (A, B,...

    Write a program in Java language to prompt the user to enter 3 integers (A, B, and C) then display these numbers from the lowest to the highest (sorted ascendingly) . Note that there are 6 different cases to handle proper order. As an example, a user entered 10 for A, 5 for B and 14 for C: the output of the program should look like this Enter number A? 10 Enter number B? 5 Enter number C? 14 Your...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT