ArrayList not storing a value - java

In my main, I am asking the user 2 questions. Both questions have 2 correct answers, which is choice number 2 and 4. Whenever I run the Code and select option 2(for both questions), it results in false. If I run the program and select option 4, it results in true. Both options 2 and 4 are correct. I feel as if the issue is due to my UpdateChoices method(located in MultiCheck class), but I don't know why. I used an ArrayList to save the correct choices, but the first correct choice (option 2) is not saved, resulting in it displaying false. Is there a reason why the first option isn't saved in the ArrayList? My output window is posted below the code.
This is the code I have: Main
package pa4_pandeyay;
import java.util.Scanner;
public class MyQuestionDemo {
public static void main(String[] args) {
// TODO code application logic here
MultiCheck first = new MultiCheck();
first.setText("Which number below is prime?");
first.UpdateChoices("4", false);
first.UpdateChoices("3", true);
first.UpdateChoices("12", false);
first.UpdateChoices("7", true);
first.UpdateChoices("8", false);
MultiCheck second = new MultiCheck();
second.setText("Which number below multiplied equals to 12?");
second.UpdateChoices("4 * 4", false);
second.UpdateChoices("12 * 1", true);
second.UpdateChoices("12 * 2", false);
second.UpdateChoices("-6 * -2", true);
second.UpdateChoices("0 * 12", false);
presentQuestion(first);
presentQuestion(second);
}
public static void presentQuestion(MultiCheck x){
x.display();
System.out.print("Your answer: ");
Scanner sc = new Scanner(System.in);
String response = sc.nextLine();
System.out.println(x.checkAnswer(response));
}
}
Java class Question.java
package pa4_pandeyay;
public class Question {
private String text;
private String answer;
// Create a constructor
public Question(){
text = "";
answer = "";
}
// Set the question text
public void setText(String questionText){
text = questionText;
}
//Set the answer text
public void setAnswer(String correctAnswer){
answer = correctAnswer;
}
// Check the respond with the actual correct answer
public boolean checkAnswer(String response){
return response.equals(answer);
}
public String getText(){
return text; // since variable text it private, we need to create a get method in order to access the private variable
}
// Diplay question to the user:
public void display(){
System.out.println(text);
}
}
Java class MultiCheck:
package pa4_pandeyay;
import java.util.ArrayList;
public class MultiCheck extends Question{
private ArrayList<String> answerChoices;
public MultiCheck(){
super();
answerChoices = new ArrayList<String>();
}
public void UpdateChoices (String choice, boolean correct){ // check the asnwers and save the 'true' answers
answerChoices.add(choice);
if (correct == true)
{
//convert choices.size() to string
String choiceString = "" + answerChoices.size();
setAnswer(choiceString);
}
}
// when calling display, this method will be called.
#Override
public void display(){
System.out.println(getText());
// Display the answer choices
for( int i =0; i< answerChoices.size(); i++){
int choiceNumber = i + 1;
System.out.println(choiceNumber + " : " + answerChoices.get(i));
}
}

The Question class can only store one correct answer by setAnswer(). If you have multiple correct answers, then they will override each other so that only the last one is finally in memory.

Related

Cannot display all items in foreach loop(Stack) in Java [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I want to display all items in a stack but it doesn't work.
Here is my Classes:
public class CommandFactory
{
public Command getCommand(String type)
{
if(type.equalsIgnoreCase("c"))
{
return new CreateDVD();
}
//......Other commands
}
return null;
}
public interface DVD
{
int getDvdID();
String getTitle();
int getLength();
int getNumAvailable();
void setNumAvailable(int numAvailable);
String toString();
}
public class Movie implements DVD
{
private int dvdID;
private String title;
private int length;
private int numAvailable;
private String director;
public Movie(int dvdID, String title, int length, int numAvailable, String director)
{
//Constructor
}
public int getDvdID() { return dvdID; }
//...getters and setters
public String toString()
{
return String.format("DVD Information\nID: %d\nTitle: %s\nLength: %d mins\nNumber of available copies: %d\nDirector: %s", dvdID, title, length, numAvailable, director);
}
}
public class CreateDVD implements Command
{
public Stack<DVD> dvdStack = new Stack<>();
private Stack<DVD> dvdUndoStack = new Stack<>();
private DVD dvd;
private DVDFactory dvdFactory = new DVDFactory();
private Scanner kb = new Scanner(System.in);
public void execute()
{
System.out.println("Please enter DVD type (mo=movie/mv=MV)");
String type = kb.next();
dvd = dvdFactory.getDVD(type);
dvdStack.push(dvd);
}
//other methods
}
The implementation below will only show the last item in the stack.
public class DVDHandler
{
Stack<Command> unDoCommandStack = new Stack<>();
Stack<Command> reDoCommandStack = new Stack<>();
Stack<DVD> dvdStack = new Stack<>();
CommandFactory commandFactory = new CommandFactory();
boolean exit = false;
public void run()
{
.
.
.
Scanner kb = new Scanner(System.in);
String input = kb.next();
Command command = commandFactory.getCommand(input);
if(command instanceof CreateDVD)
{
command.execute();
dvdStack = ((CreateDVD) command).getDvdStack();
unDoCommandStack.push(command);
}
.
.
.
else if(input.equalsIgnoreCase("s"))
{
System.out.println("Enter ID(enter a to show all): ");
String input1 = kb.next();
if(input1.equalsIgnoreCase("a"))
{
for (DVD dvd:dvdStack)
{
System.out.println(dvd.toString());
}
}
}
}
}
I have tried to print out the dvdStack and there are multiple items there. I don't why it doesn't work.
And then, I implemented it by using ArrayList below:
ArrayList<DVD> dvdArrayList = new ArrayList<>();
.
.
.
if(command instanceof CreateDVD)
{
command.execute();
dvdArrayList.add( (CreateDVD) command.getDvd() )
unDoCommandStack.push(command);
}
.
.
.
System.out.println("Enter ID(enter a to show all): ");
String input1 = kb.next();
if(input1.equalsIgnoreCase("a"))
{
for (DVD dvd:dvdArrayList)
{
System.out.println(dvd.toString());
}
}
This implementation works for displaying all items. However, I have been told to use stack.
Could someone help me to display all items in stack, please?
Every time you enter "c", a new CreateDVD command is created, which has an empty stack.
Then it's executed, which adds a single DVD to its stack.
Then the DVDHandler's stack is replaced by the stack of the CreateDVD command:
dvdStack = ((CreateDVD) command).getDvdStack();
So it's not surprising to only find one DVD in the stack.
Next time, please post more code so we can help with the issue more clearly. However, based on what you have here, a likely solution is using a for loop and the stack.elementAt method. For example:
public static void stackAttack (int inter){
Stack<Integer> stack=new Stack<Integer>();
stack.push(99);
stack.push(88);
stack.push(77);
stack.push(inter);
for(int n=stack.size(); n>0; n--) {
System.out.println(stack.elementAt(n-1));
}
}
public static void main (String[] args) {
stackAttack(69);
}
will print out each element of the stack in LIFO order without shrinking it. Hope this helps, and please include more info next time.

android studio: having trouble setting global string array

Hi I'm working on an android studio project using global arrays,
I can read from the global arrays fine, and have no problem writing
to the global integers ,But i cannot figure out how to set the global
array from code, this is the important parts of the project:
added this under application tag in the android manifest xml:
android:name=".Globals"
java class Globals:
import android.app.Application;
public class Globals extends Application {
public int empnum=13;
public int getData3() {
return empnum;
}
public void setData3(int empnum) {
this.empnum = empnum;
}
public String[] passw = {"0123","0123","0123","0123","0123","0123","0123","0123","0123","0123","0123","0123","0123"};
public String[] getData4() {
return passw;
}
public void setData4(String[] passw) {
this.passw = passw;
}
public int login=0;
public int getData5() {
return login;
}
public void setData5(int login) {
this.login = login;
}
public String[] empname = {"Name1","Name2","Name3","Name4","Name5","Name6","Name7","Name8","Name9","Name10","Name11","Name12","Name13","Not logged in"};
public String[] getData6() {
return empname;
}
public void setData6(String[] empname) {
this.empname = empname;
}
Here is the block of code I'm having trouble with
inner class of java class TimeIn:
final Globals g = (Globals) getApplication();
final String[] empname = g.getData6();
final String[] passw = g.getData4();
public void onClick(View v) {
i = 0;
String empname = edit2.getText().toString();
int getemn = Integer.parseInt(edit.getText().toString());
if (i == 0 && h == 0) {
g.setData3(getemn);
g.setData6(String[getemn], empname); // This one line right here won't compile, I have tried different combinations but have had 0 luck
i = 1;
h = 1;
}
}
I have no problems getting and using a String array, this is how it works to get
an array value and compare it to a string:
public void onClick(View v) {
i = 0;
String getemp = edit2.getText().toString();
int getemn = Integer.parseInt(edit.getText().toString());
if (i == 0 && getemp.equals(passw[getemn])) { // All of this works perfectly
g.setData3(getemn);
g.setData5(0);
tfone.setText("Empoyee " + getemn);
tftwo.setText("Logged in");
i = 1;
}
if (i == 0 && getemp != (passw[getemn])) {
tfone.setText("No matches found");
edit2.setText("Not logged in");
i = 1;
}
}
So I know this line of code is wrong:
g.setData6(String[getemn], empname);
but for
the life of me I can't figure out how it should be written, the only error hint is I
get from hovering over the line-
array type expected; found 'java.lang.String'
Anyone know what I'm doing wrong?
In Global class, you declare the method with one parameter
public void setData6(String[] empname) {
this.empname = empname;
}
but when you call, you put 2 parameters g.setData6(String[getemn], empname);
You should remove one parameter
or add another method with 2 parameters in Globals class
Also
You are wrong in here
...
String empname = edit2.getText().toString();
int getemn = Integer.parseInt(edit.getText().toString());
...
g.setData6(String[getemn], empname); // This one line right here won't compile, I have tried different combinations but have had 0 luck
The setData6 function now require 2 parameters, one is String array and the other is String
but the way you put the String array to the function is wrong
Here is a simple example that show how to pass the String array to function
public class Test {
public static void setData6(String[] empnameList, String empname) { // with the `String array` you should declare the variable name like `empnameList` or `arrEmpname` NOT `empname` because `empname` make confusing when you read code
this.empnameList = empnameList;
this.empname = empname;
}
public static void main(String[] args) {
String[] strArray = new String[]{"Name1","Name2","Name2"};
String empName = "Na";
setData6(strArray,empName); // call method with 2 parameters here
}
}
Hope this help
Solved!! it turns out I had to modify my setter part of my Globals class, so this first part (the getter method) in the Globals class is correct:
public String[] compname = {"Manager's company", "Company2", "Company3", "Company4", "Company5", "Company6", "Company7", "Company8", "Company9", "Company10", "Company11", "Company12", "Company13", "Not punched in"};
public String[] getData7() {
return compname;
}
I had to change the getter part of my Globals class to this:
public int setcmpn = 0; // <-- Edited, this should equal some integer value
public void setData7(int setcmpn, String compname) { // removed [] from 2nd argument
this.setcmpn = setcmpn;
this.compname[setcmpn] = compname; // added in [] after array's name and fill it with the first argument from setData7 method
}
And to set the value of the desired index from any class just use:
Globals g = (Globals) getApplication();
g.setData7(getemn, getemp);
where getemn is an integer and getemp is a string.

arraylist in java to sort data [duplicate]

This question already has answers here:
Collections.sort with multiple fields
(15 answers)
Closed 7 years ago.
so i'm having issues making this work for me. what this code needs to do is have 3 different (string) fields that then sort them into alphabetical order i've had help before but it wont run on my netbeans. i am currently up to date with all updates as well.
heres the code i have so far
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Comparator;
public class test {
private Scanner scan = new Scanner(System.in);
private List<LayoutOfScientist> scientistsNames = new ArrayList<LayoutOfScientist>();
private String name, field, idea;
private boolean continueLoop = true;
private int countTo3 = 0;
private void run() {
while(countTo3<3&&continueLoop) {
if(countTo3>0) {
System.out.println("Would you like to add another scientist? (Y/N)");
}
if(countTo3 == 0 || scan.nextLine().equalsIgnoreCase("y")) {
System.out.println("Please enter the scientist's name:");
name = scan.nextLine();
System.out.println("Please enter the scientist's field:");
field = scan.nextLine();
System.out.println("Please enter the scientist's idea:");
idea = scan.nextLine();
scientistsNames.add(new LayoutOfScientist(name, field, idea));
} else {
continueLoop = false;
}
countTo3++;
}
scientistsNames.sort(Comparator.comparing(LayoutOfScientist::getScientistName));
for(LayoutOfScientist lOS : scientistsNames) {
System.out.println(lOS.getScientistName() + ", " + lOS.getScientistField() + ", " + lOS.getScientistIdea());
}
}
private class LayoutOfScientist {
private String scientistName, scientistField, scientistIdea;
private LayoutOfScientist(String scientistName, String scientistField, String scientistIdea) {
this.scientistName = scientistName;
this.scientistField = scientistField;
this.scientistIdea = scientistIdea;
}
public String getScientistName() {
return scientistName;
}
public String getScientistField() {
return scientistField;
}
public String getScientistIdea() {
return scientistIdea;
}
}
public static void main(String[] args) {
new Test().run();
}
}
Your class name is test (lowercase t) and in your main method, you are calling Test().run().
You need to rename your class to be Test and that should work. Or if your file is test you need to change Test().run() to test().run() instead of public class test to public class test. However, it is good programming practice to name a ClassLikeThis.
If your error is something else entirely, tell us what the error is.

Java Eclipse - Game: How to make the user's answer change the next statement asked

Right now I am working on a programming project in school, I am using Java Eclipse. I am still learning the basics, as I am a Sophomore in high school.
My project relates to the old game called "20 Questions".
My main trouble right now is making the user's answer result with a different question. I have tried and "if else" statement, which took me far, but not far enough. Example:
print ("Is your animal furry?");
if (answer is "True") print("Does this animal wag its tail when excited?")
//This can only be a dog
else print("Is it known to lick itself clean?")
//Else meaning if it doesn't wag its tail, go to cat questions
//only cat in this program
So my predicament is getting the user's answer to change the programs next answer.
Then if the answer they give to the furry animal is false, how do I make it go to the non hairy animal questions?
When you create a Java game, or any Java application with a GUI, using the model / view / controller pattern helps separate your concerns and makes it a lot easier to code.
What you're missing is a model. Here's one way you could model the 20 questions game.
Question.java
Here's a class that holds the question string and two pointers. One pointer for the true answer, and one pointer for the false answer.
package com.ggl.twenty.questions;
public class Question {
private int falseQuestion;
private int trueQuestion;
private String question;
public Question(String question) {
this.question = question;
}
public int getFalseQuestion() {
return falseQuestion;
}
public void setFalseQuestion(int falseQuestion) {
this.falseQuestion = falseQuestion;
}
public int getTrueQuestion() {
return trueQuestion;
}
public void setTrueQuestion(int trueQuestion) {
this.trueQuestion = trueQuestion;
}
public String getQuestion() {
return question;
}
}
TwentyQuestionsModel.java
Next, we create a model class for the game. This class creates and uses a List of questions. From any question, you can get the next question by performing the getTrueQuestion or getFalseQuestion method.
package com.ggl.twenty.questions;
import java.util.ArrayList;
import java.util.List;
public class TwentyQuestionsModel {
private int questionIndex;
private List<Question> questions;
public TwentyQuestionsModel() {
this.questions = new ArrayList<Question>();
this.questionIndex = 0;
loadQuestions();
}
private void loadQuestions() {
Question q0 = new Question("Is it a vegetable?");
this.questions.add(q0);
Question q1 = new Question("Is it a mineral?");
this.questions.add(q1);
Question q2 = new Question("Is it a mammal?");
this.questions.add(q2);
// ...
q0.setFalseQuestion(1);
q0.setTrueQuestion(3);
// ...
}
public String getTrueQuestion() {
Question q = questions.get(questionIndex);
this.questionIndex = q.getTrueQuestion();
return questions.get(questionIndex).getQuestion();
}
public String getFalseQuestion() {
Question q = questions.get(questionIndex);
this.questionIndex = q.getFalseQuestion();
return questions.get(questionIndex).getQuestion();
}
public String getFirstQuestion() {
return questions.get(questionIndex).getQuestion();
}
}
You still have to code a view and a controller. The right model makes it much easier, as you can separate your concerns.
Here my solution just with a question class:
import java.util.Scanner;
public class Question {
private String message = null;
private boolean answered = false;
private Question yes = null;
private Question no = null;
public Question(String message)
{
this.message = message;
}
public void setAnswered(boolean answered)
{
this.answered = answered;
}
public boolean getAnswered()
{
return this.answered;
}
public void setYes(Question yes)
{
this.yes = yes;
}
public void setNo(Question no)
{
this.no = no;
}
public Question getYes()
{
return this.yes;
}
public Question getNo()
{
return this.no;
}
public String getMessage()
{
return this.message;
}
public static void runQuestionnaire(Question startQuestion)
{
String yes = "y";
System.out.println("Some questions. Type 'y' for yes and 'n' for no\nand press enter.");
Scanner sc = new Scanner(System.in);
String answer = null;
Question current = startQuestion;
boolean answered = false;
do
{
System.out.println(current.getMessage());
answer = sc.next();
if(answer.equals(yes))
{
current = current.getYes();
}
else
{
current = current.getNo();
}
answered = current.getAnswered();
}
while(!answered);
System.out.println(current.getMessage());
sc.close();
}
public static void main(String[] args) {
// creating the question tree
Question startQuestion = new Question("Is it fury?");
Question yes1 = new Question("Has it 4 legs?");
Question no1 = new Question("It is a human beeing.");
no1.setAnswered(true);
startQuestion.setYes(yes1);
startQuestion.setNo(no1);
Question yes11 = new Question("Is it blue?");
Question yes111 = new Question("It is a whale.");
yes111.setAnswered(true);
Question no111 = new Question("It is a bear.");
no111.setAnswered(true);
yes1.setYes(yes11);
Question no11 = new Question("It is a bird.");
no11.setAnswered(true);
yes1.setNo(no11);
yes11.setYes(yes111);
yes11.setNo(no111);
Question.runQuestionnaire(startQuestion);
}

Problems when creating methods in my task

The goal is to produce this:
Picture of the task summary here
These are the errors I get when I try to compile:
screen shot
I have changed and fixed most of the more obvious errors I think which was mainly just stupid of me. Sorry.
I have this code
public class Ex5Program {
public void start() {
Tutor[] tutors = createTutorsArray();
printTutors(tutors);
printOnLeaveList(tutors);
updateTutorDetails(tutors[1]);
printNewTutorDetails(tutors[1]);
Tutor tutorWithMostPapers = getTutorWithMostPapers(tutors);
printTutorWithMostPapers(tutorWithMostPapers);
}
private Tutor[] createTutorsArray() {
String[] noPapers = {};
String[] introductoryPapers = {"CompSci101", "CompSci111"};
String[] coreStage1Papers = {"CompSci101", "CompSci105"};
String[] allStageOnePapers = {"CompSci111", "CompSci101", "CompSci105"};
String[] stageTwoPapers = {"CompSci210", "CompSci220", "CompSci225", "CompSci230"};
Tutor[] tutors = new Tutor[7];
tutors[5] = new Tutor("Sad Sack", 86302, introductoryPapers, false);
tutors[4] = new Tutor("Crystal Ball", 49123, introductoryPapers, false);
tutors[2] = new Tutor("Earl Lee Riser", 40879, allStageOnePapers, true);
tutors[3] = new Tutor("Tom Katt", 50876, stageTwoPapers, false);
tutors[1] = new Tutor("Candy Kane", 30869, noPapers, false);
tutors[0] = new Tutor("Carrie Oakey", 30987, coreStage1Papers, true);
tutors[6] = new Tutor("Sonny Day", 49586, stageTwoPapers, true);
return tutors;
}
private void printTutors(Tutor[] tutors) {
System.out.println("Current Tutors");
System.out.println("==============");
for (int i = 0; i < tutors.length; i++) {
System.out.print(i + 1 + ". ");
System.out.println(tutors[i].toString());
}
}
private void printOnLeaveList(Tutor[] tutors) {
System.out.println();
System.out.println("Tutors Currently on Leave");
System.out.println("=========================");
for (int i = 0; i < tutors.length; i++) {
if (tutors[i].isOnLeave()) {
System.out.println(tutors[i].getName());
}
}
}
private void updateTutorDetails(Tutor tutor) {
tutor.setName("Ali Katt");
tutor.setStaffId(23456);
String[] stage1Papers = {"CompSci101", "CompSci105", "CompSci111"};
tutor.setPapers(stage1Papers);
tutor.setOnLeave(true);
}
private void printNewTutorDetails(Tutor tutor) {
System.out.println();
System.out.println("Updated details");
System.out.println("===============");
System.out.println("Name: " + tutor.getName());
System.out.println("Id: " + tutor.getStaffId());
String[] papers = tutor.getPapers();
System.out.print("Papers: ");
if (papers.length > 0) {
for (int i = 0; i < papers.length; i++) {
System.out.print(papers[i] + " ");
}
} else {
System.out.print("None");
}
System.out.println();
if (tutor.isOnLeave()) {
System.out.println("Currently on leave");
}
}
private Tutor getTutorWithMostPapers(Tutor[] tutors) {
Tutor tutorWithMostPapersSoFar = tutors[0];
for (int i = 0; i < tutors.length; i++) {
if (tutors[i].teachesMorePapersThan(tutorWithMostPapersSoFar)) {
tutorWithMostPapersSoFar = tutors[i];
}
}
return tutorWithMostPapersSoFar;
}
private void printTutorWithMostPapers(Tutor tutorWithMostPapers) {
System.out.println();
System.out.println("Most papers");
System.out.println("===========");
System.out.println(tutorWithMostPapers.getName() + " teaches more papers than any other tutor.");
}
}
and I created this code here(It has been changed):
public class Tutor {
// instance variables
private String name;
private int staffId;
private String[] papers;
private boolean onLeave;
public Tutor(String name, int staffId, String[] papers, boolean onLeave) {
// Complete this constructor method
this.name = name;
this.staffId = staffId;
this.papers = papers;
this.onLeave = onLeave;
}
// Insert getName() method here
public String getName(){
return name;
}
// Insert setName() method here
public void setName(String name){
this.name = name;
}
// Insert getStaffId() method here
public int getStaff(){
return staffId;
}
// Insert setStaffId() method here
public void setStaffId(int StaffId){
this.staffId = staffId;
}
// Insert getPapers() method here;
public String[] getPapers(){
return papers;
}
// Insert setPapers() method here
public void setPapers(String[] papers){
this.papers = papers;
}
// Insert isOnLeave() method here
public boolean isOnLeave(){
return onLeave;
}
// Insert setOnLeave() method here
public void setOnLeave(boolean OnLeave){
this.onLeave = onLeave;
}
// Insert toString() method here
public String toString(){
return name + "(Staff id:"+staffId+")";
}
// Insert teachesMorePapersThan() method here
public Tutor teachesMorePapersThan(Tutor other){
return(papers.length>other.papers.length);
}
}
Typo: toString() not tostring(), which results in Object.toString() is being invoked and the intended formatted string is not being returned. Change to:
#Override public String toString()
Using the #Override annotation would have produced a compiler error in the case of tostring() being the method name and alerted you to the error, because no method of that name exists in a superclass.
Several of the setter methods have missing parameters:
// Insert setPapers() method here
public void setPapers(){
this.papers = papers;
}
// Insert setOnLeave() method here
public void setOnLeave(){
this.OnLeave = OnLeave;
}
First error: setStaffID()
You are calling it using an int, but on your method you say it doesn't have any parameter.
Take a look that you have some others errors caused by the same mistake. Correct them first...
You need to look at the error text to find the problems. While a newbie may instinctively just dismiss the error messages as uselesss (as a result of years of clicking the x or cancel or whatever on windows dialogues), The error text is actually the most useful resource for figuring out what the error is, 90% of the time.
For instance, the first error reads
File: F:\course related stuff\101\Lab06\Ex5\Ex5Program.java [line: 54]
Error: method setStaffId in class Tutor cannot be applied to given types;
required: no arguments
found: int
reason: actual and formal argument lists differ in length
If you read it carefully, you can see it tells you the name of the file, the line number, the method call name, the class name containing the method, and some additional information about the exact type of error. It is even telling you what you did wrong in calling the method, by putting an "int" where "no arguments" were required, that the "actual and formal argument lists differ in length".
Read the other error messages, and you will see that they actually tell you what the problem is.
This code also needs newlines inserted to group blocks of stuff, comments added to explain exactly how it works, and a few java style violations fixed - some teachers grade for style and clarity as well as just functionality.
Also, if the reason you are failing your class is because you don't understand how to program, it may be because of excessive use of stack overflow to solve the problems. In the real world, if you can just use somebody else's code, that's great, but the point of a programming class is is to teach you how to come up with your own code, not how to use somebody else's.
Well it's not easy to help, because i think you don't know what you are doing. But first thing when you create a set method like this:
public void setPapers(){
this.papers = papers;
}
you should declare the arguments like this:
public void setPapers(String[] papers){
this.papers = papers;
}
and you should know that variables names is caseSensitive so :
private boolean onLeave;
public boolean isOnLeave(){
//return OnLeave; this variable is not declared
return onLeave;
}
I think you need to study a little more, because you can't read the compilation errors.

Categories

Resources