r/learnjava • u/itsyoboiGamma • 1d ago
Need help
This is for an APCSA assignment on Idecl.
My code technically works but when I run tests the "readSwitchesFromUser" method keeps creating this specific error:
/app/TestMinivan.java:97: error: method readSwitchesFromUser in class Minivan cannot be applied to given types;
van.readSwitchesFromUser();
^
required: int,int,int,int,int,int,int,int,String
found: no arguments
reason: actual and formal argument lists differ in length
I know I have to turn the readSwitchedFromUser method into a scanner but I have no clue how to go about it.
Below is the program I wrote:
import java.util.Scanner;
public class Minivan{
private int dashLeft; // 0 = switch disengaged; 1 = switch engaged
private int dashRight; // 0 = switch disengaged; 1 = switch engaged
private int childLock; // 0 = off; 1 = activated
private int masterUnlock; // 0 = off; 1 = activated
private int insideLeft; // 0 = switch disengaged; 1 = switch engaged
private int outsideLeft; // 0 = switch disengaged; 1 = switch engaged
private int insideRight; // 0 = switch disengaged; 1 = switch engaged
private int outsideRight; // 0 = switch disengaged; 1 = switch engaged
private String gearSetting;
/* Options include: P(ark) N(eutral) D(rive) 1(st gear)
2(nd gear) 3(rd gear) R(everse) */
public static void main(String[] args){
Minivan mv = new Minivan();
// This creates a new minivan with the name mv.
// If you don't like that name, feel free to change it.
// Complete the main method here.
// Be sure to create a series of your own tests to
// ensure the program runs as expected.
setSwitches();
}
public static void setSwitches(int s1, int s2, int s3, int s4, int s5, int s6, int s7, int s8, String gearShift){
Scanner sc = new Scanner(System.in);
System.out.println("Enter accetable value (eight strings, each followed by a comma, and a gear in quotes): ");
// getting each individual input from the user
String S1 = sc.nextLine();
String S2 = sc.nextLine();
String S3 = sc.nextLine();
String S4 = sc.nextLine();
String S5 = sc.nextLine();
String S6 = sc.nextLine();
String S7 = sc.nextLine();
String S8 = sc.nextLine();
String gear = sc.nextLine();
S1 = S1.substring(0, 1);
S2 = S2.substring(0, 1);
S3 = S3.substring(0, 1);
S4 = S4.substring(0, 1);
S5 = S5.substring(0, 1);
S6 = S6.substring(0, 1);
S7 = S7.substring(0, 1);
S8 = S8.substring(0, 1);
int s1 = Integer.parseInt(S1);
int s2 = Integer.parseInt(S2);
int s3 = Integer.parseInt(S3);
int s4 = Integer.parseInt(S4);
int s5 = Integer.parseInt(S5);
int s6 = Integer.parseInt(S6);
int s7 = Integer.parseInt(S7);
int s8 = Integer.parseInt(S8);
// s1 = dashLeft
// s2 = dashRight
// s3 = childLock
// s4 = masterUnlock
// s5 = insideLeft
// s6 = outsideLeft
// s7 = insideRight
// s8 = outsideRight
// I dont know why I named it like that, I dont really know what the s stands for.
//making sure the conversion is working
System.out.println(s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8);
readSwitchesFromUser(s1, s2, s3, s4, s5, s6, s7, s8, gear);
}
public static void checkDoors(int s1, int s2, int s3, int s4, int s5, int s6, int s7, int s8, String gearShift){
// Write the method checkDoors here.
if ((!gearShift.equals("P")) || s4 != 0){
System.out.println("both doors closed");
}
boolean leftDoorOpen = false;
boolean rightDoorOpen = false;
if ((s1 == 1 || s5 == 1 || s6 == 1) && s3 == 0){
leftDoorOpen = true;
}
if ((s2 == 1 || s7 == 1 || s8 == 1) && s3 == 0){
rightDoorOpen = true;
}
if (rightDoorOpen && leftDoorOpen){
System.out.println("both doors open");
}
else if (rightDoorOpen && !leftDoorOpen){
System.out.println("right door open");
}
else if (!rightDoorOpen && leftDoorOpen){
System.out.println("left door open");
}
}
}
1
u/EntrepreneurHuge5008 1d ago
My code technically works but when I run tests the "readSwitchesFromUser" method keeps creating this specific error:
The error is telling that that specific method is expecting you to give it some values:
required: int,int,int,int,int,int,int,int,String
If you didn't write this method, find where it is in the code, and I bet you there's a comment telling you what it is for and what it expects.
1
u/aqua_regis 1d ago edited 1d ago
Your code is worse than horrible. Actually, you are doing a whole lot wrong here.
You should definitely not query the user for the switches in the
setSwitchesmethod. - The settings should be passed in via the parameters.You are calling
setSwitches()in line 29 - without parameters. Yet, it expects 8You never assign anything to your real attributes, like
dashLeft, etc.Why would your
checkDoorsmethod even need parameters? You should use the fields (attributes).Where do you define the
readSwitchesFromUsermethod?
So your code does not technically work. It doesn't work at all. It's definitely not doing what it should do.
•
u/AutoModerator 1d ago
Please ensure that:
Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
You include any and all error messages in full - best also formatted as code block
You ask clear questions
You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.
If any of the above points is not met, your post can and will be removed without further warning.
Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.
Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.
Code blocks look like this:
You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.
If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.
To potential helpers
Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.