Design and extend your previous program to do the following:
Create a new Data type named Skill, which represents things that a character knows how to do. Your program should read the list of possible skills from a file (skills.txt). You will need to create this file and its contents. The user will be able to choose a limited number of these skills.
Skill should be a linked list to facilitate reading in an unknown number of skills. Base your class off of the following:
class Skill { String name, String optional, String short_desc, int stat_affinity, int ranks, Skill next_Skill};
Once read in, your program should allow the user to select a number of skills equal to their Level once they have accepted their stats. Once this process is complete, print out the selected skills along with the rest of the character information.
Your program should then offer to make another character or quit.
Bonus XP (note: NOT marks): 1) Either add or create a separate function/program to create/edit your skills. If it is within your main program, it will also need to be able to save the file skills.txt. If it is a separate program it will need to be able to load and save the file skills.txt.
TL:DR - Read Skills in from a file skill.txt. Store them in a linked list. Have user select Level skills. Print Attributes and Skills to the screen.
What I have tried:
package com.company;
import java.io.*;//the program begins with java.io.* to import all the IO classes
import java.text.NumberFormat;
import java.util.Scanner;
public class Skills {
static Scanner sc=new Scanner(System.in);
public static void main(String[] args) {
System.out.println("Choose your preferred skills from the list below,please enter only the number:\n" +
"1.Strength\n" +
"2.Dexterity\n" +
"3.Constitution\n" +
"4.Intelligence\n" +
"5.Wisdom\n" +
"6.Charisma");
int chooseskill=sc.nextInt();
System.out.println(chooseskill);
//program uses a getReader method to create a
// Buffered Reader object that can read a file.
BufferedReader in = getSkill("/Users/natasha/IdeaProjects/Workshop5/Skills.txt");//program uses a getReader method to create a
// Buffered Reader object that can read a file.
Skill skills= readSkill(in);;//Another method readMovie is used to reach each movie
while(chooseskill!=0&&skills != null) {
String msg =skills.title;
System.out.println(msg);
skills = readSkill(in);
}
}
private static BufferedReader getSkill(String name) {
BufferedReader in = null;
try {
File file = new File(name);
in = new BufferedReader(new FileReader(file));
} catch (FileNotFoundException e) {
System.out.println("file does not exist");
System.exit(0);
}
return in;
}
private static Skill readSkill(BufferedReader in) {
String title;
String line = "";
String[] data;
try {
line = in.readLine();
} catch (IOException e) {
System.out.println("I/O Exception");//un-inject language
System.exit(0);
}
if (line == null)
return null;
else {
data = line.split("\t");
title = data[0];
return new Skill(title);
}
}
private static class Skill {
public String title;
public Skill(String title) {
this.title = title;
}
}
}