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...
Write by hand a full java program that will prompt the user for the length and...
Write by hand a full java program that will prompt the user for the length and width of a square, calculate and display the area of that square rounded to the nearest tenth with an appropriate message.
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.
Answer in JAVA Write a program that would prompt the user to enter an integer. The...
Answer in JAVA Write a program that would prompt the user to enter an integer. The program then would displays a table of squares and cubes from 1 to the value entered by the user. The program should prompt the user to continue if they wish. Name your class NumberPowers.java, add header and sample output as block comments and uploaded it to this link. Use these formulas for calculating squares and cubes are: square = x * x cube =...
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.
Write a Java program called Decision that includes a while loop to prompt the user to...
Write a Java program called Decision that includes a while loop to prompt the user to enter 5 marks using the JOptionPane statement and a System. Out statement to output a message inside the loop highlighting a pass mark >= 50 and <= 100. Any other mark will output a messaging stating it’s a fail.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT