Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
import java.util.Scanner; public class Triangle extends geometricObject { Scanner input = new Scanner(System.in); public static void main(String[] args){ double side1 = 1; //All of these could have gone uninitialized, but the problem specifically stated it gets initialized to one double side2 = 1; double side3 = 1; double area; //Because we're using a method to calculate this, we need to store something in the main method //Otherwise, we wouldn't be able to store the value returned in the method double perimeter; //Same as area String color = ""; //Same as area, but Strings have to be initialized in Java. String answer = ""; //See above String talk = ""; //See above System.out.print("Side 1: "); side1 = Triangle2(side1); //Now that I know there is a triangle class, I could have called (used) 1 method, but time was of the essence //Essentially what's happening is that the code is looking at the Triangle2 method, but because the method has //(double first) instead of a blank paranthesis, it's saying "yo I can take some external input and utilize it //Cause remember, we can't return a value from the main method. We could have done this without the methods, but //I'm following the rules of the assignment. System.out.print("Side 2: "); side2 = Triangle3(side2); //Read side1 System.out.print("Side 3: "); side3 = Triangle4(side3); //Read side1 perimeter = getPerimeter(side1,side2,side3); //Similar to finding out the lengths of the sides, but it has three arguments. //Just like how normal code reads, it takes your value from first to last. So it's going to take //The first input and use it as the first input for the method and so on talk = toString(side1,side2,side3); //The same as the perimeter, but using a string. We had to create a variable so we could //use it in the output System.out.print("\nWhat color tho: "); color = geometricObject.getColor(color); //Same as the talk variable, but because we're calling from another file we have to put the //classname.methodname() System.out.print("\nIs it filled in?"); answer = geometricObject.logic(answer); //Same as the talk variable System.out.print("\nThe area of this god damn triangle is " + getArea(side1,side2,side3) + "\nThe perimeter is: " + perimeter + talk); System.out.println("\n" + color); //Remember, getArea(side1,side2,side3) is perfectly fine. Like I said, I wouldn't do area in this, but I was doing a string with this //System.out.print will also do whatever code you're trying to execute, though thats not its main function. It will function the same //as if you were like area = getArea(side1, side2, side3) in a seperate line of code. Like I said, I don't like doing this with a numerical //value, because sometimes you will need to use it after you've calculated the new value. With strings, they usually don't change though if (answer == "Shits filled") //If statement so we know that it is what it needs to be { answer = "The triangle is filled in"; //answer was originally 'Shits filled' but because of the if statement, we can now change it } else { answer = "Tne triangle is not filled in"; //Same as before } System.out.println(answer); //Because we've now changed the string via the if statement, it will print what it needs to } //<--- Ugly ass bracket, fuck you jgrasp format yourself public static double Triangle2(double first) //First method we call. Name is irrelevant, but because we're throwing other variables into it //in the main method. We need to declare a variable so that we can then bring it into the equation //Again, now that I know there's the Triangle class itself, or I could have made an array, this could //be simplified to 1 method { double x = 1; Scanner stdin = new Scanner(System.in); //Simple scanner //side1 = side1 * first; x = stdin.nextInt(); return x; //We need to return the variable so that side1 in main will now become the variable we entered //Without return, it will still do what we asked but it won't tell the main statement what it did } public static double Triangle3(double second) //Read Triangle2 { double side2 = 1; Scanner stdin = new Scanner(System.in); side2 = stdin.nextInt(); return side2; } public static double Triangle4(double third) //Read Triangle2 { double side3 = 1; Scanner stdin = new Scanner(System.in); side3 = stdin.nextInt(); return side3; } public static double getArea(double x, double y, double z) //Taking in all three variables. Like I said, when you call the function //It will read left to right. So side1 is now x, side2 is now y, etc. //xyz are now replaced with the values stored in side1,2,and 3. So we're //calculating area with the values stored in main { double area; area = (x + y + z)/2; return area; } public static double getPerimeter(double x, double y, double z) //See area { double perimeter; perimeter = x + y + z; return perimeter; } public static String toString(double x, double y, double z) //No calculations, but its doing the same shit as area and perimeter //But, we're creating the new string that we need to create with the variables //Because we're creating the string on the fly, we don't need to initialize //with nothing. We're initializing it with the full string. { double side1; double side2; double side3; side1 = x; side2 = y; side3 = z; String sides = "\nTriangle: side1 = " + side1 + " side 2 = " + side2 + " side3 = " + side3; return sides; } } import java.util.Scanner; //Needed to import the scanner so that we could type shit in public class geometricObject { public String color = "Yellow"; //public boolean filled = true; //I commented this out because I couldn't use it in the other method public static String getColor(String color2) //Method to call in the Triangle class { Scanner stdin = new Scanner(System.in); //Scanner so we can type shit in //boolean filled = true; //Spaghetti code that I didn't realize I fucked up with String userColor = ""; userColor = stdin.nextLine(); return userColor; } public static String logic(String response) //So we can enter an answer and make it work { char answer; //This way we can make any answer okay boolean filled = false; //It's false, because being true made compilation errors Scanner input = new Scanner(System.in); String asdf = input.nextLine(); //If we had it read from the char, then any extra input would cause the system to crash on the next line answer = Character.toUpperCase(asdf.charAt(0)); //This takes the string, finds the first character, and makes it uppercase switch (answer) { case 'Y': filled = true; //Because we made the first character uppercase, answers like "Yes, Y, yes, y, No, N, no, n" all work break; case 'N': filled = false; break; default: System.out.print("Invalid input detected.\nProgram will end now. "); //End the switch statement if they put in a wrong character System.exit(0); break; } if (filled == true) //The switch statement assigned the boolean value { asdf = "Shits filled"; } else { asdf = "Nah g"; } return asdf; //Returns the String that } }
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
OoT rando seed 6/13
11 min ago | 202.05 KB
w
17 hours ago | 0.09 KB
[email protected]
- idiot sending fr...
19 hours ago | 1.35 KB
Untitled
22 hours ago | 0.03 KB
Checking in availability
1 day ago | 0.66 KB
TRMP TOKEN
1 day ago | 1.56 KB
Untitled
1 day ago | 0.16 KB
my-push Script
1 day ago | 0.19 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!