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...
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
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.
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...
java language NetBeans Write a program that prompts the user to enter the weight of a...
java language NetBeans Write a program that prompts the user to enter the weight of a person in kilograms and outputs the equivalent weight in pounds. Output both the weights rounded to two decimal places. (Note that 1 kilogram = 2.2 pounds.) Format your output with two decimal places.
C# Programming Language Write a C# program ( Console or GUI ) that prompts the user...
C# Programming Language Write a C# program ( Console or GUI ) that prompts the user to enter the three examinations ( test 1, test 2, and test 3), homework, and final project grades then calculate and display the overall grade along with a message, using the selection structure (if/else). The message is based on the following criteria: “Excellent” if the overall grade is 90 or more. “Good” if the overall grade is between 80 and 90 ( not including...
Create in Java a program that will prompt the user to enter aweight for a...
Create in Java a program that will prompt the user to enter a weight for a patient in kilograms and that calculates both bolus and infusion rates based on weight of patient in an interactive GUI application, label it AMI Calculator. The patients weight will be the only entry from the user. Use 3999 as a standard for calculating BOLUS: To calculate the BOLUS you will multiply 60 times the weight of the patient for a total number. IF the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT