Need Help with java ASCII art - can anyone try this and then talk me through it. Please and Thanks:D

No description
27 Replies
JavaBot
JavaBot12mo ago
This post has been reserved for your question.
Hey @StremesJ! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
StremesJ
StremesJOP12mo ago
@ponchisao326 hello again want a challenge 😄
ponchisao326
ponchisao32612mo ago
hahhahah let me check
StremesJ
StremesJOP12mo ago
tysm - dont worry if your busy tho
ponchisao326
ponchisao32612mo ago
what do you have at the moment ?
StremesJ
StremesJOP12mo ago
nothing i got the void display {} but like switch case and doing ascii art is so hard
ponchisao326
ponchisao32612mo ago
Can you pass the exercise itself through here the plain text
StremesJ
StremesJOP12mo ago
ok
Yumi
Yumi12mo ago
Program 4. Seven Segment Display (20%) In the file SevenSegment.jsh, write a method with the signature: void display(int n) that, given a number, displays ASCII art of that number in the style of an electronic “seven segment display”. For example: display(28); -- -- | | | -- -- | | | -- -- You may assume the number is a non-negative Java int. Hints:  Use n % 10 to get the right-most digit of a number. For example, 123456 % 10 == 6.  Use n / 10 to chop off the right-most digit of a number. For example, 123456 / 10 == 12345. To help your program draw the ASCII art, you should use the following method that, given a digit d and a line number n (from 1 to 5), returns a String representing line n of digit d.
String ssd(int d, int n) {
switch ((d*10)+n) {
case 1: case 5: case 21: case 23: case 25: case 31: case 33: case 35:
case 43: case 51: case 53: case 55: case 61: case 63: case 65: case 71:
case 81: case 83: case 85: case 91: case 93: case 95:
return " -- ";
case 24: case 52: case 62:
return "| ";
case 12: case 14: case 22: case 32: case 34: case 44: case 54: case 72:
case 74: case 94:
return " | ";
case 2: case 4: case 42: case 64: case 82: case 84: case 92:
return "| | ";
default: return " ";
}
}
String ssd(int d, int n) {
switch ((d*10)+n) {
case 1: case 5: case 21: case 23: case 25: case 31: case 33: case 35:
case 43: case 51: case 53: case 55: case 61: case 63: case 65: case 71:
case 81: case 83: case 85: case 91: case 93: case 95:
return " -- ";
case 24: case 52: case 62:
return "| ";
case 12: case 14: case 22: case 32: case 34: case 44: case 54: case 72:
case 74: case 94:
return " | ";
case 2: case 4: case 42: case 64: case 82: case 84: case 92:
return "| | ";
default: return " ";
}
}
This message has been formatted automatically. You can disable this using /preferences.
StremesJ
StremesJOP12mo ago
this?
ponchisao326
ponchisao32612mo ago
yes, but if you can pass it through a document would be better it's just because I can't see it that well on the photo
StremesJ
StremesJOP12mo ago
oki give me 3 mins
ponchisao326
ponchisao32612mo ago
okay
StremesJ
StremesJOP12mo ago
there you go
ponchisao326
ponchisao32612mo ago
ty
JavaBot
JavaBot12mo ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
yikadee
yikadee2d ago
hi, very late but has this been solved? I don't have any clue on how to approach this
bassus
bassus2d ago
What exactly is your issue? Maybe open a new ticket and describe it there, noone will eat you for doing it 😄
WALKITOFF
WALKITOFF2d ago
Ngl If given a choice id just make an array of strings 0 thru 9 For the ascii art Then just grab and print them based on each digit. Ooh nvm I see why that don't work damn
bassus
bassus2d ago
It kinda does, like your idea is not bad, in general but i'd just modify it a little
WALKITOFF
WALKITOFF2d ago
well since they give you a function for printing part of the number per row, its prob easier to just create a String[] arr of length 5, and just concat each number row by row, then print the array 1 row at a time.
WALKITOFF
WALKITOFF2d ago
No description
bassus
bassus2d ago
Fair
WALKITOFF
WALKITOFF2d ago
thats my plan anyway ...but @StremesJ might have already solved this by now
JavaBot
JavaBot23h ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one. In case your post is not getting any attention, you can try to use /help ping. Warning: abusing this will result in moderative actions taken against you.
WALKITOFF
WALKITOFF23h ago
i had to edit the supplied function @StremesJ not sure if ur allowed to do that for your project tho. otherwise nothing lined up
static String ssd(int d, int n) {
return switch ((d * 10) + n) {
case 1, 5, 21, 23, 25, 31, 33, 35, 43, 51, 53, 55, 61, 63, 65, 71, 81, 83, 85, 91, 93, 95 -> " -- ";
case 24, 52, 62 -> "| ";
case 12, 14, 22, 32, 34, 44, 54, 72, 74, 94 -> " | ";
case 2, 4, 42, 64, 82, 84, 92 -> "| | ";
default -> " ";
};
}
static String ssd(int d, int n) {
return switch ((d * 10) + n) {
case 1, 5, 21, 23, 25, 31, 33, 35, 43, 51, 53, 55, 61, 63, 65, 71, 81, 83, 85, 91, 93, 95 -> " -- ";
case 24, 52, 62 -> "| ";
case 12, 14, 22, 32, 34, 44, 54, 72, 74, 94 -> " | ";
case 2, 4, 42, 64, 82, 84, 92 -> "| | ";
default -> " ";
};
}
No description

Did you find this page helpful?