Question

In: Computer Science

Java Programming Language Scenario: write a program that will prompt a user for 10 legendary people/characters....

Java Programming Language

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. Store these characters in an array.

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.

Use an array to store the 10 characters

Create methods that will display the information for each character in the array

Solutions

Expert Solution

import java.util.*;

//Characters class
class Characters
{
//private data member declaration
String First;
String Last;
String Nickname;
String Role;
String Origin;
  
//dafault constructor
Characters()
{
  
}
  
//get method
public String getFirst()
{
return First;
}
  
public String getLast()
{
return Last;
}
  
public String getNickname()
{
return Nickname;
}
  
public String getRole()
{
return Role;
}
  
public String getOrigin()
{
return Origin;
}
  
//set method
public void setFirst(String first)
{
First = first;
}
  
public void setLast(String last)
{
Last = last;
}
  
public void setNickname(String nickname)
{
Nickname = nickname;
}
  
public void setRole(String role)
{
Role = role;
}
  
public void setOrigin(String origin)
{
Origin = origin;
}
public String toSttring()
{
return "\nFirst: "+First+"\nLast: "+Last+"\nNickname: "+Nickname+"\nRole: "+Role+"\nOrigin: "+Origin;
}
}

public class Main
{
   public static void main(String[] args)
   {
   //scanner declaration for input
   Scanner input = new Scanner(System.in);
   Characters c[] = new Characters[10];
   for(int i=0; i<10; i++)
   {
   c[i] = new Characters();
   }

//input characters info
   for(int i=0; i<2; i++)
   {
   System.out.print("\n\nEnter the details of character "+(i+1)+": ");
   System.out.print("\nFirst: ");
   c[i].setFirst(input.nextLine());
   System.out.print("Last: ");
   c[i].setLast(input.nextLine());
   System.out.print("Nickname: ");
   c[i].setNickname(input.nextLine());
   System.out.print("Role: ");
   c[i].setRole(input.nextLine());
   System.out.print("Origin: ");
   c[i].setOrigin(input.nextLine());
   }
  
   //display character info
   for(int i=0; i<2; i++)
   {
   System.out.print("\n\nThe details of character "+(i+1)+": ");
   System.out.println(c[i].toSttring());
   }
      
   }
}

OUTPUT:

Enter the details of character 1:
First: Tom
Last: Jarry
Nickname: TJ
Role: Dancer
Origin: US


Enter the details of character 2:
First: Sam
Last: s singh Singh
Nickname: SS
Role: Writer
Origin: JD AUS


The details of character 1:
First: Tom
Last: Jarry
Nickname: TJ
Role: Dancer
Origin: US


The details of character 2:
First: Sam
Last: Singh
Nickname: SS
Role: Writer
Origin: AUS



Related Solutions

IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user to enter the name of the month he/she was born in (example: September). b) Prompt the user to enter his/her weight in pounds (example: 145.75). c) Prompt the user to enter his/her height in feet (example: 6.5). d) Display (print) a line of message on the screen that reads as follows: You were born in the month of September and weigh 145.75 lbs. and...
(b) You will write a program that will do the following: prompt the user enter characters...
(b) You will write a program that will do the following: prompt the user enter characters from the keyboard, you will read the characters until reading the letter ‘Q’ You will compute statistics concerning the type of characters entered. In this lab we will use a while loop. We will read characters from stdin until we read the character ‘Q’. Example input mJ0*5/]+x1@3qcxQ The ‘Q’ should be included when computing the statistics properties of the input. Since characters are integers...
Using Java, write a program named MyAngles that will prompt the user for the measure of...
Using Java, write a program named MyAngles that will prompt the user for the measure of the three sides of a triangle and then reports the measurement of each interior angle of the triangle and the area of the triangle.
JAVA Write a java program that will sum all positive number. Prompt the user to enter...
JAVA Write a java program that will sum all positive number. Prompt the user to enter numbers and add all positive numbers. The program will not add negative numbers and the program will stop when you enter ‘0’.   Enter a number> 25 Enter a number> 9 Enter a number> 5 Enter a number> -3 Enter a number> 0 Sum = 39
I need a java code Write a simple program to prompt the user for a number...
I need a java code Write a simple program to prompt the user for a number between 1 and 12 (inclusive) and print out the corresponding month. For example:   The 12th month is December. Use a java "switch" statement to convert from the number (1-12) to the month. Also use a "do while" loop and conditional checking to validate that the number entered is between 1 and 12 inclusive and if not, prompt the user again until getting the correct...
Write a java program that prompt the user to insert last term’s courses and their individual...
Write a java program that prompt the user to insert last term’s courses and their individual mark and store them in an appropriate multidimensional array.
Using Java! Write a program that ask prompt the user to enter a dollar amount as...
Using Java! Write a program that ask prompt the user to enter a dollar amount as double. Then, calculate how many quarters, dimes, nickels and pennies are in the dollar amount. For example: $2.56 = 10 quarters, 1 dime, 1 nickel and 1 cent. Print all of the values. Hint: Use Modulus operator and integer division when necessary.
Java Programming: Write a program that allows the user to compute the power of a number...
Java Programming: Write a program that allows the user to compute the power of a number or the product of two numbers. Your program should prompt the user for the following information: • Type of operation to perform • Two numbers (the arguments) for the operation to perform The program then outputs the following information: • The result of the mathematical operation selected. Menu to be displayed for the user: MATH TOOL 1. Compute the power of a number 2....
Time Calculator – Intro To Programming - JAVA Write a program that asks the user to...
Time Calculator – Intro To Programming - JAVA Write a program that asks the user to enter a number of seconds. • There are 60 seconds in a minute. If the number of seconds entered by the user is greater than or equal to 60, the program should display the number of minutes in that many seconds. • There are 3,600 seconds in an hour. If the number of seconds entered by the user is greater than or equal to...
THIS IS JAVA PROGRAMMING Guessing the Capitals. Write a program Lab5.java that repeatedly prompts the user...
THIS IS JAVA PROGRAMMING Guessing the Capitals. Write a program Lab5.java that repeatedly prompts the user to enter a capital for a state (by getting a state/capital pair via the StateCapitals class. Upon receiving the user’s input, the program reports whether the answer is correct. The program should randomly select 10 out of the 50 states. Modify your program so that it is guaranteed your program never asks the same state within one round of 10 guesses.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT