Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;

}
}
}
Posted
Updated 5-Apr-18 21:58pm
Comments
Richard MacCutchan 6-Apr-18 4:01am    
What is your question? And please do not assume that someone here is going to do your work for you.

1 solution

So, you show no attempt to solve the problem yourself, you have no question, you just want us to do your HomeWork.
HomeWork problems are simplified versions of the kind of problems you will have to solve in real life, their purpose is learning and practicing.
We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
Any failure of you will help you to learn what works and what don't, it is called 'trial and error' learning.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900